From 3777803fbb1903751d5cdef0c995f0bc99115cdb Mon Sep 17 00:00:00 2001 From: Gareth Oakley Date: Thu, 8 Apr 2021 23:18:58 +0100 Subject: [PATCH] resource/aws_route53_resolver_firewall_domain_list: Address review comments --- ...s_route53_resolver_firewall_domain_list.go | 26 ++++++++++++++++--- ...te53_resolver_firewall_domain_list_test.go | 11 +++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_route53_resolver_firewall_domain_list.go b/aws/resource_aws_route53_resolver_firewall_domain_list.go index f9ee9c5cfba..2a4b348b1ff 100644 --- a/aws/resource_aws_route53_resolver_firewall_domain_list.go +++ b/aws/resource_aws_route53_resolver_firewall_domain_list.go @@ -136,11 +136,29 @@ func resourceAwsRoute53ResolverFirewallDomainListRead(d *schema.ResourceData, me func resourceAwsRoute53ResolverFirewallDomainListUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).route53resolverconn - if v, ok := d.GetOk("domains"); ok && d.HasChange("domains") { + if d.HasChange("domains") { + o, n := d.GetChange("domains") + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } + os := o.(*schema.Set) + ns := n.(*schema.Set) + + domains := ns + operation := route53resolver.FirewallDomainUpdateOperationReplace + + if domains.Len() == 0 { + domains = os + operation = route53resolver.FirewallDomainUpdateOperationRemove + } + _, err := conn.UpdateFirewallDomains(&route53resolver.UpdateFirewallDomainsInput{ FirewallDomainListId: aws.String(d.Id()), - Domains: expandStringSet(v.(*schema.Set)), - Operation: aws.String(route53resolver.FirewallDomainUpdateOperationReplace), + Domains: expandStringSet(domains), + Operation: aws.String(operation), }) if err != nil { @@ -157,7 +175,7 @@ func resourceAwsRoute53ResolverFirewallDomainListUpdate(d *schema.ResourceData, if d.HasChange("tags") { o, n := d.GetChange("tags") if err := keyvaluetags.Route53resolverUpdateTags(conn, d.Get("arn").(string), o, n); err != nil { - return fmt.Errorf("error updating Route53 Resolver DNS Firewall domain list (%s) tags: %s", d.Get("arn").(string), err) + return fmt.Errorf("error updating Route53 Resolver DNS Firewall domain list (%s) tags: %w", d.Get("arn").(string), err) } } diff --git a/aws/resource_aws_route53_resolver_firewall_domain_list_test.go b/aws/resource_aws_route53_resolver_firewall_domain_list_test.go index b5371b0066d..e24da89d3a6 100644 --- a/aws/resource_aws_route53_resolver_firewall_domain_list_test.go +++ b/aws/resource_aws_route53_resolver_firewall_domain_list_test.go @@ -18,9 +18,6 @@ func init() { resource.AddTestSweepers("aws_route53_resolver_firewall_domain_list", &resource.Sweeper{ Name: "aws_route53_resolver_firewall_domain_list", F: testSweepRoute53ResolverFirewallDomainLists, - Dependencies: []string{ - "aws_route53_resolver_firewall_domain_list_association", - }, }) } @@ -128,6 +125,14 @@ func TestAccAWSRoute53ResolverFirewallDomainList_domains(t *testing.T) { resource.TestCheckTypeSetElemAttr(resourceName, "domains.*", "bar.com."), ), }, + { + Config: testAccRoute53ResolverFirewallDomainListConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53ResolverFirewallDomainListExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "domains.#", "0"), + ), + }, }, }) }