Created
May 26, 2020 16:00
-
-
Save KerberosMorphy/189990985cdc9d6e304a44fcd17813bf to your computer and use it in GitHub Desktop.
Terraform CodePipeline Dynamic Stages and Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
${jsonencode([ | |
{ | |
"name": "Build", | |
"category": "Build", | |
"owner": "AWS", | |
"provider": "CodeBuild", | |
"input_artifacts": ["SourceArtifact"], | |
"output_artifacts": ["BuildArtifact"], | |
"version": "1", | |
"configuration": { | |
"keys": ["ProjectName"], | |
"values": ["${client}-${stage}-build"] | |
} | |
} | |
])} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
build_actions = fileexists("./build_actions.tmpl") ? jsondecode(templatefile("./build_actions.tmpl", { client = var.client, stage = var.stage })) : null | |
} | |
resource "aws_codepipeline" "codepipeline" { | |
name = "${var.client}-${var.stage}-codepipeline" | |
role_arn = aws_iam_role.codepipeline_role.arn | |
dynamic "stage" { | |
for_each = fileexists("./build_actions.json") ? [""] : [] | |
content { | |
name = "Build" | |
dynamic "action" { | |
for_each = local.build_actions | |
content { | |
name = action.value.name | |
category = action.value.category | |
owner = action.value.owner | |
provider = action.value.provider | |
input_artifacts = contains(keys(action.value), "input_artifacts") ? action.value.input_artifacts : null | |
output_artifacts = contains(keys(action.value), "output_artifacts") ? action.value.output_artifacts : null | |
version = action.value.version | |
configuration = zipmap( | |
action.value.configuration.keys, | |
action.value.configuration.values | |
) | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "stage" { | |
description = "Environment Stage Name i.e.: ['dev', 'staging', 'prod']" | |
type = string | |
default = "dev" | |
} | |
variable "client" { | |
description = "Client identifier" | |
type = string | |
default = "xyz" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment