【问题标题】:Terraform Codepipeline Deploy in Different RegionTerraform Codepipeline 在不同区域部署
【发布时间】:2022-01-26 04:37:03
【问题描述】:

我正在尝试在新近可用的区域(雅加达)部署我的服务。但看起来 Codepipeline 不可用,所以我必须在最近的区域(新加坡)创建 Codepipeline 并将其部署到雅加达地区。这也是我第一次在 Terraform 中设置 Codepipeline,所以我不确定我是否做对了。

附:所有这些基础设施的默认区域都在“雅加达”区域。我将排除部署部分,因为没有它就会出现问题。

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

【问题讨论】:

    标签: amazon-web-services terraform aws-codepipeline


    【解决方案1】:

    您需要设置不同区域的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
    
      # ...
    }
    

    【讨论】:

    • 我尝试添加一个别名,但看起来 Terraform 认为即使从未创建过 Codepipeline,原始提供者仍有一个挥之不去的配置。你有什么问题吗?
    • 这是错误:To work with module.xxx.aws_codepipeline.pipeline its original provider configuration at module.xxx.provider["registry.terraform.io/hashicorp/aws"].sg is required, but it has been removed. This occurs when a provider configuration is removed while objects created by that provider still exist in the state. Re-add the provider configuration to destroy module.xxx.aws_codepipeline.pipeline, after which you can remove the provider configuration again.
    • @renodesper 你必须先清理旧资源。
    • 没错,销毁旧资源并再次应用它们是可行的。谢谢
    猜你喜欢
    • 2019-08-05
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2018-10-04
    • 2021-10-25
    • 2021-12-21
    • 1970-01-01
    • 2020-11-24
    相关资源
    最近更新 更多