diff --git a/.changelog/44537.txt b/.changelog/44537.txt new file mode 100644 index 000000000000..1ed981af5c9e --- /dev/null +++ b/.changelog/44537.txt @@ -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 +``` diff --git a/internal/service/pinpointsmsvoicev2/phone_number.go b/internal/service/pinpointsmsvoicev2/phone_number.go index 51eb16bff18b..21d0a9c51919 100644 --- a/internal/service/pinpointsmsvoicev2/phone_number.go +++ b/internal/service/pinpointsmsvoicev2/phone_number.go @@ -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(), @@ -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{} diff --git a/internal/service/pinpointsmsvoicev2/phone_number_test.go b/internal/service/pinpointsmsvoicev2/phone_number_test.go index 13f67610d794..1ce073675553 100644 --- a/internal/service/pinpointsmsvoicev2/phone_number_test.go +++ b/internal/service/pinpointsmsvoicev2/phone_number_test.go @@ -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 @@ -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"] +} +`