Skip to content

Commit

Permalink
Merge pull request #27487 from hashicorp/f-aws_route53_resolver_config
Browse files Browse the repository at this point in the history
New resource: `aws_route53_resolver_config`
  • Loading branch information
ewbankkit authored Oct 27, 2022
2 parents 1de12b2 + 1a74c65 commit cae97fd
Show file tree
Hide file tree
Showing 45 changed files with 3,075 additions and 2,881 deletions.
3 changes: 3 additions & 0 deletions .changelog/27487.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_route53_resolver_config
```
22 changes: 17 additions & 5 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,17 +691,29 @@ func PreCheckMultipleRegion(t *testing.T, regions int) {
}
}

// PreCheckRegion checks that the test region is the specified region.
func PreCheckRegion(t *testing.T, region string) {
if curr := Region(); curr != region {
t.Skipf("skipping tests; %s (%s) does not equal %s", envvar.DefaultRegion, curr, region)
// PreCheckRegion checks that the test region is one of the specified regions.
func PreCheckRegion(t *testing.T, regions ...string) {
curr := Region()
var regionOK bool

for _, region := range regions {
if curr == region {
regionOK = true
break
}
}

if !regionOK {
t.Skipf("skipping tests; %s (%s) not supported", envvar.DefaultRegion, curr)
}
}

// PreCheckRegionNot checks that the test region is not one of the specified regions.
func PreCheckRegionNot(t *testing.T, regions ...string) {
curr := Region()

for _, region := range regions {
if curr := Region(); curr == region {
if curr == region {
t.Skipf("skipping tests; %s (%s) not supported", envvar.DefaultRegion, curr)
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,7 @@ func New(_ context.Context) (*schema.Provider, error) {
"aws_route53recoveryreadiness_recovery_group": route53recoveryreadiness.ResourceRecoveryGroup(),
"aws_route53recoveryreadiness_resource_set": route53recoveryreadiness.ResourceResourceSet(),

"aws_route53_resolver_config": route53resolver.ResourceConfig(),
"aws_route53_resolver_dnssec_config": route53resolver.ResourceDNSSECConfig(),
"aws_route53_resolver_endpoint": route53resolver.ResourceEndpoint(),
"aws_route53_resolver_firewall_config": route53resolver.ResourceFirewallConfig(),
Expand Down
6 changes: 3 additions & 3 deletions internal/service/apigatewayv2/domain_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestAccAPIGatewayV2DomainName_updateCertificate(t *testing.T) {

func TestAccAPIGatewayV2DomainName_MutualTLSAuthentication_basic(t *testing.T) {
rootDomain := acctest.ACMCertificateDomainFromEnv(t)
domain := fmt.Sprintf("%s.%s", acctest.RandomSubdomain(), rootDomain)
domain := acctest.ACMCertificateRandomSubDomain(rootDomain)

var v apigatewayv2.GetDomainNameOutput
resourceName := "aws_apigatewayv2_domain_name.test"
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestAccAPIGatewayV2DomainName_MutualTLSAuthentication_basic(t *testing.T) {

func TestAccAPIGatewayV2DomainName_MutualTLSAuthentication_noVersion(t *testing.T) {
rootDomain := acctest.ACMCertificateDomainFromEnv(t)
domain := fmt.Sprintf("%s.%s", acctest.RandomSubdomain(), rootDomain)
domain := acctest.ACMCertificateRandomSubDomain(rootDomain)

var v apigatewayv2.GetDomainNameOutput
resourceName := "aws_apigatewayv2_domain_name.test"
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestAccAPIGatewayV2DomainName_MutualTLSAuthentication_noVersion(t *testing.

func TestAccAPIGatewayV2DomainName_MutualTLSAuthentication_ownership(t *testing.T) {
rootDomain := acctest.ACMCertificateDomainFromEnv(t)
domain := fmt.Sprintf("%s.%s", acctest.RandomSubdomain(), rootDomain)
domain := acctest.ACMCertificateRandomSubDomain(rootDomain)
key := acctest.TLSRSAPrivateKeyPEM(2048)
certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(key, domain)

Expand Down
21 changes: 21 additions & 0 deletions internal/service/route53/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ func FindKeySigningKeyByResourceID(conn *route53.Route53, resourceID string) (*r
return FindKeySigningKey(conn, hostedZoneID, name)
}

func FindQueryLoggingConfigByID(ctx context.Context, conn *route53.Route53, id string) (*route53.QueryLoggingConfig, error) {
input := &route53.GetQueryLoggingConfigInput{
Id: aws.String(id),
}

output, err := conn.GetQueryLoggingConfigWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, route53.ErrCodeNoSuchQueryLoggingConfig, route53.ErrCodeNoSuchHostedZone) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if output == nil || output.QueryLoggingConfig == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.QueryLoggingConfig, nil
}

func FindTrafficPolicyByID(ctx context.Context, conn *route53.Route53, id string) (*route53.TrafficPolicy, error) {
var latestVersion int64

Expand Down
68 changes: 33 additions & 35 deletions internal/service/route53/query_log.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package route53

import (
"context"
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

func ResourceQueryLog() *schema.Resource {
return &schema.Resource{
Create: resourceQueryLogCreate,
Read: resourceQueryLogRead,
Delete: resourceQueryLogDelete,
CreateWithoutTimeout: resourceQueryLogCreate,
ReadWithoutTimeout: resourceQueryLogRead,
DeleteWithoutTimeout: resourceQueryLogDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand All @@ -33,7 +37,6 @@ func ResourceQueryLog() *schema.Resource {
ForceNew: true,
ValidateFunc: verify.ValidARN,
},

"zone_id": {
Type: schema.TypeString,
Required: true,
Expand All @@ -43,71 +46,66 @@ func ResourceQueryLog() *schema.Resource {
}
}

func resourceQueryLogCreate(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*conns.AWSClient).Route53Conn
func resourceQueryLogCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).Route53Conn

input := &route53.CreateQueryLoggingConfigInput{
CloudWatchLogsLogGroupArn: aws.String(d.Get("cloudwatch_log_group_arn").(string)),
HostedZoneId: aws.String(d.Get("zone_id").(string)),
}

log.Printf("[DEBUG] Creating Route53 query logging configuration: %#v", input)
out, err := r53.CreateQueryLoggingConfig(input)
output, err := conn.CreateQueryLoggingConfigWithContext(ctx, input)

if err != nil {
return fmt.Errorf("Error creating Route53 query logging configuration: %s", err)
return diag.Errorf("creating Route53 Query Logging Config: %s", err)
}
log.Printf("[DEBUG] Route53 query logging configuration created: %#v", out)

d.SetId(aws.StringValue(out.QueryLoggingConfig.Id))
d.SetId(aws.StringValue(output.QueryLoggingConfig.Id))

return resourceQueryLogRead(d, meta)
return resourceQueryLogRead(ctx, d, meta)
}

func resourceQueryLogRead(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*conns.AWSClient).Route53Conn
func resourceQueryLogRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).Route53Conn

input := &route53.GetQueryLoggingConfigInput{
Id: aws.String(d.Id()),
output, err := FindQueryLoggingConfigByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Route53 Query Logging Config %s not found, removing from state", d.Id())
d.SetId("")
return nil
}
log.Printf("[DEBUG] Reading Route53 query logging configuration: %#v", input)
out, err := r53.GetQueryLoggingConfig(input)

if err != nil {
if tfawserr.ErrCodeEquals(err, route53.ErrCodeNoSuchQueryLoggingConfig) || tfawserr.ErrCodeEquals(err, route53.ErrCodeNoSuchHostedZone) {
log.Printf("[WARN] Route53 Query Logging Config (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("Error reading Route53 query logging configuration: %s", err)
return diag.Errorf("reading Route53 Query Logging Config (%s): %s", d.Id(), err)
}
log.Printf("[DEBUG] Route53 query logging configuration received: %#v", out)

d.Set("cloudwatch_log_group_arn", out.QueryLoggingConfig.CloudWatchLogsLogGroupArn)
d.Set("zone_id", out.QueryLoggingConfig.HostedZoneId)

arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Service: "route53",
Resource: fmt.Sprintf("queryloggingconfig/%s", d.Id()),
}.String()
d.Set("arn", arn)
d.Set("cloudwatch_log_group_arn", output.CloudWatchLogsLogGroupArn)
d.Set("zone_id", output.HostedZoneId)

return nil
}

func resourceQueryLogDelete(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*conns.AWSClient).Route53Conn
func resourceQueryLogDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).Route53Conn

input := &route53.DeleteQueryLoggingConfigInput{
log.Printf("[DEBUG] Deleting Route53 Query Logging Config: %s", d.Id())
_, err := conn.DeleteQueryLoggingConfigWithContext(ctx, &route53.DeleteQueryLoggingConfigInput{
Id: aws.String(d.Id()),
}
log.Printf("[DEBUG] Deleting Route53 query logging configuration: %#v", input)
_, err := r53.DeleteQueryLoggingConfig(input)
})

if tfawserr.ErrCodeEquals(err, route53.ErrCodeNoSuchQueryLoggingConfig) {
return nil
}

if err != nil {
return fmt.Errorf("deleting Route53 query logging configuration (%s): %w", d.Id(), err)
return diag.Errorf("deleting Route53 Query Logging Config (%s): %s", d.Id(), err)
}

return nil
Expand Down
Loading

0 comments on commit cae97fd

Please sign in to comment.