Skip to content

Commit

Permalink
Merge pull request #44 from pluralsh/fix-cluster-project-bug
Browse files Browse the repository at this point in the history
fix: Make cluster's project id non-computed attribute and add constant-ness check
  • Loading branch information
maciaszczykm authored Jun 26, 2024
2 parents b3bb6c7 + 43f6458 commit 54d51db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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
2 changes: 0 additions & 2 deletions internal/resource/cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions internal/resource/cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 54d51db

Please sign in to comment.