Hello everyone,
I'm writing codepipeline module and I'm trying to figure it out the best way on how to write stages in a module, so they can be expanded as needed.
As of now I have:
# This supports only 1 environment and in the near future I would like to add a lot more stages to codepipeline.
resource "aws_codepipeline" "pipeline" {
name = "${var.pipeline_name}"
role_arn = "${aws_iam_role.pipelineRole.arn}"
artifact_store {
location = "${aws_s3_bucket.pipeline_s3_bucket.bucket}"
type = "S3"
}
stage {
name = "Source"
action {
name = "DetectCodeChanges"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
output_artifacts = ["MyApp"]
configuration {
RepositoryName = "${var.codeCommit_repository}"
BranchName = "${var.codeCommit_branch}"
}
}
}
stage {
name = "PushToDEV"
action {
name = "Deploy"
category = "Deploy"
owner = "AWS"
provider = "CodeDeploy"
input_artifacts = ["MyApp"]
version = "1"
configuration {
ApplicationName = "${aws_codedeploy_app.codedeploy_configurations_app.name}"
DeploymentGroupName = "${aws_codedeploy_deployment_group.DeploymentToNewEC2underASG.deployment_group_name}"
}
}
}
}
and I'm thinking of somehow do something like this:
module "codepipeline" {
source "..."
....
stage-1_name = "Source"
stage-1_action_name = "DetectCodeChanges"
stage-1_category = "Source"
stage-1_owner = "AWS"
stage-1_provider = "CodeCommit"
stage-1_version = "1"
stage-1_artifact = "MyApp"
stage-1_repo_name = "bla_repo"
stage-1_branch_name = "bla_branch"
stage-2_name = "PushToDEV"
stage-2_action_name = "Deploy"
stage-2_category = "Deploy"
stage-2_owner = "AWS"
stage-2_provider = "CodeDeploy"
stage-2_artifact = "MyApp"
stage-2_version = "1"
stage-2_app_name = "bla_app"
stage-2_d_group = "bla_d_group"
}
but that means I'm limited to only what's hardcoded in the module.
My questions are:
- Is it possible to write codepipeline module using 'count' to have how many stages we want?
- Have anyone tried this before and wrote codepipeline module using different logic to support multiple stages?
Any ideas/suggestions are really appreciated.
Thank you,
Ernest