feat(iaas): add warning that behavior of network resource will change (#1031)
relates to STACKITTPR-366 * feat(iaas): add warning that behavior of network resource will change * fix: changed payload for ipv6_nameservers * if is unset / null: ipv6_nameservers will not be sent * if set list / empty list: ipv6_nameserver will be sent with the set list / empty list
This commit is contained in:
parent
10eced46c7
commit
4552b14edd
6 changed files with 372 additions and 47 deletions
|
|
@ -2,9 +2,11 @@ package network
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
|
|
@ -37,6 +39,13 @@ var (
|
|||
_ resource.ResourceWithImportState = &networkResource{}
|
||||
)
|
||||
|
||||
const (
|
||||
ipv4BehaviorChangeTitle = "Behavior of not configured `ipv4_nameservers` will change from January 2026"
|
||||
ipv4BehaviorChangeDescription = "When `ipv4_nameservers` is not set, it will be set to the network area's `default_nameservers`.\n" +
|
||||
"To prevent any nameserver configuration, the `ipv4_nameservers` attribute should be explicitly set to an empty list `[]`.\n" +
|
||||
"In cases where `ipv4_nameservers` are defined within the resource, the existing behavior will remain unchanged."
|
||||
)
|
||||
|
||||
// NewNetworkResource is a helper function to simplify the provider implementation.
|
||||
func NewNetworkResource() resource.Resource {
|
||||
return &networkResource{}
|
||||
|
|
@ -88,10 +97,6 @@ func (r *networkResource) Configure(ctx context.Context, req resource.ConfigureR
|
|||
// ModifyPlan implements resource.ResourceWithModifyPlan.
|
||||
// Use the modifier to set the effective region in the current plan.
|
||||
func (r *networkResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
// If the v1 api is used, it's not required to get the fallback region because it isn't used
|
||||
if !r.isExperimental {
|
||||
return
|
||||
}
|
||||
var configModel model.Model
|
||||
// skip initial empty configuration to avoid follow-up errors
|
||||
if req.Config.Raw.IsNull() {
|
||||
|
|
@ -108,6 +113,15 @@ func (r *networkResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
|
|||
return
|
||||
}
|
||||
|
||||
// Warning should only be shown during the plan of the creation. This can be detected by checking if the ID is set.
|
||||
if utils.IsUndefined(planModel.Id) && utils.IsUndefined(planModel.IPv4Nameservers) {
|
||||
addIPv4Warning(&resp.Diagnostics)
|
||||
}
|
||||
|
||||
// If the v1 api is used, it's not required to get the fallback region because it isn't used
|
||||
if !r.isExperimental {
|
||||
return
|
||||
}
|
||||
utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
|
|
@ -171,8 +185,11 @@ func (r *networkResource) ConfigValidators(_ context.Context) []resource.ConfigV
|
|||
|
||||
// Schema defines the schema for the resource.
|
||||
func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
description := "Network resource schema. Must have a `region` specified in the provider configuration."
|
||||
descriptionNote := fmt.Sprintf("~> %s. %s", ipv4BehaviorChangeTitle, ipv4BehaviorChangeDescription)
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Network resource schema. Must have a `region` specified in the provider configuration.",
|
||||
MarkdownDescription: fmt.Sprintf("%s\n%s", description, descriptionNote),
|
||||
Description: description,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: "Terraform's internal resource ID. It is structured as \"`project_id`,`network_id`\".",
|
||||
|
|
@ -212,7 +229,7 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re
|
|||
},
|
||||
},
|
||||
"nameservers": schema.ListAttribute{
|
||||
Description: "The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.",
|
||||
Description: "The nameservers of the network. This field is deprecated and will be removed in January 2026, use `ipv4_nameservers` to configure the nameservers for IPv4.",
|
||||
DeprecationMessage: "Use `ipv4_nameservers` to configure the nameservers for IPv4.",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
|
|
@ -259,7 +276,7 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re
|
|||
},
|
||||
},
|
||||
"prefixes": schema.ListAttribute{
|
||||
Description: "The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
|
||||
Description: "The prefixes of the network. This field is deprecated and will be removed in January 2026, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
|
||||
DeprecationMessage: "Use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
|
|
@ -299,6 +316,7 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re
|
|||
"ipv6_prefix": schema.StringAttribute{
|
||||
Description: "The IPv6 prefix of the network (CIDR).",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Validators: []validator.String{
|
||||
validate.CIDR(),
|
||||
},
|
||||
|
|
@ -309,6 +327,7 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re
|
|||
"ipv6_prefix_length": schema.Int64Attribute{
|
||||
Description: "The IPv6 prefix length of the network.",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"ipv6_prefixes": schema.ListAttribute{
|
||||
Description: "The IPv6 prefixes of the network.",
|
||||
|
|
@ -366,6 +385,18 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re
|
|||
|
||||
// Create creates the resource and sets the initial Terraform state.
|
||||
func (r *networkResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
// Retrieve values from plan
|
||||
var planModel model.Model
|
||||
diags := req.Plan.Get(ctx, &planModel)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
// When IPv4Nameserver is not set, print warning that the behavior of ipv4_nameservers will change
|
||||
if utils.IsUndefined(planModel.IPv4Nameservers) {
|
||||
addIPv4Warning(&resp.Diagnostics)
|
||||
}
|
||||
|
||||
if !r.isExperimental {
|
||||
v1network.Create(ctx, req, resp, r.client)
|
||||
} else {
|
||||
|
|
@ -409,3 +440,9 @@ func (r *networkResource) ImportState(ctx context.Context, req resource.ImportSt
|
|||
v2network.ImportState(ctx, req, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func addIPv4Warning(diags *diag.Diagnostics) {
|
||||
diags.AddAttributeWarning(path.Root("ipv4_nameservers"),
|
||||
ipv4BehaviorChangeTitle,
|
||||
ipv4BehaviorChangeDescription)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue