Skip to content

Commit

Permalink
SUP-2591: add PlanModifiers when Hosted Agent attributes changed (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomowatt authored Dec 20, 2024
1 parent 73d45cc commit cbd14b8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions buildkite/resource_cluster_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
Expand Down Expand Up @@ -137,6 +138,29 @@ func (clusterQueueResource) Schema(ctx context.Context, req resource.SchemaReque
Validators: []validator.Object{
&hostedAgentValidator{},
},
PlanModifiers: []planmodifier.Object{
objectplanmodifier.RequiresReplaceIf(func(ctx context.Context, or planmodifier.ObjectRequest, rrifr *objectplanmodifier.RequiresReplaceIfFuncResponse) {
var data *struct {
Mac types.Object `tfsdk:"mac"`
Linux types.Object `tfsdk:"linux"`
InstanceShape types.String `tfsdk:"instance_shape"`
}

rrifr.Diagnostics.Append(or.ConfigValue.As(ctx, &data, basetypes.ObjectAsOptions{})...)

if rrifr.Diagnostics.HasError() {
return
}

// If the hosted_agents attribute is added or removed e.g., change from a Hosted Agent to Self-Hosted Agent Queue
if or.StateValue.IsNull() && !or.PlanValue.IsNull() || or.ConfigValue.IsNull() {
rrifr.RequiresReplace = true
return
}

rrifr.RequiresReplace = false
}, "Recreates the resource if the hosted_agents attribute is added or removed.", "Recreates the resource if the hosted_agents attribute is added or removed."),
},
Attributes: map[string]resource_schema.Attribute{
"mac": resource_schema.SingleNestedAttribute{
Optional: true,
Expand Down Expand Up @@ -176,6 +200,9 @@ func (clusterQueueResource) Schema(ctx context.Context, req resource.SchemaReque
LinuxARM64InstanceXLarge,
),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
},
Expand Down

0 comments on commit cbd14b8

Please sign in to comment.