Skip to content

Commit 1fd5612

Browse files
authored
Merge pull request #44372 from tabito-hara/f-aws_pinpointsmsvoice2_phone_number-support_amazon_connect_two_way_channel
[Enhancement] aws_pinpointsmsvoice2_phone_number: Support Amazon Connect as the inbound destination for two-way SMS
2 parents 2224bf8 + 6b31c0c commit 1fd5612

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

.changelog/44372.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_pinpointsmsvoicev2_phone_number: Update `two_way_channel_arn` argument to accept `connect.[region].amazonaws.com` in addition to ARNs
3+
```

internal/service/pinpointsmsvoicev2/phone_number.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/hashicorp/terraform-provider-aws/internal/framework"
3636
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
3737
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
38+
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators"
3839
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3940
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
4041
"github.com/hashicorp/terraform-provider-aws/names"
@@ -128,12 +129,15 @@ func (r *phoneNumberResource) Schema(ctx context.Context, request resource.Schem
128129
names.AttrTags: tftags.TagsAttribute(),
129130
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
130131
"two_way_channel_arn": schema.StringAttribute{
131-
CustomType: fwtypes.ARNType,
132-
Optional: true,
132+
Optional: true,
133133
Validators: []validator.String{
134134
stringvalidator.AlsoRequires(
135135
path.MatchRelative().AtParent().AtName("two_way_channel_enabled"),
136136
),
137+
stringvalidator.Any(
138+
fwvalidators.ARN(),
139+
stringvalidator.RegexMatches(regexache.MustCompile(`^connect\.[a-z0-9-]+\.amazonaws.com$`), "Must be connect.{region}.amazonaws.com"),
140+
),
137141
},
138142
},
139143
"two_way_channel_role": schema.StringAttribute{
@@ -390,7 +394,7 @@ type phoneNumberResourceModel struct {
390394
Tags tftags.Map `tfsdk:"tags"`
391395
TagsAll tftags.Map `tfsdk:"tags_all"`
392396
Timeouts timeouts.Value `tfsdk:"timeouts"`
393-
TwoWayChannelARN fwtypes.ARN `tfsdk:"two_way_channel_arn"`
397+
TwoWayChannelARN types.String `tfsdk:"two_way_channel_arn"`
394398
TwoWayEnabled types.Bool `tfsdk:"two_way_channel_enabled"`
395399
TwoWayChannelRole fwtypes.ARN `tfsdk:"two_way_channel_role"`
396400
}

internal/service/pinpointsmsvoicev2/phone_number_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,42 @@ func TestAccPinpointSMSVoiceV2PhoneNumber_twoWayChannelRole(t *testing.T) {
176176
},
177177
})
178178
}
179+
180+
func TestAccPinpointSMSVoiceV2PhoneNumber_twoWayChannelConnect(t *testing.T) {
181+
ctx := acctest.Context(t)
182+
183+
iamRoleName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
184+
resourceName := "aws_pinpointsmsvoicev2_phone_number.test"
185+
186+
resource.ParallelTest(t, resource.TestCase{
187+
PreCheck: func() {
188+
acctest.PreCheck(ctx, t)
189+
testAccPreCheckPhoneNumber(ctx, t)
190+
},
191+
ErrorCheck: acctest.ErrorCheck(t, names.PinpointSMSVoiceV2ServiceID),
192+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
193+
CheckDestroy: testAccCheckPhoneNumberDestroy(ctx),
194+
Steps: []resource.TestStep{
195+
{
196+
Config: testAccPhoneNumberConfig_two_way_channel_connect(iamRoleName),
197+
ConfigStateChecks: []statecheck.StateCheck{
198+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("iso_country_code"), knownvalue.StringExact("US")),
199+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("message_type"), knownvalue.StringExact("TRANSACTIONAL")),
200+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("number_type"), knownvalue.StringExact("SIMULATOR")),
201+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("two_way_channel_enabled"), knownvalue.Bool(true)),
202+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("two_way_channel_arn"), knownvalue.StringRegexp(regexache.MustCompile(`^connect\.[a-z0-9-]+\.amazonaws\.com`))),
203+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("two_way_channel_role"), tfknownvalue.GlobalARNRegexp("iam", regexache.MustCompile(fmt.Sprintf(`role/%s`, iamRoleName)))),
204+
},
205+
},
206+
{
207+
ResourceName: resourceName,
208+
ImportState: true,
209+
ImportStateVerify: true,
210+
},
211+
},
212+
})
213+
}
214+
179215
func TestAccPinpointSMSVoiceV2PhoneNumber_disappears(t *testing.T) {
180216
ctx := acctest.Context(t)
181217
var phoneNumber awstypes.PhoneNumberInformation
@@ -441,6 +477,64 @@ resource "aws_pinpointsmsvoicev2_phone_number" "test" {
441477
`, snsTopicName, iamRoleName)
442478
}
443479

480+
func testAccPhoneNumberConfig_two_way_channel_connect(iamRoleName string) string {
481+
return fmt.Sprintf(`
482+
data "aws_caller_identity" "current" {}
483+
data "aws_region" "current" {}
484+
485+
resource "aws_iam_role" "test" {
486+
name = %[1]q
487+
assume_role_policy = jsonencode({
488+
Version = "2012-10-17",
489+
Statement = [
490+
{
491+
Action = "sts:AssumeRole",
492+
Effect = "Allow",
493+
Principal = {
494+
Service = "sms-voice.amazonaws.com"
495+
}
496+
Condition = {
497+
StringEquals = {
498+
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
499+
}
500+
}
501+
}
502+
]
503+
})
504+
}
505+
506+
resource "aws_iam_role_policy" "test" {
507+
name = "pinpointsmsvoicev2-sns-policy"
508+
role = aws_iam_role.test.id
509+
policy = jsonencode({
510+
Version = "2012-10-17",
511+
Statement = [
512+
{
513+
Effect = "Allow",
514+
Action = [
515+
"connect:SendChatIntegrationEvent",
516+
],
517+
Resource = ["*"]
518+
}
519+
]
520+
})
521+
}
522+
523+
resource "aws_pinpointsmsvoicev2_phone_number" "test" {
524+
iso_country_code = "US"
525+
message_type = "TRANSACTIONAL"
526+
number_type = "SIMULATOR"
527+
two_way_channel_arn = "connect.${data.aws_region.current.region}.amazonaws.com"
528+
two_way_channel_role = aws_iam_role.test.arn
529+
two_way_channel_enabled = true
530+
number_capabilities = [
531+
"SMS",
532+
"VOICE",
533+
]
534+
}
535+
`, iamRoleName)
536+
}
537+
444538
func testAccPhoneNumberConfig_tags1(tagKey1, tagValue1 string) string {
445539
return fmt.Sprintf(`
446540
resource "aws_pinpointsmsvoicev2_phone_number" "test" {

website/docs/r/pinpointsmsvoicev2_phone_number.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This resource supports the following arguments:
3737
* `opt_out_list_name` - (Optional) The name of the opt-out list to associate with the phone number.
3838
* `registration_id` - (Optional) Use this field to attach your phone number for an external registration process.
3939
* `self_managed_opt_outs_enabled` - (Optional) When set to `false` an end recipient sends a message that begins with HELP or STOP to one of your dedicated numbers, AWS End User Messaging SMS and Voice automatically replies with a customizable message and adds the end recipient to the opt-out list. When set to true you’re responsible for responding to HELP and STOP requests. You’re also responsible for tracking and honoring opt-out request.
40-
* `two_way_channel_arn` - (Optional) The Amazon Resource Name (ARN) of the two way channel.
40+
* `two_way_channel_arn` - (Optional) Configuration for two-way SMS. Specify an ARN to receive incoming SMS messages, or `connect.[region].amazonaws.com` (with `[region]` replaced by the AWS Region of the Amazon Connect instance) to set Amazon Connect as the inbound destination.
4141
* `two_way_channel_enabled` - (Optional) By default this is set to `false`. When set to `true` you can receive incoming text messages from your end recipients.
4242
* `two_way_channel_role` - (Optional) IAM Role ARN for a service to assume, to be able to post inbound SMS messages.
4343

0 commit comments

Comments
 (0)