-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (65 loc) · 1.94 KB
/
infrastructure.yaml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Infrastructure CI and CD
on:
push:
branches:
- main
paths:
- .github/**
- infrastructure/**
pull_request:
paths:
- .github/**
- infrastructure/**
defaults:
run:
working-directory: ./infrastructure
env:
TF_VAR_project_name: tarhche
TF_VAR_instance_name: backend
TF_VAR_ssh_public_key: $(shell cat ssh-public-key.pub)
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Format
id: fmt
run: terraform fmt -check
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
run: terraform plan -no-color -input=false
continue-on-error: true
cd:
runs-on: ubuntu-latest
# This job will be invoked only on default branch
if: ${{ always() && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
needs:
- ci
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Apply
run: terraform apply -auto-approve -input=false
continue-on-error: true