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_ses_receipt_rule fails when kms_key_arn is not specified #4965

Merged
merged 3 commits into from Jun 25, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions aws/resource_aws_ses_receipt_rule.go
Expand Up @@ -683,9 +683,15 @@ func buildReceiptRule(d *schema.ResourceData, meta interface{}) *ses.ReceiptRule
elem := element.(map[string]interface{})

s3Action := &ses.S3Action{
BucketName: aws.String(elem["bucket_name"].(string)),
KmsKeyArn: aws.String(elem["kms_key_arn"].(string)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please add an acceptance test which fails on master and passes with this patch to ensure we don't hit this regression in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

ObjectKeyPrefix: aws.String(elem["object_key_prefix"].(string)),
BucketName: aws.String(elem["bucket_name"].(string)),
}

if elem["kms_key_arn"] != "" {
s3Action.KmsKeyArn = aws.String(elem["kms_key_arn"].(string))
}

if elem["object_key_prefix"] != "" {
s3Action.ObjectKeyPrefix = aws.String(elem["object_key_prefix"].(string))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although i think this change is harmless, assigning object_key_prefix with value "" (equivalent to not providing the param at Terraform level) works at AWS level

}

if elem["topic_arn"] != "" {
Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_ses_receipt_rule_test.go
Expand Up @@ -31,6 +31,24 @@ func TestAccAWSSESReceiptRule_basic(t *testing.T) {
})
}

func TestAccAWSSESReceiptRule_s3Action(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckSESReceiptRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSSESReceiptRuleS3ActionConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsSESReceiptRuleExists("aws_ses_receipt_rule.basic"),
),
},
},
})
}

func TestAccAWSSESReceiptRule_order(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -244,6 +262,32 @@ resource "aws_ses_receipt_rule" "basic" {
}
`, srrsRandomInt)

var testAccAWSSESReceiptRuleS3ActionConfig = fmt.Sprintf(`
resource "aws_ses_receipt_rule_set" "test" {
rule_set_name = "test-me-%d"
}

resource "aws_s3_bucket" "emails" {
bucket = "ses-terraform-emails-%d"
acl = "public-read-write"
force_destroy = "true"
}

resource "aws_ses_receipt_rule" "basic" {
name = "basic"
rule_set_name = "${aws_ses_receipt_rule_set.test.rule_set_name}"
recipients = ["test@example.com"]
enabled = true
scan_enabled = true
tls_policy = "Require"

s3_action {
bucket_name = "${aws_s3_bucket.emails.id}"
position = 1
}
}
`, srrsRandomInt, srrsRandomInt)

var testAccAWSSESReceiptRuleOrderConfig = fmt.Sprintf(`
resource "aws_ses_receipt_rule_set" "test" {
rule_set_name = "test-me-%d"
Expand Down