Skip to content
Open
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/44537.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_pinpointsmsvoicev2_phone_number: Fix `number_type` to support SHORT_CODE and prevent creation attempts with clear error message
```
11 changes: 10 additions & 1 deletion internal/service/pinpointsmsvoicev2/phone_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *phoneNumberResource) Schema(ctx context.Context, request resource.Schem
},
},
"number_type": schema.StringAttribute{
CustomType: fwtypes.StringEnumType[awstypes.RequestableNumberType](),
CustomType: fwtypes.StringEnumType[awstypes.NumberType](),
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
Expand Down Expand Up @@ -177,6 +177,15 @@ func (r *phoneNumberResource) Create(ctx context.Context, request resource.Creat
return
}

if data.NumberType.ValueString() == string(awstypes.NumberTypeShortCode) {
response.Diagnostics.AddError(
"Invalid Number Type",
"SHORT_CODE cannot be created via Terraform. Short codes must be provisioned through AWS Support. "+
"After provisioning, you can import the resource using 'terraform import'.",
)
return
}

conn := r.Meta().PinpointSMSVoiceV2Client(ctx)

input := &pinpointsmsvoicev2.RequestPhoneNumberInput{}
Expand Down
30 changes: 30 additions & 0 deletions internal/service/pinpointsmsvoicev2/phone_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ func TestAccPinpointSMSVoiceV2PhoneNumber_twoWayChannelConnect(t *testing.T) {
})
}

func TestAccPinpointSMSVoiceV2PhoneNumber_shortCodeCreateValidation(t *testing.T) {
ctx := acctest.Context(t)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
testAccPreCheckPhoneNumber(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.PinpointSMSVoiceV2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckPhoneNumberDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccPhoneNumberConfig_shortCode,
ExpectError: regexache.MustCompile(`SHORT_CODE cannot be created via Terraform`),
},
},
})
}

func TestAccPinpointSMSVoiceV2PhoneNumber_disappears(t *testing.T) {
ctx := acctest.Context(t)
var phoneNumber awstypes.PhoneNumberInformation
Expand Down Expand Up @@ -571,3 +591,13 @@ resource "aws_pinpointsmsvoicev2_phone_number" "test" {
}
`, tagKey1, tagValue1, tagKey2, tagValue2)
}

const testAccPhoneNumberConfig_shortCode = `
resource "aws_pinpointsmsvoicev2_phone_number" "test" {
iso_country_code = "US"
message_type = "TRANSACTIONAL"
number_type = "SHORT_CODE"

number_capabilities = ["SMS"]
}
`
Loading