Skip to content

Commit a01f443

Browse files
committed
Remove deployment names attribute on stack model
1 parent c907c9b commit a01f443

File tree

2 files changed

+16
-51
lines changed

2 files changed

+16
-51
lines changed

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)