Giter Club home page Giter Club logo

terraform-ecs-codeploy-blue-green's Introduction

Terraform ECS Fargate API with Prisma Blue-Green Deployment

Blog post

The Infrastructure as Code for ECS Fargate API with Prisma ORM, PostgreSQL, Secret Manager, CodePipeline, CodeBuild, CodeDeploy, Route53, ACM, SSM, ALB

Terraform installation

Terraform install for Apple Silicon

Reference

    1. Remove any existing Terraform binary (/usr/bin/terraform and/or /usr/local/bin/terraform)
    1. Install m1-terraform-provider-helper
    • 2.1. brew install kreuzwerker/taps/m1-terraform-provider-helper
    1. Install Terraform
    • 3.1. brew tap hashicorp/tap
    • 3.2. brew install hashicorp/tap/terraform
    1. Install the hashicorp/template version v2.2.0
    • 4.1. m1-terraform-provider-helper activate
    • 4.2. m1-terraform-provider-helper install hashicorp/template -v v2.2.0
➜  ~ terraform --version
Terraform v1.3.1
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v4.33.0
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/hashicorp/template v2.2.0

Initial setting state

  • 초기에는 default workspace 를 사용한다.
  • terraform.tfstate.terraform.lock.hcl을 Remote로 관리하기 위해 상태관리 인프라를 먼저 배포하고 Terraform을 backed 설정을 변경한다. => 아래 코드만 남기고 모두 주석 처리
locals {
  availability_zones = ["${var.region}a", "${var.region}b", "${var.region}c"]
}

provider "aws" {
  region = var.region
}

module "terraform_state" {
  source                               = "./modules/terraform-state"
  s3_terraform_state_bucket_name       = "mystack-terraform-running-state"
  s3_terraform_state_key               = "global/s3/terraform.tfstate"
  dynamodb_terraform_state_locks_table = "mystack-terraform-running-locks"
}
  • 이후 아래 Terraform backend 설정하고 terraform init으로 S3로 백엔드를 설정한다.
 terraform {
   backend "s3" {
     bucket = "mystack-terraform-running-state"
     key    = "global/s3/terraform.tfstate"
     region = "ap-northeast-2"
     dynamodb_table = "mystack-terraform-running-locks"
     encrypt        = true
   }
 }
  • 이후 terraform_state 모듈은 주석처리하고 Workspace를 생성하여 각 스테이징 환경에 따라 State를 나누는 과정을 한다. ex) dev
terraform workspace new dev
terraform apply
  • Apple Silicon Mac의 경우 Lock을 다음으로 업데이트한다. terraform providers lock -platform=linux_amd64
  • 이후 주석처리한 모든 module들을 해제하고 각 워크스페이스를 terraform workspace select 명령을 통해 체크아웃한 후 배포 한다.

CodeStar Connection

GitHub 리포 연결을 위해서는 콘솔에서 직접 연결해야 함. CodePipeline 에서 Setting

terraform apply 이후

CodePipeline > Settings > Connections

Status = Pending 인 커넥션 선택 후 Update pending connection 으로 Github 연결

Workspace Migration

https://stackoverflow.com/questions/66979732/in-terraform-is-it-possible-to-move-to-state-from-one-workspace-to-another

Terraform Workspace

Check workspace

terraform workspace list
  • dev: 개발 인프라
  • staged: E2E 테스트 인프라
  • prod: Production 인프라

Select workspace

  • dev 워크스페이스 선택
terraform workspace select ${workspace name}

terraform-ecs-codeploy-blue-green's People

Contributors

eunchurn avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.