-
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 #22620 from danquack/realtime-log-conifg
d/aws_cloudfront_realtime_log_config
- Loading branch information
Showing
6 changed files
with
209 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,3 @@ | ||
```release-note:new-data-source | ||
aws_cloudfront_realtime_log_config | ||
``` |
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
85 changes: 85 additions & 0 deletions
85
internal/service/cloudfront/realtime_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,85 @@ | ||
package cloudfront | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
) | ||
|
||
func DataSourceRealtimeLogConfig() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceRealtimeLogConfigRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"endpoint": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"kinesis_stream_config": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"role_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"stream_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"stream_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"fields": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"sampling_rate": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceRealtimeLogConfigRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).CloudFrontConn | ||
|
||
name := d.Get("name").(string) | ||
logConfig, err := FindRealtimeLogConfigByName(conn, name) | ||
if err != nil { | ||
return fmt.Errorf("error reading CloudFront Real-time Log Config (%s): %w", name, err) | ||
} | ||
d.SetId( | ||
aws.StringValue(logConfig.ARN), | ||
) | ||
d.Set("arn", logConfig.ARN) | ||
if err := d.Set("endpoint", flattenEndPoints(logConfig.EndPoints)); err != nil { | ||
return fmt.Errorf("error setting endpoint: %w", err) | ||
} | ||
d.Set("fields", aws.StringValueSlice(logConfig.Fields)) | ||
d.Set("name", logConfig.Name) | ||
d.Set("sampling_rate", logConfig.SamplingRate) | ||
|
||
return nil | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/service/cloudfront/realtime_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,50 @@ | ||
package cloudfront_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudfront" | ||
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 TestAccCloudFrontRealtimeLogConfigDataSource_basic(t *testing.T) { | ||
var v cloudfront.RealtimeLogConfig | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
samplingRate := sdkacctest.RandIntRange(1, 100) | ||
resourceName := "aws_cloudfront_realtime_log_config.test" | ||
dataSourceName := "data.aws_cloudfront_realtime_log_config.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(cloudfront.EndpointsID, t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, cloudfront.EndpointsID), | ||
Providers: acctest.Providers, | ||
CheckDestroy: testAccCheckCloudFrontRealtimeLogConfigDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccRealtimeLogConfigDataSource(rName, samplingRate), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCloudFrontRealtimeLogConfigExists(resourceName, &v), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.#", resourceName, "endpoint.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.stream_type", resourceName, "endpoint.0.stream_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.0.kinesis_stream_config.#", resourceName, "endpoint.0.kinesis_stream_config.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "sampling_rate", resourceName, "sampling_rate"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "fields.#", resourceName, "fields.#"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccRealtimeLogConfigDataSource(rName string, samplingRate int) string { | ||
return acctest.ConfigCompose( | ||
testAccRealtimeLogConfig(rName, samplingRate), ` | ||
data "aws_cloudfront_realtime_log_config" "test" { | ||
name = aws_cloudfront_realtime_log_config.test.name | ||
} | ||
`, | ||
) | ||
} |
45 changes: 45 additions & 0 deletions
45
website/docs/d/cloudfront_realtime_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,45 @@ | ||
--- | ||
subcategory: "CloudFront" | ||
layout: "aws" | ||
page_title: "AWS: aws_cloudfront_realtime_log_config" | ||
description: |- | ||
Provides a CloudFront real-time log configuration resource. | ||
--- | ||
|
||
# Data Source: aws_cloudfront_realtime_log_config | ||
|
||
Provides a CloudFront real-time log configuration resource. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_cloudfront_realtime_log_config" "example" { | ||
name = "example" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The unique name to identify this real-time log configuration. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `arn` - The ARN (Amazon Resource Name) of the CloudFront real-time log configuration. | ||
* `endpoint` - (Required) The Amazon Kinesis data streams where real-time log data is sent. | ||
* `fields` - (Required) The fields that are included in each real-time log record. See the [AWS documentation](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-fields) for supported values. | ||
* `sampling_rate` - (Required) The sampling rate for this real-time log configuration. The sampling rate determines the percentage of viewer requests that are represented in the real-time log data. An integer between `1` and `100`, inclusive. | ||
|
||
The `endpoint` object supports the following: | ||
|
||
* `kinesis_stream_config` - (Required) The Amazon Kinesis data stream configuration. | ||
* `stream_type` - (Required) The type of data stream where real-time log data is sent. The only valid value is `Kinesis`. | ||
|
||
The `kinesis_stream_config` object supports the following: | ||
|
||
* `role_arn` - (Required) The ARN of an [IAM role](iam_role.html) that CloudFront can use to send real-time log data to the Kinesis data stream. | ||
See the [AWS documentation](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-iam-role) for more information. | ||
* `stream_arn` - (Required) The ARN of the [Kinesis data stream](kinesis_stream.html). |