diff --git a/internal/resources/metal/vlan/models.go b/internal/resources/metal/vlan/models.go index 92da521d6..e0d44568b 100644 --- a/internal/resources/metal/vlan/models.go +++ b/internal/resources/metal/vlan/models.go @@ -21,32 +21,22 @@ type DataSourceModel struct { func (m *DataSourceModel) parse(vlan *packngo.VirtualNetwork) diag.Diagnostics { m.ID = types.StringValue(vlan.ID) + m.VlanID = types.StringValue(vlan.ID) + m.Description = types.StringValue(vlan.Description) + m.Vxlan = types.Int64Value(int64(vlan.VXLAN)) + m.Facility = types.StringNull() if vlan.Project.ID != "" { m.ProjectID = types.StringValue(vlan.Project.ID) } - m.VlanID = types.StringValue(vlan.ID) - m.Description = types.StringValue(vlan.Description) - m.Vxlan = types.Int64Value(int64(vlan.VXLAN)) - - var metroCode, facilityCode types.String if vlan.Facility != nil { - facilityCode = types.StringValue(vlan.Facility.Code) - metroCode = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) - } - // version of this resource. StateFunc doesn't exist in terraform and it requires implementation - // of bespoke logic before storing state. To ensure backward compatibility we ignore lower/upper - // case diff for now, but we may want to require input upper case - if !strings.EqualFold(m.Facility.ValueString(), facilityCode.ValueString()) { - m.Facility = facilityCode + m.Facility = types.StringValue(strings.ToLower(vlan.Facility.Code)) + m.Metro = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) } if vlan.Metro != nil { - metroCode = types.StringValue(strings.ToLower(vlan.Metro.Code)) - } - if !strings.EqualFold(m.Metro.ValueString(), metroCode.ValueString()) { - m.Metro = metroCode + m.Metro = types.StringValue(strings.ToLower(vlan.Metro.Code)) } deviceIds := make([]types.String, 0, len(vlan.Instances)) @@ -70,28 +60,20 @@ func (m *ResourceModel) parse(vlan *packngo.VirtualNetwork) diag.Diagnostics { m.ID = types.StringValue(vlan.ID) m.Description = types.StringValue(vlan.Description) m.Vxlan = types.Int64Value(int64(vlan.VXLAN)) + m.Facility = types.StringNull() if vlan.Project.ID != "" { m.ProjectID = types.StringValue(vlan.Project.ID) } - var metroCode, facilityCode types.String if vlan.Facility != nil { - facilityCode = types.StringValue(vlan.Facility.Code) - metroCode = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) - } - // version of this resource. StateFunc doesn't exist in terraform and it requires implementation - // of bespoke logic before storing state. To ensure backward compatibility we ignore lower/upper - // case diff for now, but we may want to require input upper case - if !strings.EqualFold(m.Facility.ValueString(), facilityCode.ValueString()) { - m.Facility = facilityCode + m.Facility = types.StringValue(strings.ToLower(vlan.Facility.Code)) + m.Metro = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) } if vlan.Metro != nil { - metroCode = types.StringValue(strings.ToLower(vlan.Metro.Code)) - } - if !strings.EqualFold(m.Metro.ValueString(), metroCode.ValueString()) { - m.Metro = metroCode + m.Metro = types.StringValue(strings.ToLower(vlan.Metro.Code)) } + return nil } diff --git a/internal/resources/metal/vlan/resource_schema.go b/internal/resources/metal/vlan/resource_schema.go index 11405c340..b1e2cde5d 100644 --- a/internal/resources/metal/vlan/resource_schema.go +++ b/internal/resources/metal/vlan/resource_schema.go @@ -2,14 +2,17 @@ package vlan import ( "context" - equinixplanmodifiers "github.com/equinix/terraform-provider-equinix/internal/planmodifiers" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + equinixplanmodifiers "github.com/equinix/terraform-provider-equinix/internal/planmodifiers" ) func resourceSchema(ctx context.Context) schema.Schema { @@ -40,6 +43,7 @@ func resourceSchema(ctx context.Context) schema.Schema { Description: "Facility where to create the VLAN", DeprecationMessage: "Use metro instead of facility. For more information, read the migration guide: https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_facilities_to_metros_devices", Optional: true, + Computed: true, Validators: []validator.String{ stringvalidator.ConflictsWith(path.MatchRoot("metro")), }, @@ -47,6 +51,7 @@ func resourceSchema(ctx context.Context) schema.Schema { stringplanmodifier.RequiresReplace(), stringplanmodifier.UseStateForUnknown(), }, + Default: stringdefault.StaticString(""), }, "metro": schema.StringAttribute{ Description: "Metro in which to create the VLAN",