-
Notifications
You must be signed in to change notification settings - Fork 1
93 lines (78 loc) · 2.82 KB
/
terraformapply.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
83
84
85
86
87
88
89
90
91
92
93
# This is a basic workflow that is manually triggered
name: Terraform Apply
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
# but only for the main branch
push:
paths:
- 'sandbox/**'
branches:
- main
#pull_request:
#types: [edited, opened, synchronize, reopened]
env:
SPECTROCLOUD_TF_PATH: sandbox
SPECTROCLOUD_WORKSPACE: default
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "greet"
apply:
# The type of runner that the job will run on
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.SPECTROCLOUD_TF_PATH }}
steps:
- uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.2.9
- name: Terraform fmt
id: fmt
run: terraform fmt -check
continue-on-error: true
- name: Terraform Init
id: init
run: terraform init -backend-config="endpoints=[\"${{ secrets.SC_ETCD_ENDPOINT }}\"]"
- name: Terraform Workspace
id: workspace
run: terraform workspace select ${{ env.SPECTROCLOUD_WORKSPACE }}
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Apply
id: apply
run: |
terraform apply -auto-approve -no-color -input=false \
-var 'sc_host=${{ secrets.SC_HOST }}' \
-var 'sc_project_name=${{ secrets.SC_PROJECT_NAME }}' \
-var 'sc_username=${{ secrets.SC_USERNAME }}' \
-var 'sc_password=${{ secrets.SC_PASSWORD }}'
continue-on-error: true
- uses: jwalton/gh-find-current-pr@v1
id: findPr
- uses: actions/github-script@v3
if: success() && steps.findPr.outputs.number
env:
PLAN: "terraform\n${{ steps.apply.outputs.stdout }}"
PR: ${{ steps.findPr.outputs.pr }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌 \`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️ \`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖 ${{ steps.validate.outputs.stdout }}
#### Terraform Apply 📖 \`${{ steps.apply.outcome }}\`
<details open><summary>Show Plan</summary>
\`\`\`hcl
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.SPECTROCLOUD_TF_PATH }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.issues.createComment({
issue_number: ${process.env.PR},
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})