-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource/aws_route53_resolver_firewall_domain_list: Add new resource
- Loading branch information
Showing
7 changed files
with
619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
aws/resource_aws_route53_resolver_firewall_domain_list.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/route53resolver" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/route53resolver/finder" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/route53resolver/waiter" | ||
) | ||
|
||
func resourceAwsRoute53ResolverFirewallDomainList() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsRoute53ResolverFirewallDomainListCreate, | ||
Read: resourceAwsRoute53ResolverFirewallDomainListRead, | ||
Update: resourceAwsRoute53ResolverFirewallDomainListUpdate, | ||
Delete: resourceAwsRoute53ResolverFirewallDomainListDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validateRoute53ResolverName, | ||
}, | ||
|
||
"domains": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
MinItems: 0, | ||
MaxItems: 255, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
|
||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsRoute53ResolverFirewallDomainListCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).route53resolverconn | ||
|
||
input := &route53resolver.CreateFirewallDomainListInput{ | ||
CreatorRequestId: aws.String(resource.PrefixedUniqueId("tf-r53-resolver-firewall-domain-list-")), | ||
Name: aws.String(d.Get("name").(string)), | ||
} | ||
if v, ok := d.GetOk("tags"); ok && len(v.(map[string]interface{})) > 0 { | ||
input.Tags = keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().Route53resolverTags() | ||
} | ||
|
||
log.Printf("[DEBUG] Creating Route 53 Resolver DNS Firewall domain list: %#v", input) | ||
output, err := conn.CreateFirewallDomainList(input) | ||
if err != nil { | ||
return fmt.Errorf("error creating Route 53 Resolver DNS Firewall domain list: %w", err) | ||
} | ||
|
||
d.SetId(aws.StringValue(output.FirewallDomainList.Id)) | ||
d.Set("arn", output.FirewallDomainList.Arn) | ||
|
||
return resourceAwsRoute53ResolverFirewallDomainListUpdate(d, meta) | ||
} | ||
|
||
func resourceAwsRoute53ResolverFirewallDomainListRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).route53resolverconn | ||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
firewallDomainList, err := finder.FirewallDomainListByID(conn, d.Id()) | ||
|
||
if isAWSErr(err, route53resolver.ErrCodeResourceNotFoundException, "") { | ||
log.Printf("[WARN] Route53 Resolver DNS Firewall domain list (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Route 53 Resolver DNS Firewall domain list (%s): %w", d.Id(), err) | ||
} | ||
|
||
if firewallDomainList == nil { | ||
log.Printf("[WARN] Route 53 Resolver DNS Firewall domain list (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
arn := aws.StringValue(firewallDomainList.Arn) | ||
d.Set("arn", arn) | ||
d.Set("id", firewallDomainList.Id) | ||
d.Set("name", firewallDomainList.Name) | ||
|
||
input := &route53resolver.ListFirewallDomainsInput{ | ||
FirewallDomainListId: aws.String(d.Id()), | ||
} | ||
|
||
domains := []*string{} | ||
|
||
err = conn.ListFirewallDomainsPages(input, func(output *route53resolver.ListFirewallDomainsOutput, lastPage bool) bool { | ||
domains = append(domains, output.Domains...) | ||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing Route 53 Resolver DNS Firewall domain list (%s) domains: %w", d.Id(), err) | ||
} | ||
|
||
d.Set("domains", flattenStringSet(domains)) | ||
|
||
tags, err := keyvaluetags.Route53resolverListTags(conn, arn) | ||
if err != nil { | ||
return fmt.Errorf("error listing tags for Route53 Resolver DNS Firewall domain list (%s): %w", arn, err) | ||
} | ||
|
||
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsRoute53ResolverFirewallDomainListUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).route53resolverconn | ||
|
||
if v, ok := d.GetOk("domains"); ok && d.HasChange("domains") { | ||
_, err := conn.UpdateFirewallDomains(&route53resolver.UpdateFirewallDomainsInput{ | ||
FirewallDomainListId: aws.String(d.Id()), | ||
Domains: expandStringSet(v.(*schema.Set)), | ||
Operation: aws.String(route53resolver.FirewallDomainUpdateOperationReplace), | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error updating Route 53 Resolver DNS Firewall domain list (%s) domains: %w", d.Id(), err) | ||
} | ||
|
||
_, err = waiter.FirewallDomainListUpdated(conn, d.Id()) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error waiting for Route 53 Resolver DNS Firewall domain list (%s) domains to be updated: %w", d.Id(), err) | ||
} | ||
} | ||
|
||
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 resourceAwsRoute53ResolverFirewallDomainListRead(d, meta) | ||
} | ||
|
||
func resourceAwsRoute53ResolverFirewallDomainListDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).route53resolverconn | ||
|
||
_, err := conn.DeleteFirewallDomainList(&route53resolver.DeleteFirewallDomainListInput{ | ||
FirewallDomainListId: aws.String(d.Id()), | ||
}) | ||
|
||
if isAWSErr(err, route53resolver.ErrCodeResourceNotFoundException, "") { | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error deleting Route 53 Resolver DNS Firewall domain list (%s): %w", d.Id(), err) | ||
} | ||
|
||
_, err = waiter.FirewallDomainListDeleted(conn, d.Id()) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error waiting for Route 53 Resolver DNS Firewall domain list (%s) to be deleted: %w", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.