forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (88 loc) · 3.42 KB
/
deploy-ami-with-terraform.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2023 Democratized Data Foundation
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
name: Deploy AMI With Terraform Workflow
env:
# Verbosity setting for Terraform logs
TF_LOG: INFO
# Credentials for deployment to AWS.
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_AMI_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_AMI_SECRET_ACCESS_KEY }}
# Set environment type: dev, test, prod
ENVIRONMENT: "dev"
on:
workflow_run:
workflows: ["Build AMI With Packer Workflow"]
types:
- completed
pull_request:
jobs:
deploy-ami-with-terraform:
name: Deploy ami with terraform job
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools/cloud/aws/terraform
steps:
- name: Checkout code into the directory
uses: actions/checkout@v3
- name: Terraform action setup
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform format
id: fmt
run: terraform fmt -check
- name: Terraform initialization
id: init
run: terraform init -backend-config="workspaces/$ENVIRONMENT-backend.conf"
- name: Terraform workspace
id: wrokspace
run: terraform workspace select $ENVIRONMENT || terraform workspace new $ENVIRONMENT #Create workspace if it doesnt exist
- name: Terraform validate
id: validate
run: terraform validate -no-color
- name: Terraform plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false -var-file="workspaces/source-ec2-$ENVIRONMENT.tfvars"
continue-on-error: true
- name: Update pull request
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.ONLY_DEFRADB_REPO_CI_PAT }} # Must have pull request write perms.
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform plan status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: List workspaces
run: ls workspaces
- name: Terraform Apply # Only runs if pushed
if: github.event_name != 'pull_request'
run: terraform apply -auto-approve -input=false -var-file="workspaces/source-ec2-$ENVIRONMENT.tfvars"