This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
/
terraform-stages-template.yml
77 lines (67 loc) · 2.57 KB
/
terraform-stages-template.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
parameters:
environment: agents
TerraformArguments: ''
TerraformEnvVariables:
stages:
- stage: Terraform_${{ parameters.environment }}
displayName: Terraform ${{ parameters.environmentDisplayName }}
pool:
vmImage: ubuntu-latest
jobs:
- job: Terraform
displayName: Terraform
# Avoid concurrent Terraform runs on PRs, which would result in failures due to exclusive lock on remote state file.
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), variables['RUN_FLAG_TERRAFORM']))
steps:
- template: ../infrastructure/terraform-init-template.yml
parameters:
provisionStorage: true
TerraformDirectory: 301-deploy-agent-vms/terraform
environment: ${{ parameters.environment }}
# Using bash instead of Terraform extension because of following issues:
# - https://github.com/microsoft/azure-pipelines-extensions/issues/748
# - https://github.com/microsoft/azure-pipelines-extensions/issues/725
# - https://github.com/microsoft/azure-pipelines-extensions/issues/747
- bash: |
set -eu
export ARM_CLIENT_SECRET=$(ARM_CLIENT_SECRET)
terraform apply -input=false -auto-approve -var environment=${{ parameters.environment }} ${{ parameters.TerraformArguments }}
displayName: Terraform apply
workingDirectory: 301-deploy-agent-vms/terraform
env:
${{ parameters.TerraformEnvVariables }}
- stage: PostTerraform_${{ parameters.environment }}
displayName: PostTerraform ${{ parameters.environmentDisplayName }}
pool:
vmImage: ubuntu-latest
jobs:
- job: ReadTerraform
displayName: Read Terraform outputs
steps:
- template: ../infrastructure/terraform-init-template.yml
parameters:
TerraformDirectory: 301-deploy-agent-vms/terraform
environment: ${{ parameters.environment }}
- template: ../infrastructure/terraform-outputs-template.yml
parameters:
TerraformDirectory: 301-deploy-agent-vms/terraform
- bash: env
- task: AzureCLI@1
displayName: Start agents
inputs:
azureSubscription: Terraform
scriptLocation: inlineScript
inlineScript: |
set -eux # fail on error
az vm start --ids $(echo $AGENT_VM_IDS | jq -r '.[]') -o none
- job: DummySampleJob
displayName: Run Agent job
dependsOn: ReadTerraform
variables:
pool_name: $[ dependencies.ReadTerraform.outputs['Outputs.pool_name'] ]
pool: $(pool_name)
steps:
- bash: |
echo This is running on agent
hostname
displayName: Sample script