HiveBrain v1.2.0
Get Started
← Back to all entries
snippetterraformMinor

How to set an existing IAM role to a new instance while spinning in terraform?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
iamwhilenewspinningroleinstancehowexistingsetterraform

Problem

I am trying to attach an existing role created in AWS, but I am not able to add it in Terraform Code. I tried to add the role in instance profile but it didn't work either for me.

Is there any direct way to add it in the resource in Terraform Code ?

iam_instance_profile = "my-role"


Note: my-role is having the full access of ec2.

Solution

you can add role like below

role = "${aws_iam_role.ec2_role_name.name}"


Please check - https://www.terraform.io/docs/providers/aws/r/iam_instance_profile.html

Code Snippets

role = "${aws_iam_role.ec2_role_name.name}"

Context

StackExchange DevOps Q#4034, answer score: 1

Revisions (0)

No revisions yet.