-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathgithub-actions.yml
126 lines (126 loc) · 4.42 KB
/
github-actions.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
# This is a basic GitHub Actions pipeline to validate Terraform
name: Databricks Terraform Infrastructure Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
defaults:
run:
working-directory: examples/databricks-department-clusters-pat
env:
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
BACKEND_RG_NAME: ${{ secrets.BACKEND_RG_NAME }}
BACKEND_SA_NAME: ${{ secrets.BACKEND_SA_NAME }}
BACKEND_CONTAINER_NAME: ${{ secrets.BACKEND_CONTAINER_NAME }}
BACKEND_KEY: ${{ secrets.BACKEND_KEY }}
TERRAFORM_VERSION: 1.4.6
jobs:
build:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
strategy:
max-parallel: 4
steps:
- uses: actions/checkout@v3
- name: Install Terraform
uses: hashicorp/[email protected]
with:
terraform_version: $TERRAFORM_VERSION
- name: Check formatting of Terraform code
id: fmt
run: |
terraform fmt -check
- name: Terraform Init
id: init
run: |
terraform init \
-backend-config="resource_group_name=$BACKEND_RG_NAME" \
-backend-config="storage_account_name=$BACKEND_SA_NAME" \
-backend-config="container_name=$BACKEND_CONTAINER_NAME" \
-backend-config="key=$BACKEND_KEY"
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
run: terraform plan -no-color -input=false
continue-on-error: true
- name: Update Pull Request
uses: actions/[email protected]
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.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
release:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
strategy:
max-parallel: 4
steps:
- uses: actions/checkout@v3
- name: Install Terraform
uses: hashicorp/[email protected]
with:
terraform_version: $TERRAFORM_VERSION
- name: Set up Databricks CLI profile for Terraform provider
run: |
echo "[DEFAULT]" >> ~/.databrickscfg
echo "host = $DATABRICKS_HOST" >> ~/.databrickscfg
echo "token = $DATABRICKS_TOKEN" >> ~/.databrickscfg
- name: Check formatting of Terraform code
id: fmt
run: |
terraform fmt -check
- name: Terraform Init
id: init
run: |
terraform init \
-backend-config="resource_group_name=$BACKEND_RG_NAME" \
-backend-config="storage_account_name=$BACKEND_SA_NAME" \
-backend-config="container_name=$BACKEND_CONTAINER_NAME" \
-backend-config="key=$BACKEND_KEY"
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
run: terraform plan -no-color -input=false
continue-on-error: true
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
id: apply
run: terraform apply -no-color -input=false --auto-approve
continue-on-error: true
- name: Terraform Apply Status
if: steps.apply.outcome == 'failure'
run: exit 1