Skip to content

Commit

Permalink
Merge pull request #39067 from hashicorp/issue-39050
Browse files Browse the repository at this point in the history
r/aws_ssm_parameter: Fix import by ARN
  • Loading branch information
ewbankkit authored Aug 28, 2024
2 parents 6f6d44c + 62a4543 commit d17b01a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/39067.txt
Original file line number Diff line number Diff line change
@@ -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
```
3 changes: 2 additions & 1 deletion internal/service/ssm/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 35 additions & 0 deletions internal/service/ssm/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &param),
),
},
// 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 {
Expand Down

0 comments on commit d17b01a

Please sign in to comment.