Skip to content

Commit

Permalink
Merge pull request #41043 from acwwat/f-aws_pinpoint_email_channel-ad…
Browse files Browse the repository at this point in the history
…d_orchestration_sending_role_arn_arg

feat: Add orchestration_sending_role_arn arg for aws_pinpoint_email_channel
  • Loading branch information
ewbankkit authored Jan 23, 2025
2 parents 4902131 + a1c61b8 commit f9f9043
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/41043.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_pinpoint_email_channel: Add `orchestration_sending_role_arn` argument
```
10 changes: 10 additions & 0 deletions internal/service/pinpoint/email_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func resourceEmailChannel() *schema.Resource {
Required: true,
ValidateFunc: verify.ValidARN,
},
"orchestration_sending_role_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
names.AttrRoleARN: {
Type: schema.TypeString,
Optional: true,
Expand All @@ -81,6 +86,10 @@ func resourceEmailChannelUpsert(ctx context.Context, d *schema.ResourceData, met
params.FromAddress = aws.String(d.Get("from_address").(string))
params.Identity = aws.String(d.Get("identity").(string))

if v, ok := d.GetOk("orchestration_sending_role_arn"); ok {
params.OrchestrationSendingRoleArn = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrRoleARN); ok {
params.RoleArn = aws.String(v.(string))
}
Expand Down Expand Up @@ -126,6 +135,7 @@ func resourceEmailChannelRead(ctx context.Context, d *schema.ResourceData, meta
d.Set(names.AttrEnabled, output.Enabled)
d.Set("from_address", output.FromAddress)
d.Set("identity", output.Identity)
d.Set("orchestration_sending_role_arn", output.OrchestrationSendingRoleArn)
d.Set(names.AttrRoleARN, output.RoleArn)
d.Set("configuration_set", output.ConfigurationSet)
d.Set("messages_per_second", output.MessagesPerSecond)
Expand Down
95 changes: 95 additions & 0 deletions internal/service/pinpoint/email_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestAccPinpointEmailChannel_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "from_address", address1),
resource.TestCheckResourceAttrSet(resourceName, "messages_per_second"),
resource.TestCheckResourceAttrPair(resourceName, "identity", "aws_ses_domain_identity.test", names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "orchestration_sending_role_arn", ""),
),
},
{
Expand Down Expand Up @@ -124,6 +125,37 @@ func TestAccPinpointEmailChannel_noRole(t *testing.T) {
})
}

func TestAccPinpointEmailChannel_orchestrationSendingRoleARN(t *testing.T) {
ctx := acctest.Context(t)
var channel awstypes.EmailChannelResponse
resourceName := "aws_pinpoint_email_channel.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

domain := acctest.RandomDomainName()
address := acctest.RandomEmailAddress(domain)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckApp(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.PinpointServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckEmailChannelDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEmailChannelConfig_orchestrationSendingRoleARN(domain, address, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckEmailChannelExists(ctx, resourceName, &channel),
resource.TestCheckResourceAttrPair(resourceName, "orchestration_sending_role_arn", "aws_iam_role.test", names.AttrARN),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccPinpointEmailChannel_disappears(t *testing.T) {
ctx := acctest.Context(t)
var channel awstypes.EmailChannelResponse
Expand Down Expand Up @@ -339,3 +371,66 @@ resource "aws_ses_domain_identity" "test" {
}
`, domain, fromAddress, rName)
}

func testAccEmailChannelConfig_orchestrationSendingRoleARN(domain, fromAddress, rName string) string {
return fmt.Sprintf(`
resource "aws_pinpoint_app" "test" {}
resource "aws_ses_configuration_set" "test" {
name = %[3]q
}
resource "aws_pinpoint_email_channel" "test" {
application_id = aws_pinpoint_app.test.application_id
enabled = "false"
from_address = %[2]q
identity = aws_ses_domain_identity.test.arn
configuration_set = aws_ses_configuration_set.test.arn
orchestration_sending_role_arn = aws_iam_role.test.arn
}
resource "aws_ses_domain_identity" "test" {
domain = %[1]q
}
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": [
"ses:SendEmail",
"ses:SendRawEmail"
],
"Effect": "Allow",
"Resource": [
"${aws_ses_configuration_set.test.arn}",
"${aws_ses_domain_identity.test.arn}"
]
}
}
EOF
}
`, domain, fromAddress, rName)
}
1 change: 1 addition & 0 deletions website/docs/r/pinpoint_email_channel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ This resource supports the following arguments:
* `configuration_set` - (Optional) The ARN of the Amazon SES configuration set that you want to apply to messages that you send through the channel.
* `from_address` - (Required) The email address used to send emails from. You can use email only (`[email protected]`) or friendly address (`User <[email protected]>`). This field comply with [RFC 5322](https://www.ietf.org/rfc/rfc5322.txt).
* `identity` - (Required) The ARN of an identity verified with SES.
* `orchestration_sending_role_arn` - (Optional) The ARN of an IAM role for Amazon Pinpoint to use to send email from your campaigns or journeys through Amazon SES.
* `role_arn` - (Optional) *Deprecated* The ARN of an IAM Role used to submit events to Mobile Analytics' event ingestion service.

## Attribute Reference
Expand Down

0 comments on commit f9f9043

Please sign in to comment.