相对简单的问题。
我不知道这是terraform可以做的事情,但是我想使用for循环在terraform资源中创建对象。您可以在下面看到我的意思的示例。我已经遍历了资源以创建管道,但是我还想遍历部署对象,因此可以将一个codeCommit存储库推送到多个ECS服务,而不必创建新的管道。这可能吗?
我想循环的部分有:
使用多个循环放置多个部署
resource "aws_codepipeline" "pipeline" {
count = "${local.numRepo}"
name = "${element(var.respository_names, count.index)}-${terraform.workspace}"
role_arn = "${var.role}"
artifact_store {
location = "${element(aws_s3_bucket.artifact.*.bucket, count.index)}"
type = "S3"
}
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeCommit"
version = "1"
output_artifacts = ["source"]
configuration {
RepositoryName = "${element(var.respository_names, count.index)}"
BranchName = "${element(split(",",lookup(var.codepipelines_info,"${terraform.workspace}.${element(var.respository_names,count.index)}")),1)}"
}
}
}
stage {
name = "Test"
action {
name = "Test"
category = "Test"
owner = "AWS"
provider = "CodeBuild"
input_artifacts = ["source"]
output_artifacts = ["tested"]
version = "1"
configuration {
ProjectName = "${element(aws_codebuild_project.openjobs_build_test.*.name, count.index)}"
}
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
input_artifacts = ["source"]
output_artifacts = ["imagedefinitions"]
configuration {
ProjectName = "${element(aws_codebuild_project.openjobs_build.*.name, count.index)}"
}
}
}
stage {
name = "Production"
action { <<<PLACE MULTIPLE DEPLOYMENTS USING SOME FOR LOOP
name = "Deploy"
category = "Deploy"
owner = "AWS"
provider = "ECS"
input_artifacts = ["imagedefinitions"]
version = "1"
configuration {
ClusterName = "${var.ecs_cluster_name}"
ServiceName = "${terraform.workspace}-${element(var.respository_names, count.index)}"
FileName = "imagedefinitions.json"
}
}
}
}