Skip to content

Commit 54d51db

Browse files
authored
Merge pull request #44 from pluralsh/fix-cluster-project-bug
fix: Make cluster's project id non-computed attribute and add constant-ness check
2 parents b3bb6c7 + 43f6458 commit 54d51db

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

internal/resource/cluster.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ func (r *clusterResource) Read(ctx context.Context, req resource.ReadRequest, re
110110
}
111111

112112
func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
113-
var data cluster
113+
var data, state cluster
114114
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
115+
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
115116
if resp.Diagnostics.HasError() {
116117
return
117118
}
118119

120+
if !data.ProjectId.Equal(state.ProjectId) {
121+
resp.Diagnostics.AddError("Invalid Configuration", fmt.Sprintf("Unable to update cluster, project ID must not be modified"))
122+
return
123+
}
124+
119125
_, err := r.client.UpdateCluster(ctx, data.Id.ValueString(), data.UpdateAttributes(ctx, resp.Diagnostics))
120126
if err != nil {
121127
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update cluster, got error: %s", err))

internal/resource/cluster_model.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func (c *cluster) From(cl *console.ClusterFragment, ctx context.Context, d diag.
112112
c.InsertedAt = types.StringPointerValue(cl.InsertedAt)
113113
c.Name = types.StringValue(cl.Name)
114114
c.Handle = types.StringPointerValue(cl.Handle)
115-
c.ProjectId = common.ProjectFrom(cl.Project)
116115
// c.DesiredVersion = c.ClusterVersionFrom(cl.Provider, cl.Version, cl.CurrentVersion)
117116
c.Protect = types.BoolPointerValue(cl.Protect)
118117
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
126125
c.InsertedAt = types.StringPointerValue(cc.CreateCluster.InsertedAt)
127126
c.Name = types.StringValue(cc.CreateCluster.Name)
128127
c.Handle = types.StringPointerValue(cc.CreateCluster.Handle)
129-
c.ProjectId = common.ProjectFrom(cc.CreateCluster.Project)
130128
// c.DesiredVersion = c.ClusterVersionFrom(cc.CreateCluster.Provider, cc.CreateCluster.Version, cc.CreateCluster.CurrentVersion)
131129
c.Protect = types.BoolPointerValue(cc.CreateCluster.Protect)
132130
c.Tags = common.TagsFrom(cc.CreateCluster.Tags, c.Tags, d)

internal/resource/cluster_schema.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ func (r *clusterResource) schema() schema.Schema {
4949
"project_id": schema.StringAttribute{
5050
Description: "ID of the project that this cluster belongs to.",
5151
MarkdownDescription: "ID of the project that this cluster belongs to.",
52-
Computed: true,
5352
Optional: true,
54-
// PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
5553
},
5654
"detach": schema.BoolAttribute{
5755
Description: "Determines behavior during resource destruction, if true it will detach resource instead of deleting it.",

0 commit comments

Comments
 (0)