-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource/aws_pinpoint_email_channel: Support using SES configuration …
…set and add plan time validations (#18314) Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSPinpointEmailChannel_disappears (19.13s) --- PASS: TestAccAWSPinpointEmailChannel_configurationSet (22.62s) --- PASS: TestAccAWSPinpointEmailChannel_basic (34.66s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- PASS: TestAccAWSPinpointEmailChannel_disappears (27.30s) --- PASS: TestAccAWSPinpointEmailChannel_configurationSet (33.09s) --- PASS: TestAccAWSPinpointEmailChannel_basic (53.08s) ```
- Loading branch information
Showing
4 changed files
with
161 additions
and
24 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,7 @@ | ||
```release-note:enhancement | ||
resource/aws_pinpoint_email_channel: Add `configuration_set` argument | ||
``` | ||
|
||
```release-note:enhancement | ||
resource/aws_pinpoint_email_channel: Add plan time validation for `identity` and `role_arn` | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,14 @@ import ( | |
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/pinpoint" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccAWSPinpointEmailChannel_basic(t *testing.T) { | ||
var channel pinpoint.EmailChannelResponse | ||
resourceName := "aws_pinpoint_email_channel.test_email_channel" | ||
resourceName := "aws_pinpoint_email_channel.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSPinpointApp(t) }, | ||
|
@@ -27,6 +28,8 @@ func TestAccAWSPinpointEmailChannel_basic(t *testing.T) { | |
testAccCheckAWSPinpointEmailChannelExists(resourceName, &channel), | ||
resource.TestCheckResourceAttr(resourceName, "enabled", "false"), | ||
resource.TestCheckResourceAttrSet(resourceName, "messages_per_second"), | ||
resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.test", "arn"), | ||
resource.TestCheckResourceAttrPair(resourceName, "identity", "aws_ses_domain_identity.test", "arn"), | ||
), | ||
}, | ||
{ | ||
|
@@ -46,6 +49,56 @@ func TestAccAWSPinpointEmailChannel_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSPinpointEmailChannel_configurationSet(t *testing.T) { | ||
var channel pinpoint.EmailChannelResponse | ||
resourceName := "aws_pinpoint_email_channel.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSPinpointApp(t) }, | ||
ErrorCheck: testAccErrorCheck(t, pinpoint.EndpointsID), | ||
IDRefreshName: resourceName, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSPinpointEmailChannelDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSPinpointEmailChannelConfigConfigurationSet("[email protected]", rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSPinpointEmailChannelExists(resourceName, &channel), | ||
resource.TestCheckResourceAttrPair(resourceName, "configuration_set", "aws_ses_configuration_set.test", "arn"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
func TestAccAWSPinpointEmailChannel_disappears(t *testing.T) { | ||
var channel pinpoint.EmailChannelResponse | ||
resourceName := "aws_pinpoint_email_channel.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSPinpointApp(t) }, | ||
ErrorCheck: testAccErrorCheck(t, pinpoint.EndpointsID), | ||
IDRefreshName: resourceName, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSPinpointEmailChannelDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSPinpointEmailChannelConfig_FromAddress("[email protected]"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSPinpointEmailChannelExists(resourceName, &channel), | ||
testAccCheckResourceDisappears(testAccProvider, resourceAwsPinpointEmailChannel(), resourceName), | ||
), | ||
ExpectNonEmptyPlan: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSPinpointEmailChannelExists(n string, channel *pinpoint.EmailChannelResponse) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
@@ -77,21 +130,21 @@ func testAccCheckAWSPinpointEmailChannelExists(n string, channel *pinpoint.Email | |
|
||
func testAccAWSPinpointEmailChannelConfig_FromAddress(fromAddress string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_pinpoint_app" "test_app" {} | ||
resource "aws_pinpoint_app" "test" {} | ||
resource "aws_pinpoint_email_channel" "test_email_channel" { | ||
application_id = aws_pinpoint_app.test_app.application_id | ||
resource "aws_pinpoint_email_channel" "test" { | ||
application_id = aws_pinpoint_app.test.application_id | ||
enabled = "false" | ||
from_address = %[1]q | ||
identity = aws_ses_domain_identity.test_identity.arn | ||
role_arn = aws_iam_role.test_role.arn | ||
identity = aws_ses_domain_identity.test.arn | ||
role_arn = aws_iam_role.test.arn | ||
} | ||
resource "aws_ses_domain_identity" "test_identity" { | ||
resource "aws_ses_domain_identity" "test" { | ||
domain = "example.com" | ||
} | ||
resource "aws_iam_role" "test_role" { | ||
resource "aws_iam_role" "test" { | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
|
@@ -109,9 +162,9 @@ resource "aws_iam_role" "test_role" { | |
EOF | ||
} | ||
resource "aws_iam_role_policy" "test_role_policy" { | ||
name = "test_policy" | ||
role = aws_iam_role.test_role.id | ||
resource "aws_iam_role_policy" "test" { | ||
name = "test" | ||
role = aws_iam_role.test.id | ||
policy = <<EOF | ||
{ | ||
|
@@ -132,6 +185,68 @@ EOF | |
`, fromAddress) | ||
} | ||
|
||
func testAccAWSPinpointEmailChannelConfigConfigurationSet(fromAddress, rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_pinpoint_app" "test" {} | ||
resource "aws_ses_configuration_set" "test" { | ||
name = %[2]q | ||
} | ||
resource "aws_pinpoint_email_channel" "test" { | ||
application_id = aws_pinpoint_app.test.application_id | ||
enabled = "false" | ||
from_address = %[1]q | ||
identity = aws_ses_domain_identity.test.arn | ||
role_arn = aws_iam_role.test.arn | ||
configuration_set = aws_ses_configuration_set.test.arn | ||
} | ||
resource "aws_ses_domain_identity" "test" { | ||
domain = "example.com" | ||
} | ||
resource "aws_iam_role" "test" { | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "pinpoint.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
resource "aws_iam_role_policy" "test" { | ||
name = "test" | ||
role = aws_iam_role.test.id | ||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": { | ||
"Action": [ | ||
"mobileanalytics:PutEvents", | ||
"mobileanalytics:PutItems" | ||
], | ||
"Effect": "Allow", | ||
"Resource": [ | ||
"*" | ||
] | ||
} | ||
} | ||
EOF | ||
} | ||
`, fromAddress, rName) | ||
} | ||
|
||
func testAccCheckAWSPinpointEmailChannelDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).pinpointconn | ||
|
||
|
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