fix(networkinterface): Recognize the removal of allowed_addresses and security_group_ids from terraform config (#940)

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Alexander Dahmen 2025-08-11 08:16:58 +02:00 committed by GitHub
parent 721e10a02f
commit f16b83170a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 172 additions and 0 deletions

View file

@ -33,6 +33,7 @@ var (
_ resource.Resource = &networkInterfaceResource{}
_ resource.ResourceWithConfigure = &networkInterfaceResource{}
_ resource.ResourceWithImportState = &networkInterfaceResource{}
_ resource.ResourceWithModifyPlan = &networkInterfaceResource{}
)
type Model struct {
@ -61,6 +62,38 @@ type networkInterfaceResource struct {
client *iaas.APIClient
}
// ModifyPlan implements resource.ResourceWithModifyPlan.
func (r *networkInterfaceResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
// skip initial empty configuration to avoid follow-up errors
if req.Config.Raw.IsNull() {
return
}
var configModel Model
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
if resp.Diagnostics.HasError() {
return
}
var planModel Model
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}
// If allowed_addresses were completly removed from the config this is not recognized by terraform
// since this field is optional and computed therefore this plan modifier is needed.
utils.CheckListRemoval(ctx, configModel.AllowedAddresses, planModel.AllowedAddresses, path.Root("allowed_addresses"), types.StringType, false, resp)
if resp.Diagnostics.HasError() {
return
}
// If security_group_ids were completly removed from the config this is not recognized by terraform
// since this field is optional and computed therefore this plan modifier is needed.
utils.CheckListRemoval(ctx, configModel.SecurityGroupIds, planModel.SecurityGroupIds, path.Root("security_group_ids"), types.StringType, true, resp)
if resp.Diagnostics.HasError() {
return
}
}
// Metadata returns the resource type name.
func (r *networkInterfaceResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_network_interface"