Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 51 additions & 44 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
25 changes: 19 additions & 6 deletions provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down