generated from bcgov-c/bcgov-terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 1
140 lines (123 loc) · 4.87 KB
/
terraform-v2-custom.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Terraform Custom Realm Batch Job
on:
workflow_dispatch:
schedule:
- cron: 0 12 * * *
env:
TF_VERSION: 1.1.4
KEYCLOAK_V2_DEV_URL: https://dev.loginproxy.gov.bc.ca
KEYCLOAK_V2_TEST_URL: https://test.loginproxy.gov.bc.ca
KEYCLOAK_V2_PROD_URL: https://loginproxy.gov.bc.ca
REALM_REGISTRY_API_URL: ${{ secrets.REALM_REGISTRY_API_URL }}
jobs:
terraform:
runs-on: ubuntu-20.04
steps:
- uses: hmarr/debug-action@v2
- uses: actions/checkout@v2
- name: Fetch Requests Count
id: requests
uses: fjogeleit/http-request-action@master
with:
url: ${{ env.REALM_REGISTRY_API_URL }}/realms/pending
method: GET
customHeaders: '{"Authorization": "${{ secrets.REALM_REGISTRY_GH_API_TOKEN }}"}'
timeout: '60000'
- name: Get Requests Count
id: count
run: |
count=$(jq length <<< ${{ steps.requests.outputs.response }})
echo "$count"
echo "count=$count" >> $GITHUB_OUTPUT
- name: Setup Terraform
if: steps.count.outputs.count != '0'
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Terraform Format
id: fmt
if: steps.count.outputs.count != '0'
run: terraform fmt -check
working-directory: ./terraform-v2-custom
- name: Terraform Variables
if: steps.count.outputs.count != '0'
run: |
cat >"config.tf" <<EOF
terraform {
backend "s3" {
bucket = "xgr00q-prod-keycloak"
key = "keycloak/gold-custom"
region = "ca-central-1"
dynamodb_table = "xgr00q-prod-state-locking"
access_key = "${{ secrets.TF_S3_ACCESS_KEY }}"
secret_key = "${{ secrets.TF_S3_SECRET_KEY }}"
role_arn = "${{ secrets.TF_S3_ROLE_ARN }}"
}
required_providers {
keycloak = {
source = "mrparkers/keycloak"
version = "3.10.0"
}
}
}
EOF
cat >"ci.auto.tfvars" <<EOF
dev_keycloak_url="${{ env.KEYCLOAK_V2_DEV_URL }}"
test_keycloak_url="${{ env.KEYCLOAK_V2_TEST_URL }}"
prod_keycloak_url="${{ env.KEYCLOAK_V2_PROD_URL }}"
dev_client_secret="${{ secrets.KEYCLOAK_V2_DEV_CLIENT_SECRET }}"
test_client_secret="${{ secrets.KEYCLOAK_V2_TEST_CLIENT_SECRET }}"
prod_client_secret="${{ secrets.KEYCLOAK_V2_PROD_CLIENT_SECRET }}"
EOF
working-directory: ./terraform-v2-custom
- name: Terraform Init
if: steps.count.outputs.count != '0'
id: init
run: terraform init -upgrade
working-directory: ./terraform-v2-custom
- name: Terraform Plan
if: steps.count.outputs.count != '0'
id: plan
run: terraform plan -no-color
working-directory: ./terraform-v2-custom
continue-on-error: true
- name: Update Realm Request TF Plan Status
if: steps.count.outputs.count != '0'
uses: fjogeleit/http-request-action@master
with:
url: ${{ env.REALM_REGISTRY_API_URL }}/realms/pending
method: PUT
data: "{\"ids\": ${{ steps.requests.outputs.response }}, \"action\": \"tf_plan\", \"success\": \"${{ steps.plan.outcome != 'failure' }}\"}"
customHeaders: '{"Authorization": "${{ secrets.REALM_REGISTRY_GH_API_TOKEN }}"}'
timeout: '60000'
- name: Terraform Plan Status
if: steps.count.outputs.count != '0' && steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: steps.count.outputs.count != '0' && steps.plan.outcome != 'failure'
id: apply
run: terraform apply -auto-approve
working-directory: ./terraform-v2-custom
continue-on-error: true
- uses: bcgov/sso-requests-actions/keycloak@v0.63.0
if: steps.count.outputs.count != '0' && steps.apply.outcome != 'failure'
with:
dev-keycloak-url: ${{ env.KEYCLOAK_V2_DEV_URL }}
test-keycloak-url: ${{ env.KEYCLOAK_V2_TEST_URL }}
prod-keycloak-url: ${{ env.KEYCLOAK_V2_PROD_URL }}
dev-client-secret: ${{ secrets.KEYCLOAK_V2_DEV_CLIENT_SECRET }}
test-client-secret: ${{ secrets.KEYCLOAK_V2_TEST_CLIENT_SECRET }}
prod-client-secret: ${{ secrets.KEYCLOAK_V2_PROD_CLIENT_SECRET }}
tasks: create-master-viewer
- name: Update Realm Request TF Apply Status
if: steps.count.outputs.count != '0'
uses: fjogeleit/http-request-action@master
with:
url: ${{ env.REALM_REGISTRY_API_URL }}/realms/pending
method: PUT
data: "{\"ids\": ${{ steps.requests.outputs.response }}, \"action\": \"tf_apply\", \"success\": \"${{ steps.apply.outcome != 'failure' }}\"}"
customHeaders: '{"Authorization": "${{ secrets.REALM_REGISTRY_GH_API_TOKEN }}"}'
timeout: '60000'
- name: Terraform Apply Status
if: steps.count.outputs.count != '0' && steps.apply.outcome == 'failure'
run: exit 1