|
| 1 | +locals { |
| 2 | + codestar_enabled = module.this.enabled && var.codestar_connection_arn != "" && var.codestar_connection_arn != null |
| 3 | +} |
| 4 | + |
1 | 5 | module "codepipeline_label" { |
2 | 6 | source = "cloudposse/label/null" |
3 | 7 | version = "0.25.0" |
@@ -157,28 +161,28 @@ data "aws_iam_policy_document" "codebuild" { |
157 | 161 |
|
158 | 162 | # https://docs.aws.amazon.com/codepipeline/latest/userguide/connections-permissions.html |
159 | 163 | resource "aws_iam_role_policy_attachment" "codestar" { |
160 | | - count = module.this.enabled && var.codestar_connection_arn != "" ? 1 : 0 |
| 164 | + count = local.codestar_enabled ? 1 : 0 |
161 | 165 | role = join("", aws_iam_role.default.*.id) |
162 | 166 | policy_arn = join("", aws_iam_policy.codestar.*.arn) |
163 | 167 | } |
164 | 168 |
|
165 | 169 | module "codestar_label" { |
166 | 170 | source = "cloudposse/label/null" |
167 | 171 | version = "0.25.0" |
168 | | - enabled = module.this.enabled && var.codestar_connection_arn != "" |
| 172 | + enabled = local.codestar_enabled |
169 | 173 | attributes = ["codestar"] |
170 | 174 |
|
171 | 175 | context = module.this.context |
172 | 176 | } |
173 | 177 |
|
174 | 178 | resource "aws_iam_policy" "codestar" { |
175 | | - count = module.this.enabled && var.codestar_connection_arn != "" ? 1 : 0 |
| 179 | + count = local.codestar_enabled ? 1 : 0 |
176 | 180 | name = module.codestar_label.id |
177 | 181 | policy = join("", data.aws_iam_policy_document.codestar.*.json) |
178 | 182 | } |
179 | 183 |
|
180 | 184 | data "aws_iam_policy_document" "codestar" { |
181 | | - count = module.this.enabled && var.codestar_connection_arn != "" ? 1 : 0 |
| 185 | + count = local.codestar_enabled ? 1 : 0 |
182 | 186 | statement { |
183 | 187 | sid = "" |
184 | 188 |
|
@@ -240,6 +244,12 @@ resource "aws_iam_role_policy_attachment" "codebuild_s3" { |
240 | 244 | policy_arn = join("", aws_iam_policy.s3.*.arn) |
241 | 245 | } |
242 | 246 |
|
| 247 | +resource "aws_iam_role_policy_attachment" "codebuild_codestar" { |
| 248 | + count = local.codestar_enabled && var.codestar_output_artifact_format == "CODEBUILD_CLONE_REF" ? 1 : 0 |
| 249 | + role = module.codebuild.role_id |
| 250 | + policy_arn = join("", aws_iam_policy.codestar.*.arn) |
| 251 | +} |
| 252 | + |
243 | 253 | resource "aws_codepipeline" "default" { |
244 | 254 | count = module.this.enabled && var.github_oauth_token != "" ? 1 : 0 |
245 | 255 | name = module.codepipeline_label.id |
@@ -323,7 +333,7 @@ resource "aws_codepipeline" "default" { |
323 | 333 |
|
324 | 334 | # https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodestarConnectionSource.html#action-reference-CodestarConnectionSource-example |
325 | 335 | resource "aws_codepipeline" "bitbucket" { |
326 | | - count = module.this.enabled && var.codestar_connection_arn != "" ? 1 : 0 |
| 336 | + count = local.codestar_enabled ? 1 : 0 |
327 | 337 | name = module.codepipeline_label.id |
328 | 338 | role_arn = join("", aws_iam_role.default.*.arn) |
329 | 339 |
|
@@ -355,7 +365,7 @@ resource "aws_codepipeline" "bitbucket" { |
355 | 365 | ConnectionArn = var.codestar_connection_arn |
356 | 366 | FullRepositoryId = format("%s/%s", var.repo_owner, var.repo_name) |
357 | 367 | BranchName = var.branch |
358 | | - OutputArtifactFormat = "CODE_ZIP" |
| 368 | + OutputArtifactFormat = var.codestar_output_artifact_format |
359 | 369 | } |
360 | 370 | } |
361 | 371 | } |
|
0 commit comments