Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_ssm_parameter: Fix import by ARN #39067

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/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
34 changes: 34 additions & 0 deletions internal/service/ssm/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,40 @@
})
}

func TestAccSSMParameter_importByARN(t *testing.T) {

Check failure on line 1056 in internal/service/ssm/parameter_test.go

View workflow job for this annotation

GitHub Actions / providerlint

AT002: acceptance test function name should not include import
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
Loading