Skip to content

Commit a367792

Browse files
AirhisAirhis
Airhis
authored and
Airhis
committed
changed the pipeline stage dynamic code block in the main.tf file
1 parent af05c9b commit a367792

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

examples/complete/test.tfvars

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
name = "tf-aws-module_primitive-codepipeline-test-pipeline"
2-
pipeline_type = "V2"
3-
execution_mode = "PARALLEL"
4-
artifact_bucket_name = "osahon-test-020127659860"
1+
name = "tf-aws-module_primitive-codepipeline-test-pipeline"
2+
pipeline_type = "V2"
3+
execution_mode = "PARALLEL"
4+
artifact_bucket_name = "osahon-test-020127659860"
55

66

77
stages = [
88
{
9-
stage_name = "Source",
10-
name = "Source",
11-
category = "Source",
12-
owner = "AWS",
13-
provider = "S3",
14-
version = "1",
9+
stage_name = "Source"
10+
name = "Source"
11+
category = "Source"
12+
owner = "AWS"
13+
provider = "S3"
14+
version = "1"
1515
configuration = {
16-
S3Bucket = "osahon-test-020127659860",
17-
S3ObjectKey = "trigger_pipeline.zip",
16+
S3Bucket = "osahon-test-020127659860"
17+
S3ObjectKey = "trigger_pipeline.zip"
1818
PollForSourceChanges = "false"
19-
},
20-
input_artifacts = [],
21-
output_artifacts = ["SourceArtifact"],
22-
run_order = null,
23-
region = null,
19+
}
20+
input_artifacts = []
21+
output_artifacts = ["SourceArtifact"]
22+
run_order = null
23+
region = null
2424
namespace = null
2525
},
2626
{
27-
stage_name = "Manual-Approval",
28-
name = "Manual-Approval",
29-
category = "Approval",
30-
owner = "AWS",
31-
provider = "Manual",
32-
version = "1",
33-
configuration = {},
34-
input_artifacts = [],
35-
output_artifacts = ["SourceArtifact"]
36-
run_order = null,
37-
region = null,
27+
stage_name = "Manual-Approval"
28+
name = "Manual-Approval"
29+
category = "Approval"
30+
owner = "AWS"
31+
provider = "Manual"
32+
version = "1"
33+
configuration = {}
34+
input_artifacts = []
35+
output_artifacts = []
36+
run_order = null
37+
region = null
3838
namespace = null
3939
}
4040
]

main.tf

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,35 @@ resource "aws_codepipeline" "this" {
4545
}
4646

4747
dynamic "stage" {
48-
for_each = [for s in var.stages : {
49-
stage_name = lookup(s, "stage_name", "My-Stage")
50-
name = s.name
51-
action = s.action
52-
} if(lookup(s, "enabled", true))]
48+
for_each = [for stage_val in var.stages : {
49+
stage_name = try(stage_val.stage_name, "My-Stage")
50+
name = try(stage_val.name, "Manual-Approval")
51+
category = try(stage_val.category, "Approval")
52+
owner = try(stage_val.owner, "AWS")
53+
provider = try(stage_val.provider, "Manual")
54+
version = try(stage_val.version, "1")
55+
configuration = try(stage_val.configuration, {})
56+
input_artifacts = try(stage_val.input_artifacts, [])
57+
output_artifacts = try(stage_val.output_artifacts, [])
58+
run_order = try(stage_val.run_order, null)
59+
region = try(stage_val.region, null)
60+
namespace = try(stage_val.namespace, null)
61+
}]
5362

5463
content {
5564
name = stage.value.stage_name
56-
dynamic "action" {
57-
for_each = stage.value.action
58-
content {
59-
name = lookup(action.value, "name", "Manual-Approval")
60-
owner = lookup(action.value, "owner", "AWS")
61-
version = lookup(action.value, "version", "1")
62-
category = lookup(action.value, "category", "Approval")
63-
provider = lookup(action.value, "provider", "Manual")
64-
input_artifacts = lookup(action.value, "input_artifacts", [])
65-
output_artifacts = lookup(action.value, "output_artifacts", [])
66-
configuration = lookup(action.value, "configuration", {})
67-
run_order = lookup(action.value, "run_order", null)
68-
region = lookup(action.value, "region", null)
69-
namespace = lookup(action.value, "namespace", null)
70-
}
65+
action {
66+
name = stage.value.name
67+
category = stage.value.category
68+
owner = stage.value.owner
69+
provider = stage.value.provider
70+
version = stage.value.version
71+
configuration = stage.value.configuration
72+
input_artifacts = stage.value.input_artifacts
73+
output_artifacts = stage.value.output_artifacts
74+
run_order = stage.value.run_order
75+
region = stage.value.region
76+
namespace = stage.value.namespace
7177
}
7278
}
7379
}

0 commit comments

Comments
 (0)