Skip to content

Commit 6fae202

Browse files
arsdehnelstack72
authored andcommitted
Adding details around using a data source (hashicorp#11494)
landed on hashicorp#5541 and wanted to take a shot at adding the appropriate details to the iam role page.
1 parent 79024db commit 6fae202

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

website/source/docs/providers/aws/r/iam_role.html.markdown

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ The following arguments are supported:
4040
* `name` - (Optional, Forces new resource) The name of the role.
4141
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`.
4242
* `assume_role_policy` - (Required) The policy that grants an entity permission to assume the role.
43+
44+
~> **NOTE:** This `assume_role_policy` is very similar but slightly different than just a standard IAM policy and cannot use an `aws_iam_policy` resource. If _can_ however, use an `aws_iam_policy_document` [data source](https://www.terraform.io/docs/providers/aws/d/iam_policy_document.html), see example below for how this could work.
45+
4346
* `path` - (Optional) The path to the role.
4447
See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
4548

@@ -51,10 +54,31 @@ The following attributes are exported:
5154
* `create_date` - The creation date of the IAM role.
5255
* `unique_id` - The stable and unique string identifying the role.
5356

57+
## Example of Using Data Source for Assume Role Policy
58+
59+
```
60+
data "aws_iam_policy_document" "instance-assume-role-policy" {
61+
statement {
62+
actions = [ "sts:AssumeRole" ]
63+
64+
principals {
65+
type = "Service"
66+
identifiers = ["ec2.amazonaws.com"]
67+
}
68+
}
69+
}
70+
71+
resource "aws_iam_role" "instance" {
72+
name = "instance_role"
73+
path = "/system/"
74+
assume_role_policy = "${data.aws_iam_policy_document.instance-assume-role-policy.json}"
75+
}
76+
```
77+
5478
## Import
5579

5680
IAM Roles can be imported using the `name`, e.g.
5781

5882
```
5983
$ terraform import aws_iam_role.developer developer_name
60-
```
84+
```

0 commit comments

Comments
 (0)