-
Notifications
You must be signed in to change notification settings - Fork 5
56 lines (47 loc) · 1.65 KB
/
terraform.yml
File metadata and controls
56 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: Terraform Apply
on:
workflow_dispatch:
jobs:
terraform-apply:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.7.6
- name: Terraform Init
working-directory: ./infra/terraform #워크플로우 파일 위치 폴더 기준 x, 체크아웃된 저장소 루트 기준
run: terraform init
- name: Set Environment based on Branch
run: |
BRANCH=${{ github.ref_name }}
if [ "$BRANCH" = "develop" ] ; then
ENV="test"
elif [ "$BRANCH" = "main" ] ; then
ENV="prod"
else
echo "Unsupported branch: $BRANCH"
exit 1
fi
echo "Environment: $ENV"
if [ "$ENV" = "prod" ] ; then
echo "${{secrets.TFVARS_PROD}}" > ./infra/terraform/env/terraform.tfvars
else
echo "${{secrets.TFVARS_TEST}}" > ./infra/terraform/env/terraform.tfvars
fi
- name: Select or Create Workspace
working-directory: ./infra/terraform
run: |
if terraform workspace list | grep -q "$ENV"; then
terraform workspace select "$ENV"
else
terraform workspace new "$ENV"
fi
- name: Terraform Apply
working-directory: ./infra/terraform/env
run: terraform apply -auto-approve -var-file="terraform.tfvars"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}