Skip to content

Commit 249013d

Browse files
authored
Merge pull request #1855 from hashicorp/go-tfe-stacks-ga-update
Stacks GA update
2 parents 21f6118 + 8bd4549 commit 249013d

File tree

4 files changed

+19
-54
lines changed

4 files changed

+19
-54
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/hashicorp/go-multierror v1.1.1 // indirect
1515
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
1616
github.com/hashicorp/go-slug v0.16.7
17-
github.com/hashicorp/go-tfe v1.92.0
17+
github.com/hashicorp/go-tfe v1.93.0
1818
github.com/hashicorp/go-version v1.7.0
1919
github.com/hashicorp/hcl v1.0.0
2020
github.com/hashicorp/hcl/v2 v2.24.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVU
7373
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
7474
github.com/hashicorp/go-slug v0.16.7 h1:sBW8y1sX+JKOZKu9a+DQZuWDVaX+U9KFnk6+VDQvKcw=
7575
github.com/hashicorp/go-slug v0.16.7/go.mod h1:X5fm++dL59cDOX8j48CqHr4KARTQau7isGh0ZVxJB5I=
76-
github.com/hashicorp/go-tfe v1.92.0 h1:DxJ/ONlNgp4kP5xdglJBLYBeunDeii3CelpgA6PjebM=
77-
github.com/hashicorp/go-tfe v1.92.0/go.mod h1:QwqgCD5seztgp76CP7F0POJPflQNSqjIvBpVohg9X50=
76+
github.com/hashicorp/go-tfe v1.93.0 h1:hJubwn1xNCo1iBO66iQkjyC+skR61cK1AQUj4O9vvuI=
77+
github.com/hashicorp/go-tfe v1.93.0/go.mod h1:QwqgCD5seztgp76CP7F0POJPflQNSqjIvBpVohg9X50=
7878
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
7979
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
8080
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

internal/provider/resource_tfe_stack.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1414
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1515
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
16-
"github.com/hashicorp/terraform-plugin-framework/types"
1716
"github.com/hashicorp/terraform-plugin-log/tflog"
1817
)
1918

@@ -92,11 +91,6 @@ func (r *resourceTFEStack) Schema(ctx context.Context, req resource.SchemaReques
9291
Description: "Description of the Stack",
9392
Optional: true,
9493
},
95-
"deployment_names": schema.SetAttribute{
96-
Description: "The time when the Stack was created.",
97-
Computed: true,
98-
ElementType: types.StringType,
99-
},
10094
"created_at": schema.StringAttribute{
10195
Description: "The time when the stack was created.",
10296
Computed: true,
@@ -194,7 +188,7 @@ func (r *resourceTFEStack) Read(ctx context.Context, req resource.ReadRequest, r
194188
}
195189

196190
tflog.Debug(ctx, fmt.Sprintf("Reading stack %q", state.ID.ValueString()))
197-
stack, err := r.config.Client.Stacks.Read(ctx, state.ID.ValueString(), nil)
191+
stack, err := r.config.Client.Stacks.Read(ctx, state.ID.ValueString())
198192
if err != nil {
199193
resp.Diagnostics.AddError("Unable to read stack", err.Error())
200194
return
@@ -222,27 +216,6 @@ func (r *resourceTFEStack) Update(ctx context.Context, req resource.UpdateReques
222216
return
223217
}
224218

225-
// NOTE: if there are existing deployments, and you plan to move a stack from vcs to non-vcs or vice versa,
226-
// we should prevent the update and return an error because the API does not allow this.
227-
// TODO: When the go-tfe package would allow such operation we should revisit this logic.
228-
// This is also inspired by similar behavior of the destroy / delete operation for this resource.
229-
var deploymentNames []string
230-
if !state.DeploymentNames.IsNull() {
231-
if diags := state.DeploymentNames.ElementsAs(ctx, &deploymentNames, false); diags.HasError() {
232-
resp.Diagnostics.AddError("Invalid deployment names", "Expected a set of strings for deployment names.")
233-
return
234-
}
235-
}
236-
tflog.Debug(ctx, fmt.Sprintf("Current deployments: %v", deploymentNames))
237-
238-
if (len(deploymentNames) > 0) && ((state.VCSRepo != nil && plan.VCSRepo == nil) || (state.VCSRepo == nil && plan.VCSRepo != nil)) {
239-
resp.Diagnostics.AddError(
240-
"Cannot update Stack VCS configuration with existing deployments",
241-
"Please remove all deployments associated with this Stack before updating the VCS configuration.",
242-
)
243-
return
244-
}
245-
246219
options := tfe.StackUpdateOptions{
247220
Name: tfe.String(plan.Name.ValueString()),
248221
Description: tfe.String(plan.Description.ValueString()),

internal/provider/stack.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/hashicorp/go-tfe"
10-
"github.com/hashicorp/terraform-plugin-framework/attr"
1110
"github.com/hashicorp/terraform-plugin-framework/types"
1211
)
1312

@@ -21,34 +20,27 @@ type modelTFEStackVCSRepo struct {
2120
// modelTFEStack maps the resource or data source schema data to a
2221
// struct.
2322
type modelTFEStack struct {
24-
ID types.String `tfsdk:"id"`
25-
ProjectID types.String `tfsdk:"project_id"`
26-
AgentPoolID types.String `tfsdk:"agent_pool_id"`
27-
Name types.String `tfsdk:"name"`
28-
Description types.String `tfsdk:"description"`
29-
DeploymentNames types.Set `tfsdk:"deployment_names"`
30-
VCSRepo *modelTFEStackVCSRepo `tfsdk:"vcs_repo"`
31-
CreatedAt types.String `tfsdk:"created_at"`
32-
UpdatedAt types.String `tfsdk:"updated_at"`
23+
ID types.String `tfsdk:"id"`
24+
ProjectID types.String `tfsdk:"project_id"`
25+
AgentPoolID types.String `tfsdk:"agent_pool_id"`
26+
Name types.String `tfsdk:"name"`
27+
Description types.String `tfsdk:"description"`
28+
VCSRepo *modelTFEStackVCSRepo `tfsdk:"vcs_repo"`
29+
CreatedAt types.String `tfsdk:"created_at"`
30+
UpdatedAt types.String `tfsdk:"updated_at"`
3331
}
3432

3533
// modelFromTFEStack builds a modelTFEStack struct from a
3634
// tfe.Stack value.“
3735
func modelFromTFEStack(v *tfe.Stack) modelTFEStack {
38-
names := make([]attr.Value, len(v.DeploymentNames))
39-
for i, name := range v.DeploymentNames {
40-
names[i] = types.StringValue(name)
41-
}
42-
4336
result := modelTFEStack{
44-
ID: types.StringValue(v.ID),
45-
ProjectID: types.StringValue(v.Project.ID),
46-
AgentPoolID: types.StringNull(),
47-
Name: types.StringValue(v.Name),
48-
Description: types.StringNull(),
49-
DeploymentNames: types.SetValueMust(types.StringType, names),
50-
CreatedAt: types.StringValue(v.CreatedAt.Format(time.RFC3339)),
51-
UpdatedAt: types.StringValue(v.UpdatedAt.Format(time.RFC3339)),
37+
ID: types.StringValue(v.ID),
38+
ProjectID: types.StringValue(v.Project.ID),
39+
AgentPoolID: types.StringNull(),
40+
Name: types.StringValue(v.Name),
41+
Description: types.StringNull(),
42+
CreatedAt: types.StringValue(v.CreatedAt.Format(time.RFC3339)),
43+
UpdatedAt: types.StringValue(v.UpdatedAt.Format(time.RFC3339)),
5244
}
5345

5446
if v.VCSRepo != nil {

0 commit comments

Comments
 (0)