diff --git a/.changelog/39067.txt b/.changelog/39067.txt new file mode 100644 index 00000000000..be2d8804fd3 --- /dev/null +++ b/.changelog/39067.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ssm_parameter: Fix `ValidationException: Parameter ARN is not supported for this operation` errors when deleting resources imported by ARN +``` \ No newline at end of file diff --git a/internal/service/ssm/parameter.go b/internal/service/ssm/parameter.go index 082353da5e2..a5fe04fa270 100644 --- a/internal/service/ssm/parameter.go +++ b/internal/service/ssm/parameter.go @@ -337,7 +337,8 @@ func resourceParameterDelete(ctx context.Context, d *schema.ResourceData, meta i log.Printf("[DEBUG] Deleting SSM Parameter: %s", d.Id()) _, err := conn.DeleteParameter(ctx, &ssm.DeleteParameterInput{ - Name: aws.String(d.Id()), + // Use "name" instead of "id" in case the resource was imported by ARN. + Name: aws.String(d.Get(names.AttrName).(string)), }) if errs.IsA[*awstypes.ParameterNotFound](err) { diff --git a/internal/service/ssm/parameter_test.go b/internal/service/ssm/parameter_test.go index ee8616e558d..57a8117cf3d 100644 --- a/internal/service/ssm/parameter_test.go +++ b/internal/service/ssm/parameter_test.go @@ -1053,6 +1053,41 @@ func TestAccSSMParameter_Secure_keyUpdate(t *testing.T) { }) } +// lintignore:AT002 +func TestAccSSMParameter_importByARN(t *testing.T) { + ctx := acctest.Context(t) + var param awstypes.Parameter + name := fmt.Sprintf("%s_%s", t.Name(), sdkacctest.RandString(10)) + resourceName := "aws_ssm_parameter.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.SSMServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckParameterDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccParameterConfig_basic(name, "String", "test2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckParameterExists(ctx, resourceName, ¶m), + ), + }, + // Test import by ARN. + // https://github.com/hashicorp/terraform-provider-aws/issues/39050. + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: func(*terraform.State) (string, error) { + return aws.ToString(param.ARN), nil + }, + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: names.AttrName, + ImportStateVerifyIgnore: []string{names.AttrID, "overwrite"}, + }, + }, + }) +} + func testAccCheckParameterRecreated(t *testing.T, before, after *awstypes.Parameter) resource.TestCheckFunc { return func(s *terraform.State) error { if *before.Name == *after.Name {