Skip to content

Commit

Permalink
Merge pull request hashicorp#34099 from kuredev/b-fix-iam-instance-pr…
Browse files Browse the repository at this point in the history
…ofile-role-nil

 Fix aws_iam_instance_profile detects that the instance profile is not associated with IAM Role.
  • Loading branch information
YakDriver authored Mar 27, 2024
2 parents 9ec5e15 + 0df6e6c commit d3c1cd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/34099.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/instance_profile: Detect when the associated `role` no longer exists
```
5 changes: 5 additions & 0 deletions internal/service/iam/instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,14 @@ func resourceInstanceProfileRead(ctx context.Context, d *schema.ResourceData, me
d.Set("name", instanceProfile.InstanceProfileName)
d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(instanceProfile.InstanceProfileName)))
d.Set("path", instanceProfile.Path)

if d.Get("role") != "" {
d.Set("role", nil)
}
if len(instanceProfile.Roles) > 0 {
d.Set("role", instanceProfile.Roles[0].RoleName) //there will only be 1 role returned
}

d.Set("unique_id", instanceProfile.InstanceProfileId)

setTagsOut(ctx, instanceProfile.Tags)
Expand Down

0 comments on commit d3c1cd4

Please sign in to comment.