1
1
2
2
locals {
3
- # # The name of the iam role to create for the readonly
3
+ # # The name of the iam role to create for the readonly
4
4
readonly_role_name = format (" %s-ro" , var. name )
5
5
# # The name of the iam role to create for the readwrite
6
6
readwrite_role_name = var. name
7
- # # The name of the iam role to create for the state reader
7
+ # # The name of the iam role to create for the state reader
8
8
state_reader_role_name = format (" %s-sr" , var. name )
9
9
}
10
10
@@ -53,20 +53,22 @@ resource "aws_iam_role" "ro" {
53
53
path = var. role_path
54
54
permissions_boundary = local. permission_boundary_arn
55
55
tags = merge (var. tags , { Name = local.readonly_role_name })
56
+ }
56
57
57
- inline_policy {
58
- name = " tfstate_plan"
59
- policy = data. aws_iam_policy_document . tfstate_plan . json
60
- }
58
+ # # Create an inline policy for the read only role
59
+ resource "aws_iam_role_policy" "tfstate_plan_ro" {
60
+ name = " tfstate_plan"
61
+ role = aws_iam_role. ro . id
62
+ policy = data. aws_iam_policy_document . tfstate_plan . json
63
+ }
61
64
62
- dynamic "inline_policy" {
63
- for_each = merge (var. read_only_inline_policies , var. default_inline_policies )
65
+ # # Provision the inline policies for the read only role
66
+ resource "aws_iam_role_policy" "inline_policies_ro" {
67
+ for_each = merge (var. read_only_inline_policies , var. default_inline_policies )
64
68
65
- content {
66
- name = inline_policy. key
67
- policy = inline_policy. value
68
- }
69
- }
69
+ name = each. key
70
+ role = aws_iam_role. ro . id
71
+ policy = each. value
70
72
}
71
73
72
74
# # Attach the read only policies to the read only role
@@ -129,7 +131,7 @@ data "aws_iam_policy_document" "rw" {
129
131
}
130
132
}
131
133
132
- # # Provision the read write role
134
+ # # Provision the read write role
133
135
resource "aws_iam_role" "rw" {
134
136
assume_role_policy = data. aws_iam_policy_document . rw . json
135
137
description = var. description
@@ -139,20 +141,22 @@ resource "aws_iam_role" "rw" {
139
141
path = var. role_path
140
142
permissions_boundary = local. permission_boundary_arn
141
143
tags = merge (var. tags , { Name = local.readwrite_role_name })
144
+ }
142
145
143
- inline_policy {
144
- name = " tfstate_apply"
145
- policy = data. aws_iam_policy_document . tfstate_apply . json
146
- }
146
+ # # Provision the inline terraform policy for the rw role
147
+ resource "aws_iam_role_policy" "tfstate_apply_rw" {
148
+ name = " tfstate_apply"
149
+ role = aws_iam_role. rw . id
150
+ policy = data. aws_iam_policy_document . tfstate_apply . json
151
+ }
147
152
148
- dynamic "inline_policy" {
149
- for_each = merge (var. read_write_inline_policies , var. default_inline_policies )
153
+ # # Provision the inline policies for the read write role
154
+ resource "aws_iam_role_policy" "inline_policies_rw" {
155
+ for_each = merge (var. read_write_inline_policies , var. default_inline_policies )
150
156
151
- content {
152
- name = inline_policy. key
153
- policy = inline_policy. value
154
- }
155
- }
157
+ name = each. key
158
+ role = aws_iam_role. rw . id
159
+ policy = each. value
156
160
}
157
161
158
162
# # Attach the read write policies to the read write role
0 commit comments