File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -135,26 +135,32 @@ resource "aws_iam_role_policy" "ecr_required" {
135
135
}
136
136
137
137
data "aws_iam_policy_document" "assume_role" {
138
- count = local. create_iam_role ? 1 : 0
139
138
statement {
140
139
effect = " Allow"
141
-
142
140
principals {
143
141
type = " Service"
144
142
identifiers = [" codebuild.amazonaws.com" ]
145
143
}
146
-
147
144
actions = [" sts:AssumeRole" ]
145
+ condition {
146
+ test = " StringEquals"
147
+ variable = " aws:SourceAccount"
148
+ values = [data . aws_caller_identity . current . account_id ]
149
+ }
148
150
}
149
151
}
150
152
153
+ locals {
154
+ assume_role_policy = var. iam_role_assume_role_policy == null ? data. aws_iam_policy_document . assume_role . json : var. iam_role_assume_role_policy
155
+ }
156
+
151
157
# ###############################################################################
152
158
# Create role
153
159
# ###############################################################################
154
160
resource "aws_iam_role" "this" {
155
161
count = local. create_iam_role ? 1 : 0
156
162
name = var. name
157
- assume_role_policy = data . aws_iam_policy_document . assume_role [ 0 ] . json
163
+ assume_role_policy = local . assume_role_policy
158
164
permissions_boundary = var. iam_role_permissions_boundary == null ? null : var. iam_role_permissions_boundary
159
165
}
160
166
Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ variable "iam_role_name" {
120
120
default = null
121
121
}
122
122
123
+ variable "iam_role_assume_role_policy" {
124
+ description = " The IAM role assume role policy document to use. If not specified then a default is used."
125
+ type = string
126
+ default = null
127
+ }
128
+
123
129
variable "iam_role_policies" {
124
130
description = " Map of IAM role policy ARNs to attach to the IAM role"
125
131
type = map (string )
You can’t perform that action at this time.
0 commit comments