Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update domain delegation name servers to a set #186

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}