From 74940316dfa0103eb2673b4d636be3547807b116 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 26 Jun 2024 10:15:19 +0200 Subject: [PATCH 1/2] make cluster's project id non-computed attribute --- internal/resource/cluster_model.go | 2 -- internal/resource/cluster_schema.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/internal/resource/cluster_model.go b/internal/resource/cluster_model.go index 355aaf5..54c6680 100644 --- a/internal/resource/cluster_model.go +++ b/internal/resource/cluster_model.go @@ -112,7 +112,6 @@ func (c *cluster) From(cl *console.ClusterFragment, ctx context.Context, d diag. c.InsertedAt = types.StringPointerValue(cl.InsertedAt) c.Name = types.StringValue(cl.Name) c.Handle = types.StringPointerValue(cl.Handle) - c.ProjectId = common.ProjectFrom(cl.Project) // c.DesiredVersion = c.ClusterVersionFrom(cl.Provider, cl.Version, cl.CurrentVersion) c.Protect = types.BoolPointerValue(cl.Protect) c.Tags = common.TagsFrom(cl.Tags, c.Tags, d) @@ -126,7 +125,6 @@ func (c *cluster) FromCreate(cc *console.CreateCluster, ctx context.Context, d d c.InsertedAt = types.StringPointerValue(cc.CreateCluster.InsertedAt) c.Name = types.StringValue(cc.CreateCluster.Name) c.Handle = types.StringPointerValue(cc.CreateCluster.Handle) - c.ProjectId = common.ProjectFrom(cc.CreateCluster.Project) // c.DesiredVersion = c.ClusterVersionFrom(cc.CreateCluster.Provider, cc.CreateCluster.Version, cc.CreateCluster.CurrentVersion) c.Protect = types.BoolPointerValue(cc.CreateCluster.Protect) c.Tags = common.TagsFrom(cc.CreateCluster.Tags, c.Tags, d) diff --git a/internal/resource/cluster_schema.go b/internal/resource/cluster_schema.go index 79d5225..8cd0cf6 100644 --- a/internal/resource/cluster_schema.go +++ b/internal/resource/cluster_schema.go @@ -49,9 +49,7 @@ func (r *clusterResource) schema() schema.Schema { "project_id": schema.StringAttribute{ Description: "ID of the project that this cluster belongs to.", MarkdownDescription: "ID of the project that this cluster belongs to.", - Computed: true, Optional: true, - // PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()}, }, "detach": schema.BoolAttribute{ Description: "Determines behavior during resource destruction, if true it will detach resource instead of deleting it.", From 43f645817f406ad363ebaf96b26b265c506ffa0c Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 26 Jun 2024 10:58:02 +0200 Subject: [PATCH 2/2] validate that cluster's project id stays constant --- internal/resource/cluster.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/resource/cluster.go b/internal/resource/cluster.go index 3c3b9b2..06a9404 100644 --- a/internal/resource/cluster.go +++ b/internal/resource/cluster.go @@ -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))