-
Notifications
You must be signed in to change notification settings - Fork 2.2k
172 lines (172 loc) · 6.97 KB
/
infrastructure-tests.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
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
name: hashicorp/hashicat-azure/infrastructure-tests
on:
workflow_dispatch:
push:
branches:
- 'master'
env:
# See IL-574 for the source of these
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
TF_VAR_prefix: gha-infrastructure-tests-${{ github.run_id }}-${{ github.run_number }}
permissions: {}
jobs:
terraform-init:
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorp/terraform:light
permissions:
contents: read
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Terraform Init
run: terraform init
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: "tf-code"
path: ${{ github.workspace }}
azurerm-vms-available:
# We do this to aid things like IL-878, where Azure tells us we have no
# VMs of a certain size; this runs to show you what *was* available at
# the time
runs-on: ubuntu-latest
needs:
- terraform-init
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: "tf-code"
path: ${{ github.workspace }}
# Either upload or download-artifact does not preserve the exec bit on
# binaries, so fix that here
- name: fix-perms
run: |-
# e.g. .terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/linux_amd64/terraform-provider-null_v3.2.1_x5
chmod +x .terraform/providers/*/*/*/*/*/terraform-provider-*
- name: set TF vars if set
run: |-
if [ -n ${{ vars.TF_VAR_location }} ]; then
echo "TF_VAR_location=${{ vars.TF_VAR_location}}" >> "${GITHUB_ENV}"
fi
if [ -n ${{ vars.TF_VAR_vm_size }} ]; then
echo "TF_VAR_vm_size=${{ vars.TF_VAR_vm_size}}" >> "${GITHUB_ENV}"
fi
- name: check VMs
run: |-
# Whether we're using the defaults in the varables.tf file, or have overriden
# them with environment variables, 'terraform console' will tell us the current
# value that TF would use
location=$(echo "var.location" | terraform console | sed 's/^"//' | sed 's/"$//')
az vm list-skus --location "${location}" --zone --output table
terraform-validate:
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorp/terraform:light
needs:
- terraform-init
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: "tf-code"
path: ${{ github.workspace }}
# Either upload or download-artifact does not preserve the exec bit on
# binaries, so fix that here
- name: fix-perms
run: |-
# e.g. .terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/linux_amd64/terraform-provider-null_v3.2.1_x5
chmod +x .terraform/providers/*/*/*/*/*/terraform-provider-*
- name: Terraform Validate
run: terraform validate
terraform-plan:
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorp/terraform:light
needs:
- terraform-validate
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: "tf-code"
path: ${{ github.workspace }}
# Either upload or download-artifact does not preserve the exec bit on
# binaries, so fix that here
- name: fix-perms
run: |-
# e.g. .terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/linux_amd64/terraform-provider-null_v3.2.1_x5
chmod +x .terraform/providers/*/*/*/*/*/terraform-provider-*
- name: set TF vars if set
run: |-
if [ -n ${{ vars.TF_VAR_location }} ]; then
echo "TF_VAR_location=${{ vars.TF_VAR_location}}" >> "${GITHUB_ENV}"
fi
if [ -n ${{ vars.TF_VAR_vm_size }} ]; then
echo "TF_VAR_vm_size=${{ vars.TF_VAR_vm_size}}" >> "${GITHUB_ENV}"
fi
- name: Terraform Plan
run: terraform plan -out=gha-infrastructure-tests-${{ github.run_id }}-${{ github.run_number }}.plan
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: "tf-code"
path: ${{ github.workspace }}
terraform-apply:
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorp/terraform:light
needs:
- terraform-plan
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: "tf-code"
path: ${{ github.workspace }}
# Either upload or download-artifact does not preserve the exec bit on
# binaries, so fix that here
- name: fix-perms
run: |-
# e.g. .terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/linux_amd64/terraform-provider-null_v3.2.1_x5
chmod +x .terraform/providers/*/*/*/*/*/terraform-provider-*
- name: set TF vars if set
run: |-
if [ -n ${{ vars.TF_VAR_location }} ]; then
echo "TF_VAR_location=${{ vars.TF_VAR_location}}" >> "${GITHUB_ENV}"
fi
if [ -n ${{ vars.TF_VAR_vm_size }} ]; then
echo "TF_VAR_vm_size=${{ vars.TF_VAR_vm_size}}" >> "${GITHUB_ENV}"
fi
- name: Terraform Apply
run: terraform apply -auto-approve gha-infrastructure-tests-${{ github.run_id }}-${{ github.run_number }}.plan
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: "tf-code"
path: ${{ github.workspace }}
terraform-destroy:
runs-on: ubuntu-latest
container:
image: docker.mirror.hashicorp.services/hashicorp/terraform:light
needs:
- terraform-apply
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: "tf-code"
path: ${{ github.workspace }}
# Either upload or download-artifact does not preserve the exec bit on
# binaries, so fix that here
- name: fix-perms
run: |-
# e.g. .terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/linux_amd64/terraform-provider-null_v3.2.1_x5
chmod +x .terraform/providers/*/*/*/*/*/terraform-provider-*
- name: set TF vars if set
run: |-
if [ -n ${{ vars.TF_VAR_location }} ]; then
echo "TF_VAR_location=${{ vars.TF_VAR_location}}" >> "${GITHUB_ENV}"
fi
if [ -n ${{ vars.TF_VAR_vm_size }} ]; then
echo "TF_VAR_vm_size=${{ vars.TF_VAR_vm_size}}" >> "${GITHUB_ENV}"
fi
- name: Terraform Destroy
run: terraform destroy -auto-approve