Commit 70fd597
committed
r/aws_iam_user: switch tag identifier to
IAM user tag operations rely on the user name as the identifier. When the `name` argument is used as the identifier attribute, an update which changes both `name` and `tag` arguments causes transparent tagging to fail. Transparent tagging operations run _before_ the update operation, meaning the updated `name` value is passed to the [`TagUser`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_TagUser.html) API before the [`UpdateUser`](https://docs.aws.amazon.com/IAM/latest/APIReference/API_UpdateUser.html) API is called to update it.
By switching the tag identifier to `id`, we allow the `TagUser` API to reference the "old" user name, via `d.GetId()`, before the update operation executes and changes the name along with resource identifier. As `id` tracks the user name, this change does not break any existing tagging workflows, just enables the "name and tag" update case to behave as expected.
Before:
```console
% make t K=iam T=TestAccIAMUser_nameAndTags
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 b-iam_user-tag-and-name-update 🌿...
TF_ACC=1 go1.24.11 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAMUser_nameAndTags' -timeout 360m -vet=off
2025/12/15 16:39:45 Creating Terraform AWS Provider (SDKv2-style)...
2025/12/15 16:39:45 Initializing Terraform AWS Provider (SDKv2-style)...
=== CONT TestAccIAMUser_nameAndTags
user_test.go:538: Step 2/2 error: Error running apply: exit status 1
Error: updating tags for IAM (Identity & Access Management) User (tf-acc-test-1187392722609479887-updated): tagging resource (tf-acc-test-1187392722609479887-updated): operation error IAM: TagUser, https response error StatusCode: 404, RequestID: 5651011a-12db-4b23-9199-24d6672641bf, NoSuchEntity: The user with name tf-acc-test-1187392722609479887-updated cannot be found.
with aws_iam_user.user,
on terraform_plugin_test.tf line 12, in resource "aws_iam_user" "user":
12: resource "aws_iam_user" "user" {
--- FAIL: TestAccIAMUser_nameAndTags (15.18s)
FAIL
FAIL github.com/hashicorp/terraform-provider-aws/internal/service/iam 21.693s
```
After:
```console
% make t K=iam T=TestAccIAMUser_nameAndTags
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 b-iam_user-tag-and-name-update 🌿...
TF_ACC=1 go1.24.11 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAMUser_nameAndTags' -timeout 360m -vet=off
2025/12/16 10:20:19 Creating Terraform AWS Provider (SDKv2-style)...
2025/12/16 10:20:19 Initializing Terraform AWS Provider (SDKv2-style)...
--- PASS: TestAccIAMUser_nameAndTags (21.19s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/iam 27.774s
```
```console
% make t K=iam T=TestAccIAMUser_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 b-iam_user-tag-and-name-update 🌿...
TF_ACC=1 go1.24.11 test ./internal/service/iam/... -v -count 1 -parallel 20 -run='TestAccIAMUser_' -timeout 360m -vet=off
2025/12/16 10:25:18 Creating Terraform AWS Provider (SDKv2-style)...
2025/12/16 10:25:18 Initializing Terraform AWS Provider (SDKv2-style)...
--- PASS: TestAccIAMUser_ForceDestroy_policyInline (34.73s)
=== CONT TestAccIAMUser_tags_DefaultTags_updateToResourceOnly
--- PASS: TestAccIAMUser_ForceDestroy_policyAttached (36.71s)
=== CONT TestAccIAMUser_tags_DefaultTags_updateToProviderOnly
--- PASS: TestAccIAMUser_ForceDestroy_policyInlineAttached (36.82s)
=== CONT TestAccIAMUser_basic
--- PASS: TestAccIAMUser_ForceDestroy_accessKey (43.86s)
=== CONT TestAccIAMUser_disappears
--- PASS: TestAccIAMUser_ForceDestroy_signingCertificate (45.67s)
=== CONT TestAccIAMUser_tags_IgnoreTags_Overlap_ResourceTag
--- PASS: TestAccIAMUser_ForceDestroy_serviceSpecificCred (45.80s)
=== CONT TestAccIAMUser_ForceDestroy_sshKey
--- PASS: TestAccIAMUser_ForceDestroy_mfaDevice (45.97s)
=== CONT TestAccIAMUser_tags_IgnoreTags_Overlap_DefaultTag
--- PASS: TestAccIAMUser_tags_DefaultTags_nullNonOverlappingResourceTag (49.78s)
=== CONT TestAccIAMUser_tags_EmptyTag_OnUpdate_Add
--- PASS: TestAccIAMUser_tags_DefaultTags_nullOverlappingResourceTag (51.79s)
=== CONT TestAccIAMUser_tags_DefaultTags_nonOverlapping
--- PASS: TestAccIAMUser_tags_DefaultTags_emptyProviderOnlyTag (52.16s)
=== CONT TestAccIAMUser_tags_DefaultTags_providerOnly
--- PASS: TestAccIAMUser_tags_DefaultTags_emptyResourceTag (54.09s)
=== CONT TestAccIAMUser_tags_EmptyTag_OnUpdate_Replace
--- PASS: TestAccIAMUser_tags_ComputedTag_OnCreate (56.57s)
=== CONT TestAccIAMUser_tags_AddOnUpdate
--- PASS: TestAccIAMUser_pathChange (69.16s)
=== CONT TestAccIAMUser_tags_EmptyTag_OnCreate
--- PASS: TestAccIAMUser_nameChange (73.24s)
=== CONT TestAccIAMUser_ForceDestroy_loginProfile
--- PASS: TestAccIAMUser_nameAndTags (75.08s)
=== CONT TestAccIAMUser_tags_EmptyMap
--- PASS: TestAccIAMUser_disappears (37.71s)
=== CONT TestAccIAMUser_tags_null
--- PASS: TestAccIAMUser_tags_ComputedTag_OnUpdate_Replace (88.28s)
--- PASS: TestAccIAMUser_tags_ComputedTag_OnUpdate_Add (91.48s)
--- PASS: TestAccIAMUser_ForceDestroy_sshKey (46.05s)
--- PASS: TestAccIAMUser_basic (71.99s)
--- PASS: TestAccIAMUser_ForceDestroy_loginProfile (40.51s)
--- PASS: TestAccIAMUser_tags_DefaultTags_updateToResourceOnly (79.26s)
--- PASS: TestAccIAMUser_tags_DefaultTags_updateToProviderOnly (78.40s)
--- PASS: TestAccIAMUser_tags_EmptyTag_OnUpdate_Replace (72.19s)
--- PASS: TestAccIAMUser_tags_AddOnUpdate (70.56s)
--- PASS: TestAccIAMUser_tags_DefaultTags_overlapping (131.10s)
--- PASS: TestAccIAMUser_tags_EmptyMap (57.29s)
--- PASS: TestAccIAMUser_tags_IgnoreTags_Overlap_DefaultTag (88.51s)
--- PASS: TestAccIAMUser_tags_null (53.51s)
--- PASS: TestAccIAMUser_tags_EmptyTag_OnCreate (69.51s)
--- PASS: TestAccIAMUser_tags_IgnoreTags_Overlap_ResourceTag (94.78s)
--- PASS: TestAccIAMUser_tags_EmptyTag_OnUpdate_Add (93.17s)
--- PASS: TestAccIAMUser_tags (142.97s)
--- PASS: TestAccIAMUser_tags_DefaultTags_nonOverlapping (93.90s)
--- PASS: TestAccIAMUser_permissionsBoundary (147.57s)
--- PASS: TestAccIAMUser_tags_DefaultTags_providerOnly (105.94s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/iam 164.605s
```id
1 parent 2ac2917 commit 70fd597
File tree
3 files changed
+79
-2
lines changed- internal/service/iam
3 files changed
+79
-2
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
523 | 527 | | |
524 | 528 | | |
525 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
526 | 591 | | |
527 | 592 | | |
528 | 593 | | |
| |||
827 | 892 | | |
828 | 893 | | |
829 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
0 commit comments