Skip to content

Commit cb8017b

Browse files
authored
Use var.enabled for CodePipeline and GitHub webhooks (#20)
* Use `var.enabled` for webhooks * Bump `terraform-terraform-label` version
1 parent d7c00b5 commit cb8017b

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2018 Cloud Posse, LLC
189+
Copyright 2018-2019 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

main.tf

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
locals {
2+
enabled = "${var.enabled == "true" ? true : false}"
3+
}
4+
15
module "codepipeline_label" {
2-
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2"
6+
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.2.1"
37
attributes = ["${compact(concat(var.attributes, list("codepipeline")))}"]
48
delimiter = "${var.delimiter}"
59
name = "${var.name}"
@@ -9,14 +13,14 @@ module "codepipeline_label" {
913
}
1014

1115
resource "aws_s3_bucket" "default" {
12-
count = "${var.enabled == "true" ? 1 : 0}"
16+
count = "${local.enabled ? 1 : 0}"
1317
bucket = "${module.codepipeline_label.id}"
1418
acl = "private"
1519
tags = "${module.codepipeline_label.tags}"
1620
}
1721

1822
module "codepipeline_assume_label" {
19-
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2"
23+
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.2.1"
2024
attributes = ["${compact(concat(var.attributes, list("codepipeline", "assume")))}"]
2125
delimiter = "${var.delimiter}"
2226
name = "${var.name}"
@@ -26,7 +30,7 @@ module "codepipeline_assume_label" {
2630
}
2731

2832
resource "aws_iam_role" "default" {
29-
count = "${var.enabled == "true" ? 1 : 0}"
33+
count = "${local.enabled ? 1 : 0}"
3034
name = "${module.codepipeline_assume_label.id}"
3135
assume_role_policy = "${data.aws_iam_policy_document.assume.json}"
3236
}
@@ -49,13 +53,13 @@ data "aws_iam_policy_document" "assume" {
4953
}
5054

5155
resource "aws_iam_role_policy_attachment" "default" {
52-
count = "${var.enabled == "true" ? 1 : 0}"
56+
count = "${local.enabled ? 1 : 0}"
5357
role = "${aws_iam_role.default.id}"
5458
policy_arn = "${aws_iam_policy.default.arn}"
5559
}
5660

5761
resource "aws_iam_policy" "default" {
58-
count = "${var.enabled == "true" ? 1 : 0}"
62+
count = "${local.enabled ? 1 : 0}"
5963
name = "${module.codepipeline_label.id}"
6064
policy = "${data.aws_iam_policy_document.default.json}"
6165
}
@@ -84,13 +88,13 @@ data "aws_iam_policy_document" "default" {
8488
}
8589

8690
resource "aws_iam_role_policy_attachment" "s3" {
87-
count = "${var.enabled == "true" ? 1 : 0}"
91+
count = "${local.enabled ? 1 : 0}"
8892
role = "${aws_iam_role.default.id}"
8993
policy_arn = "${aws_iam_policy.s3.arn}"
9094
}
9195

9296
module "codepipeline_s3_policy_label" {
93-
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2"
97+
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.2.1"
9498
attributes = ["${compact(concat(var.attributes, list("codepipeline", "s3")))}"]
9599
delimiter = "${var.delimiter}"
96100
name = "${var.name}"
@@ -100,13 +104,13 @@ module "codepipeline_s3_policy_label" {
100104
}
101105

102106
resource "aws_iam_policy" "s3" {
103-
count = "${var.enabled == "true" ? 1 : 0}"
107+
count = "${local.enabled ? 1 : 0}"
104108
name = "${module.codepipeline_s3_policy_label.id}"
105109
policy = "${data.aws_iam_policy_document.s3.json}"
106110
}
107111

108112
data "aws_iam_policy_document" "s3" {
109-
count = "${var.enabled == "true" ? 1 : 0}"
113+
count = "${local.enabled ? 1 : 0}"
110114

111115
statement {
112116
sid = ""
@@ -128,13 +132,13 @@ data "aws_iam_policy_document" "s3" {
128132
}
129133

130134
resource "aws_iam_role_policy_attachment" "codebuild" {
131-
count = "${var.enabled == "true" ? 1 : 0}"
135+
count = "${local.enabled ? 1 : 0}"
132136
role = "${aws_iam_role.default.id}"
133137
policy_arn = "${aws_iam_policy.codebuild.arn}"
134138
}
135139

136140
module "codebuild_label" {
137-
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.1.2"
141+
source = "github.com/cloudposse/terraform-terraform-label.git?ref=0.2.1"
138142
attributes = ["${compact(concat(var.attributes, list("codebuild")))}"]
139143
delimiter = "${var.delimiter}"
140144
name = "${var.name}"
@@ -144,7 +148,7 @@ module "codebuild_label" {
144148
}
145149

146150
resource "aws_iam_policy" "codebuild" {
147-
count = "${var.enabled == "true" ? 1 : 0}"
151+
count = "${local.enabled ? 1 : 0}"
148152
name = "${module.codebuild_label.id}"
149153
policy = "${data.aws_iam_policy_document.codebuild.json}"
150154
}
@@ -190,13 +194,13 @@ module "build" {
190194
}
191195

192196
resource "aws_iam_role_policy_attachment" "codebuild_s3" {
193-
count = "${var.enabled == "true" ? 1 : 0}"
197+
count = "${local.enabled ? 1 : 0}"
194198
role = "${module.build.role_arn}"
195199
policy_arn = "${aws_iam_policy.s3.arn}"
196200
}
197201

198202
resource "aws_codepipeline" "source_build_deploy" {
199-
count = "${var.enabled == "true" ? 1 : 0}"
203+
count = "${local.enabled ? 1 : 0}"
200204
name = "${module.codepipeline_label.id}"
201205
role_arn = "${aws_iam_role.default.arn}"
202206

@@ -265,7 +269,7 @@ resource "aws_codepipeline" "source_build_deploy" {
265269
}
266270

267271
resource "random_string" "webhook_secret" {
268-
count = "${var.webhook_enabled == "true" ? 1 : 0}"
272+
count = "${local.enabled && var.webhook_enabled == "true" ? 1 : 0}"
269273
length = 32
270274

271275
# Special characters are not allowed in webhook secret (AWS silently ignores webhook callbacks)
@@ -278,7 +282,7 @@ locals {
278282
}
279283

280284
resource "aws_codepipeline_webhook" "webhook" {
281-
count = "${var.webhook_enabled == "true" ? 1 : 0}"
285+
count = "${local.enabled && var.webhook_enabled == "true" ? 1 : 0}"
282286
name = "${module.codepipeline_label.id}"
283287
authentication = "${var.webhook_authentication}"
284288
target_action = "${var.webhook_target_action}"
@@ -296,7 +300,7 @@ resource "aws_codepipeline_webhook" "webhook" {
296300

297301
module "github_webhooks" {
298302
source = "git::https://github.com/cloudposse/terraform-github-repository-webhooks.git?ref=tags/0.1.1"
299-
enabled = "${var.webhook_enabled}"
303+
enabled = "${local.enabled && var.webhook_enabled == "true" ? "true" : "false"}"
300304
github_organization = "${var.repo_owner}"
301305
github_repositories = ["${var.repo_name}"]
302306
github_token = "${var.github_oauth_token}"

0 commit comments

Comments
 (0)