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

New resource: aws_route53_resolver_config #27487

Merged
merged 44 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0597c55
acctest.PreCheckRegion: Accept list of Regions.
ewbankkit Oct 24, 2022
3d591af
r/aws_route53_query_log: Tidy up acceptance tests.
ewbankkit Oct 24, 2022
af40aa7
r/aws_route53_query_log: Add 'FindQueryLoggingConfigByID'.
ewbankkit Oct 24, 2022
6e2dfdd
r/aws_route53_query_log: Switch to 'WithoutTimeout' CRUD handlers (#1…
ewbankkit Oct 24, 2022
ecc65b9
r/aws_route53_resolver_query_log_config: 'FindResolverQueryLogConfigB…
ewbankkit Oct 24, 2022
9744915
r/aws_route53_resolver_query_log_config: Switch to 'WithoutTimeout' C…
ewbankkit Oct 24, 2022
f5cd9b8
r/aws_route53_resolver_query_log_config_association: 'FindResolverQue…
ewbankkit Oct 24, 2022
d5cdb25
r/aws_route53_resolver_query_log_config_association: Switch to 'Witho…
ewbankkit Oct 24, 2022
127db46
r/aws_route53_resolver_dnssec_config: 'FindResolverDNSSECConfigByID' …
ewbankkit Oct 25, 2022
d7d3dfd
r/aws_route53_resolver_dnssec_config: Switch to 'WithoutTimeout' CRUD…
ewbankkit Oct 25, 2022
7376271
r/aws_route53_resolver_firewall_config: Switch to 'WithoutTimeout' CR…
ewbankkit Oct 25, 2022
b47a68b
r/aws_route53_resolver_firewall_domain_list: 'FindFirewallDomainListB…
ewbankkit Oct 25, 2022
9650443
r/aws_route53_resolver_firewall_domain_list: Switch to 'WithoutTimeou…
ewbankkit Oct 25, 2022
ec85afa
r/aws_route53_resolver_firewall_rule_group: 'FindFirewallRuleGroupByI…
ewbankkit Oct 25, 2022
9553b18
r/aws_route53_resolver_firewall_rule_group: Switch to 'WithoutTimeout…
ewbankkit Oct 25, 2022
0dd126d
r/aws_route53_resolver_firewall_rule_group_association: 'FindFirewall…
ewbankkit Oct 25, 2022
d8c1abf
r/aws_route53_resolver_firewall_rule_group_association: Switch to 'Wi…
ewbankkit Oct 25, 2022
f988931
r/aws_route53_resolver_firewall_rule: 'FindFirewallRuleByTwoPartKey' …
ewbankkit Oct 26, 2022
4793cd8
r/aws_route53_resolver_firewall_rule: Switch to 'WithoutTimeout' CRUD…
ewbankkit Oct 26, 2022
9b7b03a
Use 'acctest.ACMCertificateRandomSubDomain'.
ewbankkit Oct 26, 2022
1479e2e
r/aws_route53_resolver_config: New resource.
ewbankkit Oct 26, 2022
b71a30d
r/aws_route53_resolver_config: Documentation.
ewbankkit Oct 26, 2022
d5d7196
Add 'TestAccRoute53ResolverConfig_Disappears_vpc'.
ewbankkit Oct 26, 2022
4babe9f
'Route 53' -> 'Route53'.
ewbankkit Oct 26, 2022
dc91dc2
Fix golangci-lint 'unparam'.
ewbankkit Oct 26, 2022
650b44f
Add CHANGELOG entry.
ewbankkit Oct 26, 2022
b5331b7
Route53 Resolver: Fix sweepers.
ewbankkit Oct 26, 2022
621d3e3
r/aws_route53_resolver_rule: Add 'FindRuleByID'.
ewbankkit Oct 26, 2022
a54438f
r/aws_route53_resolver_rule: Tidy up acceptance tests.
ewbankkit Oct 26, 2022
3b8bd3f
r/aws_route53_resolver_rule: Switch to 'WithoutTimeout' CRUD handlers…
ewbankkit Oct 26, 2022
e61b483
d/aws_route53_resolver_rule: Correct sharing acceptance tests.
ewbankkit Oct 26, 2022
af7a5c4
Fix terrafmt error.
ewbankkit Oct 26, 2022
d6b6c6b
'FindRuleByID' -> 'FindResolverRuleByID'.
ewbankkit Oct 27, 2022
7f16640
r/aws_route53_resolver_rule_association: Add 'FindResolverRuleAssocia…
ewbankkit Oct 27, 2022
7bb7a2f
r/aws_route53_resolver_rule_association: Additional acceptance tests.
ewbankkit Oct 27, 2022
b1eb772
r/aws_route53_resolver_rule_association: Switch to 'WithoutTimeout' C…
ewbankkit Oct 27, 2022
2cb7e66
r/aws_route53_resolver_endpoint: Add 'FindResolverEndpointByID'.
ewbankkit Oct 27, 2022
120c37d
r/aws_route53_resolver_endpoint: Additional acceptance tests.
ewbankkit Oct 27, 2022
1caec73
r/aws_route53_resolver_endpoint: Switch to 'WithoutTimeout' CRUD hand…
ewbankkit Oct 27, 2022
6ceb2f4
d/aws_route53_resolver_endpoint: Tidy up acceptance tests.
ewbankkit Oct 27, 2022
d995cf8
d/aws_route53_resolver_endpoint: Switch to 'WithoutTimeout' CRUD hand…
ewbankkit Oct 27, 2022
f1810cc
Fix golangci-lint 'ineffassign'.
ewbankkit Oct 27, 2022
0af1ac9
Fix golangci-lint 'unparam'.
ewbankkit Oct 27, 2022
1a74c65
Fix terrafmt errors.
ewbankkit Oct 27, 2022
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
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 @@ -1921,6 +1921,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