forked from Azure/mlops-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (194 loc) · 7.33 KB
/
tf-gha-install-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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: tf-gha-install-terraform.yml
on:
workflow_call:
inputs:
TFAction:
type: string
description: 'Terraform Action- Apply or Destroy'
required: true
default: 'apply'
dply_environment:
type: string
required: true
location:
description: 'Location'
type: string
required: true
namespace:
description: 'Namespace'
type: string
required: true
postfix:
description: 'postfix'
type: string
required: true
environment:
description: 'Enviroment of the AML workspace'
type: string
required: true
enable_aml_computecluster:
description: 'Boolean to decide whether to deploy an AML compute cluster or not'
type: boolean
required: true
enable_monitoring:
description: 'Boolean to decide whether to enable monitoring'
type: boolean
required: true
terraform_version:
description: 'Terraform version'
type: string
required: true
terraform_workingdir:
description: 'Terraform State working directory'
type: string
required: true
terraform_st_location:
description: 'Terraform version'
type: string
required: true
terraform_st_storage_account:
type: string
description: 'name of the terraform state storage account to create'
required: true
terraform_st_resource_group:
type: string
description: 'name of the terraform resource group to host the terraform state resources'
required: true
terraform_st_container_name:
type: string
description: 'name of the terraform state container'
required: true
terraform_st_key:
type: string
description: 'name of the terraform state key'
required: true
terraform_plan_location:
type: string
description: 'location of Terraform plan'
required: true
terraform_plan_vnet:
type: string
description: 'vnet of Terraform plan'
required: true
secrets:
azure_creds:
required: true
clientId:
required: true
clientSecret:
required: true
tenantId:
required: true
subscriptionId:
required: true
jobs:
create-tfstate-resources:
name: Create Resources for Terraform State
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: azure-login
uses: azure/login@v1
with:
creds: ${{ env.AZURE_CREDENTIALS }}
# environment: 'TBD' - default to azurecloud
env:
AZURE_CREDENTIALS: ${{ secrets.azure_creds }}
- name: create-tfstate-resource-group
uses: azure/CLI@v1
with:
azcliversion: 2.30.0
#
inlineScript: |
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
az group create --location ${{ inputs.terraform_st_location }} --name ${{ inputs.terraform_st_resource_group }}
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: create-tfstate-storage-account
uses: azure/CLI@v1
with:
azcliversion: 2.30.0
#
inlineScript: |
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
az storage account create -n ${{ inputs.terraform_st_storage_account }} -g ${{ inputs.terraform_st_resource_group }} -l ${{ inputs.terraform_st_location }} --sku Standard_LRS
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: create-tfstate-storage-container
uses: azure/CLI@v1
with:
azcliversion: 2.30.0
#
inlineScript: |
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
az storage container create --account-name ${{ inputs.terraform_st_storage_account }} --name ${{ inputs.terraform_st_container_name }}
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
install-terraform:
name: 'Install Terraform'
runs-on: ubuntu-latest
needs: create-tfstate-resources
environment: ${{ inputs.dply_environment }}
defaults:
run:
shell: bash
steps:
- name: checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Terraform Init
run: echo ${{ env.ARM_SUBSCRIPTION_ID }};
echo "all env:${{ env.ARM_CLIENT_ID }}::${{ env.ARM_SUBSCRIPTION_ID }}";
terraform -chdir=${{ inputs.terraform_workingdir }} init
-backend-config='storage_account_name=${{ inputs.terraform_st_storage_account }}'
-backend-config='container_name=${{ inputs.terraform_st_container_name }}'
-backend-config='key=${{ inputs.terraform_st_key }}'
-backend-config='resource_group_name=${{ inputs.terraform_st_resource_group }}';
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: Terraform Validate
run: terraform -chdir=${{ inputs.terraform_workingdir }} validate
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: Terraform Plan
run: terraform -chdir=${{ inputs.terraform_workingdir }} plan -out=plan.tfplan -input=false -var "location=${{ inputs.terraform_plan_location }}" -var "prefix=${{ inputs.namespace }}" -var "postfix=${{ inputs.postfix }}" -var "environment=${{ inputs.environment }}"
-var "enable_aml_computecluster=${{ inputs.enable_aml_computecluster }}" -var "enable_monitoring=${{ inputs.enable_monitoring }}" -var "client_secret=${{ env.ARM_CLIENT_SECRET }}"
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: Terraform Apply
if: ${{ inputs.TFAction == 'apply'}}
run: terraform -chdir=${{ inputs.terraform_workingdir }} apply -input=false -auto-approve plan.tfplan
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}
- name: Terraform Destroy
if: ${{ inputs.TFAction == 'destroy' }}
run: terraform -chdir=${{ inputs.terraform_workingdir }} destroy -input=false -auto-approve
env:
ARM_CLIENT_ID: ${{ secrets.clientId }}
ARM_CLIENT_SECRET: ${{ secrets.clientSecret }}
ARM_SUBSCRIPTION_ID: ${{ secrets.subscriptionId }}
ARM_TENANT_ID: ${{ secrets.tenantId }}