Terraform Codepipeline 在不同区域部署
Terraform Codepipeline Deploy in Different Region
我正在尝试在刚刚可用的区域(雅加达)部署我的服务。但看起来 Codepipeline 不可用,所以我必须在最近的区域(新加坡)创建 Codepipeline 并将其部署到雅加达区域。我也是第一次在 Terraform 中设置 Codepipeline,所以我不确定我是否做对了。
P.S. The default region of all these infrastructures is in "Jakarta" region. I will exclude the deploy part since the issue is showing up without it.
resource "aws_codepipeline" "pipeline" {
name = local.service_name
role_arn = var.codepipeline_role_arn
artifact_store {
type = "S3"
region = var.codepipeline_region
location = var.codepipeline_artifact_bucket_name
}
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["SourceArtifact"]
region = var.codepipeline_region
configuration = {
ConnectionArn = var.codestar_connection
FullRepositoryId = "${var.team_name}/${local.repo_name}"
BranchName = local.repo_branch
OutputArtifactFormat = "CODEBUILD_CLONE_REF" // NOTE: Full clone
}
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
input_artifacts = ["SourceArtifact"]
output_artifacts = ["BuildArtifact"]
run_order = 1
region = var.codepipeline_region
configuration = {
"ProjectName" = local.service_name
}
}
}
tags = {
Name = "${local.service_name}-pipeline"
Environment = local.env
}
}
以上是我创建的 Terraform 配置,但它给我这样的错误:
│ Error: region cannot be set for a single-region CodePipeline
如果我尝试删除根块上的区域,Terraform 将尝试访问默认区域,即 Jakarta 区域(并且它将失败,因为 Codepipeline 在 Jakarta 不可用)。
│ Error: Error creating CodePipeline: RequestError: send request failed
│ caused by: Post "https://codepipeline.ap-southeast-3.amazonaws.com/": dial tcp: lookup codepipeline.ap-southeast-3.amazonaws.com on 103.86.96.100:53: no such host
您需要设置 alias 不同区域的提供商。例如:
provider "aws" {
alias = "singapore"
region = "ap-southeast-1"
}
然后使用别名将管道部署到该区域:
resource "aws_codepipeline" "pipeline" {
provider = aws.singapore
name = local.service_name
role_arn = var.codepipeline_role_arn
# ...
}
我正在尝试在刚刚可用的区域(雅加达)部署我的服务。但看起来 Codepipeline 不可用,所以我必须在最近的区域(新加坡)创建 Codepipeline 并将其部署到雅加达区域。我也是第一次在 Terraform 中设置 Codepipeline,所以我不确定我是否做对了。
P.S. The default region of all these infrastructures is in "Jakarta" region. I will exclude the deploy part since the issue is showing up without it.
resource "aws_codepipeline" "pipeline" {
name = local.service_name
role_arn = var.codepipeline_role_arn
artifact_store {
type = "S3"
region = var.codepipeline_region
location = var.codepipeline_artifact_bucket_name
}
stage {
name = "Source"
action {
name = "Source"
category = "Source"
owner = "AWS"
provider = "CodeStarSourceConnection"
version = "1"
output_artifacts = ["SourceArtifact"]
region = var.codepipeline_region
configuration = {
ConnectionArn = var.codestar_connection
FullRepositoryId = "${var.team_name}/${local.repo_name}"
BranchName = local.repo_branch
OutputArtifactFormat = "CODEBUILD_CLONE_REF" // NOTE: Full clone
}
}
}
stage {
name = "Build"
action {
name = "Build"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
input_artifacts = ["SourceArtifact"]
output_artifacts = ["BuildArtifact"]
run_order = 1
region = var.codepipeline_region
configuration = {
"ProjectName" = local.service_name
}
}
}
tags = {
Name = "${local.service_name}-pipeline"
Environment = local.env
}
}
以上是我创建的 Terraform 配置,但它给我这样的错误:
│ Error: region cannot be set for a single-region CodePipeline
如果我尝试删除根块上的区域,Terraform 将尝试访问默认区域,即 Jakarta 区域(并且它将失败,因为 Codepipeline 在 Jakarta 不可用)。
│ Error: Error creating CodePipeline: RequestError: send request failed
│ caused by: Post "https://codepipeline.ap-southeast-3.amazonaws.com/": dial tcp: lookup codepipeline.ap-southeast-3.amazonaws.com on 103.86.96.100:53: no such host
您需要设置 alias 不同区域的提供商。例如:
provider "aws" {
alias = "singapore"
region = "ap-southeast-1"
}
然后使用别名将管道部署到该区域:
resource "aws_codepipeline" "pipeline" {
provider = aws.singapore
name = local.service_name
role_arn = var.codepipeline_role_arn
# ...
}