renodesper
renodesper

Reputation: 25

Terraform Codepipeline Deploy in Different Region

I'm trying to deploy my service in the region that is just newly available (Jakarta). But it looks like the Codepipeline is not available so I have to create the Codepipeline in the nearest region (Singapore) and deploy it to Jakarta region. It is also my first time setting up Codepipeline in Terraform, so I'm not sure if I do it right or not.

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
  }
}

Above is the Terraform configuration that I created, but it gives me an error like this:

│ Error: region cannot be set for a single-region CodePipeline

If I try to remove the region on the root block, the Terraform will try to access the default region which is Jakarta region (and it will fail since Codepipeline is not available in 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

Upvotes: 1

Views: 986

Answers (2)

MarieswaranK
MarieswaranK

Reputation: 1

You get this error. Error: region cannot be set for a single-region CodePipeline

This error state you could not provide region if you are going to create single region pipeline. So please remove region from artifact_store argument in the code pipeline resource block. This will clear your issue.

Upvotes: 0

Marcin
Marcin

Reputation: 238111

You need to setup alias provider with different region. For exmaple:

provider "aws" {  
    alias  = "singapore"  
    region = "ap-southeast-1"
}

Then you deploy your pipeline to that region using the alias:

resource "aws_codepipeline" "pipeline" {
 
  provider = aws.singapore

  name     = local.service_name
  role_arn = var.codepipeline_role_arn

  # ...
}

Upvotes: 1

Related Questions