Terraform: Attaching an unmanaged IAM role

Question:

Terraform version: 12

We have a legacy, unmanaged by Terraform IAM role that I’d like to reference from an aws_iam_policy_attachment block and I attempted the following:

Dry-run works fine but when applying TF says:

– ValidationError: The specified value for roleName is invalid. It must contain only alphanumeric characters and/or the following: +=,.@_-

Is there a way I can just reference the unmanaged role without defining it in TF? Or is there some non-destructive way of declaring it that doesn’t change anything to do with the unmanaged role?

Answer:

In your roles, you are providing role ARN, not role name.

Therefore, instead of ARN, you should use its name:


You can also use data_source

and the reference it in your resource:

Leave a Reply