From d5258db88a05a6366a7a175126497efe20766127 Mon Sep 17 00:00:00 2001 From: Stephen Nelson Date: Wed, 17 Jan 2024 03:37:17 -0500 Subject: [PATCH 1/3] update domain delegation name servers to a set --- .../framework/resources/domain_delegation_resource.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/internal/framework/resources/domain_delegation_resource.go b/internal/framework/resources/domain_delegation_resource.go index 62a8f7b0..bfe826fe 100644 --- a/internal/framework/resources/domain_delegation_resource.go +++ b/internal/framework/resources/domain_delegation_resource.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" @@ -39,7 +38,7 @@ type DomainDelegationResource struct { type DomainDelegationResourceModel struct { Id types.String `tfsdk:"id"` Domain types.String `tfsdk:"domain"` - NameServers types.List `tfsdk:"name_servers"` + NameServers types.Set `tfsdk:"name_servers"` } func (r *DomainDelegationResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -58,12 +57,9 @@ func (r *DomainDelegationResource) Schema(_ context.Context, _ resource.SchemaRe stringplanmodifier.RequiresReplace(), }, }, - "name_servers": schema.ListAttribute{ + "name_servers": schema.SetAttribute{ Required: true, ElementType: types.StringType, - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplace(), - }, }, }, } @@ -190,7 +186,7 @@ func (r *DomainDelegationResource) ImportState(ctx context.Context, req resource } func (r *DomainDelegationResource) updateModelFromAPIResponse(ctx context.Context, delegation *dnsimple.Delegation, data *DomainDelegationResourceModel) diag.Diagnostics { - nameServers, diag := types.ListValueFrom(ctx, types.StringType, delegation) + nameServers, diag := types.SetValueFrom(ctx, types.StringType, delegation) data.NameServers = nameServers return diag } From f36ae095d49ff2a8f9c654f147c2217ace55a7e6 Mon Sep 17 00:00:00 2001 From: Stephen Nelson Date: Wed, 17 Jan 2024 04:08:23 -0500 Subject: [PATCH 2/3] update domain delegation tests --- .../framework/resources/domain_delegation_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/framework/resources/domain_delegation_resource_test.go b/internal/framework/resources/domain_delegation_resource_test.go index 181cfeef..42edfc99 100644 --- a/internal/framework/resources/domain_delegation_resource_test.go +++ b/internal/framework/resources/domain_delegation_resource_test.go @@ -27,8 +27,8 @@ func TestAccDomainDelegationResource(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttr(resourceName, "domain", domainId), resource.TestCheckResourceAttr(resourceName, "name_servers.#", "2"), - resource.TestCheckResourceAttr(resourceName, "name_servers.0", "ns-998.awsdns-60.net"), - resource.TestCheckResourceAttr(resourceName, "name_servers.1", "ns-1556.awsdns-02.co.uk"), + resource.TestCheckTypeSetElemAttr(resourceName, "name_servers.*", "ns-998.awsdns-60.net"), + resource.TestCheckTypeSetElemAttr(resourceName, "name_servers.*", "ns-1556.awsdns-02.co.uk"), ), }, { From 8684cac33e8a858d56f5d57b8150f281eba9280c Mon Sep 17 00:00:00 2001 From: DXTimer Date: Wed, 17 Jan 2024 14:08:25 +0200 Subject: [PATCH 3/3] extend domain delegation tests --- .../domain_delegation_resource_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/framework/resources/domain_delegation_resource_test.go b/internal/framework/resources/domain_delegation_resource_test.go index 42edfc99..8bbbde52 100644 --- a/internal/framework/resources/domain_delegation_resource_test.go +++ b/internal/framework/resources/domain_delegation_resource_test.go @@ -31,6 +31,18 @@ func TestAccDomainDelegationResource(t *testing.T) { resource.TestCheckTypeSetElemAttr(resourceName, "name_servers.*", "ns-1556.awsdns-02.co.uk"), ), }, + { + Config: testAccDomainDelegationResourceConfigReversed(domainId), + ExpectNonEmptyPlan: false, + PlanOnly: true, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "domain", domainId), + resource.TestCheckResourceAttr(resourceName, "name_servers.#", "2"), + resource.TestCheckTypeSetElemAttr(resourceName, "name_servers.*", "ns-998.awsdns-60.net"), + resource.TestCheckTypeSetElemAttr(resourceName, "name_servers.*", "ns-1556.awsdns-02.co.uk"), + ), + }, { ResourceName: resourceName, ImportStateIdFunc: testAccDomainDelegationImportStateIDFunc(resourceName), @@ -69,3 +81,11 @@ resource "dnsimple_domain_delegation" "test" { name_servers = ["ns-998.awsdns-60.net", "ns-1556.awsdns-02.co.uk"] }`, domainId) } + +func testAccDomainDelegationResourceConfigReversed(domainId string) string { + return fmt.Sprintf(` +resource "dnsimple_domain_delegation" "test" { + domain = %[1]q + name_servers = ["ns-1556.awsdns-02.co.uk", "ns-998.awsdns-60.net"] +}`, domainId) +}