Skip to content

Commit

Permalink
resource/aws_route53_resolver_firewall_domain_list: Address review co…
Browse files Browse the repository at this point in the history
…mments
  • Loading branch information
gazoakley committed Apr 10, 2021
1 parent 0bceac3 commit 3777803
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
26 changes: 22 additions & 4 deletions aws/resource_aws_route53_resolver_firewall_domain_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down
11 changes: 8 additions & 3 deletions aws/resource_aws_route53_resolver_firewall_domain_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
})
}

Expand Down Expand Up @@ -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"),
),
},
},
})
}
Expand Down

0 comments on commit 3777803

Please sign in to comment.