TerraformからAWS CodePipelineでECSへDockerイメージをデプロイする。
variable "github_token" {}
resource "aws_codepipeline" "example" {
name = "example"
role_arn = module.codepipeline_role.iam_role_arn
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "ThirdParty"
provider = "GitHub"
version = 1
output_artifacts = ["Source"]
configuration = {
Owner = "your-github-name"
Repo = "your-repository"
Branch = "master"
PollForSourceChanges = false
OAuthToken = var.github_token
}
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = 1
input_artifacts = ["Source"]
output_artifacts = ["Build"]
configuration = {
ProjectName = aws_codebuild_project.example.id
}
}
}
stage {
name = "Deploy"
action {
name = "Deploy"
category = "Deploy"
owner = "AWS"
provider = "ECS"
version = 1
input_artifacts = ["Build"]
configuration = {
ClusterName = aws_ecs_cluster.example.name
ServiceName = aws_ecs_service.example.name
FileName = "imagedefinitions.json"
}
}
}
artifact_store {
location = aws_s3_bucket.artifact.id
type = "S3"
}
}