-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (72 loc) · 2.44 KB
/
deploy.yml
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
83
84
85
86
87
88
89
name: Deploy Static Website
on:
workflow_dispatch: {}
push:
branches:
- main
#workflow_dispatch: # Permet de déclencher manuellement pour le destroy
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }} # Exécute ce job uniquement sur les pushs, pas sur les dispatch manuels
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.8
- name: Install AWS CLI
uses: unfor19/install-aws-cli-action@v1
with:
version: 2
verbose: false
arch: amd64
- name: Terraform Init
run: terraform init
- name: Terraform Apply
run: terraform apply -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-west-2
- name: Output website URL
run: echo "Website URL is $(terraform output INFO)"
- name: Cache Terraform State # Enregistre l'état entre les jobs apply et destroy
uses: actions/cache@v4
with:
path: .terraform
key: ${{ runner.os }}-terraform-${{ github.sha }}
restore-keys: |
${{ runner.os }}-terraform-
destroy:
runs-on: ubuntu-latest
environment: Prod-manual
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.8
- name: Restore Terraform State # Restaure l'état sauvegardé
uses: actions/cache@v4
with:
path: .terraform
key: ${{ runner.os }}-terraform-${{ github.sha }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Terraform Init
run: terraform init
- name: Install AWS CLI
uses: unfor19/install-aws-cli-action@v1
with:
version: 2
verbose: false
arch: amd64
- name: Terraform Destroy
run: terraform destroy -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-west-2