diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index f4be501..84d8dcd 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -1,45 +1,52 @@ -name: Terraform CI/CD - -on: - # pull_request: - # branches: - # - main - 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 Init - run: terraform init - - - name: Terraform Validate - run: terraform validate - - - name: Terraform Plan - # if: github.event_name == 'push' - run: terraform plan -no-color - - - name: Terraform Apply - if: github.event_name == 'push' && github.ref == 'refs/heads/infra' - run: terraform apply -auto-approve +# - name: Terraform Format Check +# run: terraform fmt + +# - name: Terraform Init +# run: terraform init + +# - 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: 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 diff --git a/main.tf b/main.tf index 5f88de7..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-infra" + 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" {