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

AWS ConfigService KMS encryption support #20800

Merged
merged 4 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/20600.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_config_delivery_channel: Add `s3_kms_key_arn` argument
```
9 changes: 9 additions & 0 deletions aws/resource_aws_config_delivery_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func resourceAwsConfigDeliveryChannel() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"s3_kms_key_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"sns_topic_arn": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -76,6 +81,9 @@ func resourceAwsConfigDeliveryChannelPut(d *schema.ResourceData, meta interface{
if v, ok := d.GetOk("s3_key_prefix"); ok {
channel.S3KeyPrefix = aws.String(v.(string))
}
if v, ok := d.GetOk("s3_kms_key_arn"); ok {
channel.S3KmsKeyArn = aws.String(v.(string))
}
if v, ok := d.GetOk("sns_topic_arn"); ok {
channel.SnsTopicARN = aws.String(v.(string))
}
Expand Down Expand Up @@ -151,6 +159,7 @@ func resourceAwsConfigDeliveryChannelRead(d *schema.ResourceData, meta interface
d.Set("name", channel.Name)
d.Set("s3_bucket_name", channel.S3BucketName)
d.Set("s3_key_prefix", channel.S3KeyPrefix)
d.Set("s3_kms_key_arn", channel.S3KmsKeyArn)
d.Set("sns_topic_arn", channel.SnsTopicARN)

if channel.ConfigSnapshotDeliveryProperties != nil {
Expand Down
35 changes: 34 additions & 1 deletion aws/resource_aws_config_delivery_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func testAccConfigDeliveryChannel_allParams(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", expectedName),
resource.TestCheckResourceAttr(resourceName, "s3_bucket_name", expectedBucketName),
resource.TestCheckResourceAttr(resourceName, "s3_key_prefix", "one/two/three"),
resource.TestCheckResourceAttrPair(resourceName, "s3_kms_key_arn", "aws_kms_key.k", "arn"),
resource.TestCheckResourceAttrPair(resourceName, "sns_topic_arn", "aws_sns_topic.t", "arn"),
resource.TestCheckResourceAttr(resourceName, "snapshot_delivery_properties.0.delivery_frequency", "Six_Hours"),
),
Expand Down Expand Up @@ -320,6 +321,14 @@ resource "aws_iam_role_policy" "p" {
"${aws_s3_bucket.b.arn}",
"${aws_s3_bucket.b.arn}/*"
]
},
{
"Effect": "Allow",
"Action": [
"kms:Decrypt",
"kms:GenerateDataKey"
],
"Resource": "${aws_kms_key.k.arn}"
}
]
}
Expand All @@ -335,10 +344,34 @@ resource "aws_sns_topic" "t" {
name = "tf-acc-test-%d"
}

resource "aws_kms_key" "k" {
description = "tf-acc-test-awsconfig-%d"
deletion_window_in_days = 7

policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "tf-acc-test-awsconfig-%d",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
POLICY
}

resource "aws_config_delivery_channel" "foo" {
name = "tf-acc-test-awsconfig-%d"
s3_bucket_name = aws_s3_bucket.b.bucket
s3_key_prefix = "one/two/three"
s3_kms_key_arn = aws_kms_key.k.arn
sns_topic_arn = aws_sns_topic.t.arn

snapshot_delivery_properties {
Expand All @@ -347,5 +380,5 @@ resource "aws_config_delivery_channel" "foo" {

depends_on = [aws_config_configuration_recorder.foo]
}
`, randInt, randInt, randInt, randInt, randInt, randInt)
`, randInt, randInt, randInt, randInt, randInt, randInt, randInt, randInt)
}
1 change: 1 addition & 0 deletions website/docs/r/config_delivery_channel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The following arguments are supported:
* `name` - (Optional) The name of the delivery channel. Defaults to `default`. Changing it recreates the resource.
* `s3_bucket_name` - (Required) The name of the S3 bucket used to store the configuration history.
* `s3_key_prefix` - (Optional) The prefix for the specified S3 bucket.
* `s3_kms_key_arn` - (Optional) The ARN of the AWS KMS key used to encrypt objects delivered by AWS Config. Must belong to the same Region as the destination S3 bucket.
* `sns_topic_arn` - (Optional) The ARN of the SNS topic that AWS Config delivers notifications to.
* `snapshot_delivery_properties` - (Optional) Options for how AWS Config delivers configuration snapshots. See below

Expand Down