-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29111 from ValFadeev/f-aws_route53_resolver_query…
…_log_config_data_source New Data Source: aws_route53_resolver_query_log_config
- Loading branch information
Showing
5 changed files
with
288 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
```release-note:new-data-source | ||
aws_route53_resolver_query_log_config | ||
``` | ||
|
132 changes: 132 additions & 0 deletions
132
internal/service/route53resolver/query_log_config_data_source.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,132 @@ | ||
package route53resolver | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/route53resolver" | ||
"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/create" | ||
"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters" | ||
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
// @SDKDataSource("aws_route53_resolver_query_log_config") | ||
func DataSourceQueryLogConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataSourceQueryLogConfigRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"destination_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"filter": namevaluesfilters.Schema(), | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validResolverName, | ||
}, | ||
"owner_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resolver_query_log_config_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"share_status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tftags.TagsSchemaComputed(), | ||
}, | ||
} | ||
} | ||
|
||
const ( | ||
DSNameQueryLogConfig = "Query Log Config Data Source" | ||
) | ||
|
||
func dataSourceQueryLogConfigRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).Route53ResolverConn() | ||
|
||
configID := d.Get("resolver_query_log_config_id").(string) | ||
|
||
input := &route53resolver.ListResolverQueryLogConfigsInput{} | ||
|
||
if v, ok := d.GetOk("filter"); ok && v.(*schema.Set).Len() > 0 { | ||
input.Filters = namevaluesfilters.New(v.(*schema.Set)).Route53resolverFilters() | ||
} | ||
|
||
var configs []*route53resolver.ResolverQueryLogConfig | ||
|
||
err := conn.ListResolverQueryLogConfigsPagesWithContext(ctx, input, func(page *route53resolver.ListResolverQueryLogConfigsOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, v := range page.ResolverQueryLogConfigs { | ||
if configID != "" { | ||
if aws.StringValue(v.Id) == configID { | ||
configs = append(configs, v) | ||
} | ||
} else { | ||
configs = append(configs, v) | ||
} | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return diag.Errorf("listing Route53 resolver Query Logging Configurations: %s", err) | ||
} | ||
|
||
if n := len(configs); n == 0 { | ||
return create.DiagError(names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned no results, "+ | ||
"please change your search criteria and try again")) | ||
} else if n > 1 { | ||
return create.DiagError(names.Route53Resolver, create.ErrActionReading, DSNameQueryLogConfig, configID, errors.New("your query returned more than one result, "+ | ||
"please try more specific search criteria")) | ||
} | ||
|
||
config := configs[0] | ||
|
||
d.SetId(aws.StringValue(config.Id)) | ||
arn := aws.StringValue(config.Arn) | ||
d.Set("arn", arn) | ||
d.Set("destination_arn", config.DestinationArn) | ||
d.Set("name", config.Name) | ||
d.Set("owner_id", config.OwnerId) | ||
d.Set("resolver_query_log_config_id", config.Id) | ||
|
||
shareStatus := aws.StringValue(config.ShareStatus) | ||
d.Set("share_status", shareStatus) | ||
|
||
if shareStatus != route53resolver.ShareStatusSharedWithMe { | ||
tags, err := ListTags(ctx, conn, arn) | ||
|
||
if err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionReading, DSNameQueryLogConfig, configID, err) | ||
} | ||
|
||
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig | ||
tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) | ||
|
||
//lintignore:AWSR002 | ||
if err := d.Set("tags", tags.Map()); err != nil { | ||
return create.DiagError(names.AppConfig, create.ErrActionSetting, DSNameQueryLogConfig, configID, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
96 changes: 96 additions & 0 deletions
96
internal/service/route53resolver/query_log_config_data_source_test.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,96 @@ | ||
package route53resolver_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/route53resolver" | ||
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-aws/internal/acctest" | ||
) | ||
|
||
func TestAccRoute53ResolverQueryLogConfigDataSource_basic(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
|
||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
resourceName := "aws_route53_resolver_query_log_config.test" | ||
dataSourceName := "data.aws_route53_resolver_query_log_config.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(ctx, t) | ||
acctest.PreCheckPartitionHasService(t, route53resolver.EndpointsID) | ||
testAccPreCheck(ctx, t) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, route53resolver.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccQueryLogConfigDataSourceConfig_basic(rName, "key1", "value1"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "destination_arn", resourceName, "destination_arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "resolver_query_log_config_id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "share_status", resourceName, "share_status"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.key1", resourceName, "tags.key1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccRoute53ResolverQueryLogConfigDataSource_filter(t *testing.T) { | ||
ctx := acctest.Context(t) | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
resourceName := "aws_route53_resolver_query_log_config.test" | ||
dataSourceName := "data.aws_route53_resolver_query_log_config.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acctest.PreCheck(ctx, t) | ||
acctest.PreCheckPartitionHasService(t, route53resolver.EndpointsID) | ||
testAccPreCheck(ctx, t) | ||
}, | ||
ErrorCheck: acctest.ErrorCheck(t, route53resolver.EndpointsID), | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccQueryLogConfigDataSourceConfig_filter(rName, "key1", "value1"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "destination_arn", resourceName, "destination_arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "resolver_query_log_config_id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "share_status", resourceName, "share_status"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.key1", resourceName, "tags.key1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccQueryLogConfigDataSourceConfig_basic(rName string, tagKey string, tagValue string) string { | ||
return acctest.ConfigCompose(testAccQueryLogConfigConfig_tags1(rName, tagKey, tagValue), ` | ||
data "aws_route53_resolver_query_log_config" "test" { | ||
resolver_query_log_config_id = aws_route53_resolver_query_log_config.test.id | ||
} | ||
`) | ||
} | ||
|
||
func testAccQueryLogConfigDataSourceConfig_filter(rName string, tagKey string, tagValue string) string { | ||
return acctest.ConfigCompose(testAccQueryLogConfigConfig_tags1(rName, tagKey, tagValue), ` | ||
data "aws_route53_resolver_query_log_config" "test" { | ||
filter { | ||
name = "Name" | ||
values = [aws_route53_resolver_query_log_config.test.name] | ||
} | ||
} | ||
`) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
website/docs/d/route53_resolver_query_log_config.html.markdown
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,52 @@ | ||
--- | ||
subcategory: "Route 53 Resolver" | ||
layout: "aws" | ||
page_title: "AWS: aws_route53_resolver_query_log_config" | ||
description: |- | ||
Provides details about a specific Route53 Resolver Query Logging Configuration. | ||
--- | ||
|
||
# Data Source: aws_route53_resolver_query_log_config | ||
|
||
`aws_route53_resolver_query_log_config` provides details about a specific Route53 Resolver Query Logging Configuration. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_route53_resolver_query_log_config" "example" { | ||
resolver_query_log_config_id = "rqlc-1abc2345ef678g91h" | ||
} | ||
``` | ||
|
||
```terraform | ||
data "aws_route53_resolver_query_log_config" "example" { | ||
filter { | ||
name = "Name" | ||
values = ["shared-query-log-config"] | ||
} | ||
filter { | ||
name = "ShareStatus" | ||
values = ["SHARED_WITH_ME"] | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `resolver_query_log_config_id` - (Optional) ID of the Route53 Resolver Query Logging Configuration. | ||
* `filter` - (Optional) One or more name/value pairs to use as filters. There are | ||
several valid keys, for a full reference, check out | ||
[Route53resolver Filter value in the AWS API reference][1]. | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The ID for the query logging configuration. | ||
* `arn` - Computed ARN of the Route53 Resolver Query Logging Configuration. | ||
* `destination_arn` - The ARN of the resource that you want Resolver to send query logs: an Amazon S3 bucket, a CloudWatch Logs log group or a Kinesis Data Firehose delivery stream. | ||
* `name` - The name of the query logging configuration. | ||
* `owner_id` - The AWS account ID for the account that created the query logging configuration. | ||
* `share_status` - An indication of whether the query logging configuration is shared with other AWS accounts or was shared with the current account by another AWS account. | ||
* `tags` - Map of tags to assign to the service. | ||
|
||
[1]: https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53resolver_Filter.html |