From cc4e3635da568ac55dced0aa49100e411ae5e261 Mon Sep 17 00:00:00 2001 From: sinascode Date: Wed, 25 Jun 2025 14:28:15 +0900 Subject: [PATCH 1/4] Update terraform.yaml --- .github/workflows/terraform.yaml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index f4be501..01db6ac 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -1,9 +1,9 @@ name: Terraform CI/CD on: - # pull_request: - # branches: - # - main + pull_request: + branches: + - infra push: branches: - infra @@ -37,9 +37,16 @@ jobs: run: terraform validate - name: Terraform Plan - # if: github.event_name == 'push' - run: terraform plan -no-color - + if: github.event_name == 'push' || github.event_name == 'pull_request' + run: terraform plan -no-color > plan.txt || true + + - name: Upload Terraform Plan Artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: terraform-plan + path: plan.txt + - name: Terraform Apply if: github.event_name == 'push' && github.ref == 'refs/heads/infra' run: terraform apply -auto-approve From c6c9e675b7165870a9e1635115a01fb47331891b Mon Sep 17 00:00:00 2001 From: sinascode Date: Wed, 25 Jun 2025 14:33:42 +0900 Subject: [PATCH 2/4] update aws_vpc_backend-vpc Name --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 848b443..f7882ce 100644 --- a/main.tf +++ b/main.tf @@ -2,6 +2,6 @@ resource "aws_vpc" "backend-vpc" { cidr_block = "10.0.0.0/16" tags = { - Name = "tf-backend" + Name = "tf-backend-plan" } } \ No newline at end of file From 2d4b5f70b51fd51de9850d8c26721aeb4100c851 Mon Sep 17 00:00:00 2001 From: sinascode Date: Wed, 25 Jun 2025 15:21:08 +0900 Subject: [PATCH 3/4] Update terraform.yaml --- .github/workflows/terraform.yaml | 92 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 01db6ac..84d8dcd 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -1,52 +1,52 @@ -name: Terraform CI/CD - -on: - pull_request: - branches: - - infra - push: - branches: - - infra - -jobs: - terraform: - name: Terraform Pipeline - runs-on: ubuntu-latest - - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: ap-northeast-2 - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v2 - with: - terraform_version: 1.6.6 +# name: Terraform CI/CD + +# on: +# pull_request: +# branches: +# - infra +# push: +# branches: +# - infra + +# jobs: +# terraform: +# name: Terraform Pipeline +# runs-on: ubuntu-latest + +# env: +# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} +# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# AWS_DEFAULT_REGION: ap-northeast-2 + +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 + +# - name: Setup Terraform +# uses: hashicorp/setup-terraform@v2 +# with: +# terraform_version: 1.6.6 - - name: Terraform Format Check - run: terraform fmt +# - name: Terraform Format Check +# run: terraform fmt - - name: Terraform Init - run: terraform init +# - name: Terraform Init +# run: terraform init - - name: Terraform Validate - run: terraform validate +# - name: Terraform Validate +# run: terraform validate - - name: Terraform Plan - if: github.event_name == 'push' || github.event_name == 'pull_request' - run: terraform plan -no-color > plan.txt || true +# - name: Terraform Plan +# if: github.event_name == 'push' || github.event_name == 'pull_request' +# run: terraform plan -no-color > plan.txt || true - - name: Upload Terraform Plan Artifact - if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v4 - with: - name: terraform-plan - path: plan.txt +# - name: Upload Terraform Plan Artifact +# if: github.event_name == 'pull_request' +# uses: actions/upload-artifact@v4 +# with: +# name: terraform-plan +# path: plan.txt - - name: Terraform Apply - if: github.event_name == 'push' && github.ref == 'refs/heads/infra' - run: terraform apply -auto-approve +# - name: Terraform Apply +# if: github.event_name == 'push' && github.ref == 'refs/heads/infra' +# run: terraform apply -auto-approve From e88b6517e8a8642a888fe8058e8e817db80b97b5 Mon Sep 17 00:00:00 2001 From: sinascode Date: Wed, 25 Jun 2025 15:29:21 +0900 Subject: [PATCH 4/4] update cloud configuration --- main.tf | 2 +- provider.tf | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index f7882ce..28eb20f 100644 --- a/main.tf +++ b/main.tf @@ -2,6 +2,6 @@ resource "aws_vpc" "backend-vpc" { cidr_block = "10.0.0.0/16" tags = { - Name = "tf-backend-plan" + Name = "tf-backend-cloud" } } \ No newline at end of file diff --git a/provider.tf b/provider.tf index 6651372..b423188 100644 --- a/provider.tf +++ b/provider.tf @@ -4,14 +4,27 @@ terraform { source = "hashicorp/aws" version = ">= 5.0.0" } + } + + cloud { + + organization = "devops_sn" + + workspaces { + name = "devops_sn" + } + } + + # 같은 리소스?면 output으로 참조하면됨 - backend "s3" { - bucket = "backend-bucket-ce00" - key = "terraform/state-test/terraform.tfstate" # tfstate가 이곳에 저장됨 - region = "ap-northeast-2" - dynamodb_table = "terraform-lock" #dynamodb에서 만든 테이블 이름 - } + # terraform cloud 사용 시 s3는 사용x + # backend "s3" { + # bucket = "backend-bucket-ce00" + # key = "terraform/state-test/terraform.tfstate" # tfstate가 이곳에 저장됨 + # region = "ap-northeast-2" + # dynamodb_table = "terraform-lock" #dynamodb에서 만든 테이블 이름 + # } } provider "aws" {