Skip to content

Commit

Permalink
Update domain delegation name servers to a set (#186)
Browse files Browse the repository at this point in the history
* update domain delegation name servers to a set

---------

Co-authored-by: DXTimer <[email protected]>
  • Loading branch information
AGS4NO and DXTimer authored Jan 24, 2024
1 parent 7d5e7c3 commit bc71acb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 3 additions & 7 deletions internal/framework/resources/domain_delegation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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(),
},
},
},
}
Expand Down Expand Up @@ -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
}
24 changes: 22 additions & 2 deletions internal/framework/resources/domain_delegation_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ 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"),
),
},
{
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"),
),
},
{
Expand Down Expand Up @@ -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)
}

0 comments on commit bc71acb

Please sign in to comment.