Skip to content

Commit

Permalink
validate that cluster's project id stays constant
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Jun 26, 2024
1 parent 7494031 commit 43f6458
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ func (r *clusterResource) Read(ctx context.Context, req resource.ReadRequest, re
}

func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data cluster
var data, state cluster
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

if !data.ProjectId.Equal(state.ProjectId) {
resp.Diagnostics.AddError("Invalid Configuration", fmt.Sprintf("Unable to update cluster, project ID must not be modified"))
return
}

_, err := r.client.UpdateCluster(ctx, data.Id.ValueString(), data.UpdateAttributes(ctx, resp.Diagnostics))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update cluster, got error: %s", err))
Expand Down

0 comments on commit 43f6458

Please sign in to comment.