/
no-template.yaml
180 lines (168 loc) · 6.71 KB
/
no-template.yaml
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
name: $(BuildDefinitionName)_$(date:yyyyMMdd)$(rev:.r)
trigger: none
pr: none
variables:
- group: azurefestivecalendar-production
- name: backendServiceArm
value: 'tamopstf2'
- name: backendAzureRmResourceGroupName
value: 'tamopstfstates'
- name: backendAzureRmStorageAccountName
value: 'tfstatedevops'
- name: backendAzureRmContainerName
value: 'azuredevopstemplates'
- name: backendAzureRmKey
value: 'terraform.tfstate'
- name: environment
value: 'production'
stages :
- stage: validate
jobs:
- job: validate
continueOnError: false
steps:
- task: TerraformInstaller@0
displayName: 'install'
inputs:
terraformVersion: '0.13.3'
- task: TerraformTaskV1@0
displayName: 'init'
inputs:
provider: 'azurerm'
command: 'init'
backendServiceArm: 'tamopstf'
backendAzureRmResourceGroupName: '${{ variables.backendAzureRmResourceGroupName}}'
backendAzureRmStorageAccountName: '${{ variables.backendAzureRmStorageAccountName}}'
backendAzureRmContainerName: '${{ variables.backendAzureRmContainerName }}'
backendAzureRmKey: 'terraform.tfstate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- task: TerraformTaskV1@0
displayName: 'validate'
inputs:
provider: 'azurerm'
command: 'validate'
- stage: plan
dependsOn: [validate]
condition: succeeded('validate')
jobs:
- job: terraform_plan_develop
steps:
- checkout: self
- task: TerraformInstaller@0
displayName: 'install'
inputs:
terraformVersion: '0.13.3'
- task: TerraformTaskV1@0
displayName: 'init'
inputs:
provider: 'azurerm'
command: 'init'
backendServiceArm: 'tamopstf'
backendAzureRmResourceGroupName: '${{ variables.backendAzureRmResourceGroupName}}'
backendAzureRmStorageAccountName: '${{ variables.backendAzureRmStorageAccountName}}'
backendAzureRmContainerName: '${{ variables.backendAzureRmContainerName }}'
backendAzureRmKey: 'terraform.tfstate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- task: TerraformTaskV1@0
displayName: 'plan'
inputs:
provider: 'azurerm'
command: 'plan'
commandOptions: '-input=false -var-file="../$(Environment)/$(Environment).tfvars"'
environmentServiceNameAzureRM: 'tamopstf'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- stage: apply
dependsOn: [plan]
condition: succeeded('plan')
jobs:
- job: terraform_apply_production
steps:
- checkout: self
- task: TerraformInstaller@0
displayName: 'install'
inputs:
terraformVersion: '0.13.3'
- task: TerraformTaskV1@0
displayName: 'init'
inputs:
provider: 'azurerm'
command: 'init'
backendServiceArm: 'tamopstf'
backendAzureRmResourceGroupName: '${{ variables.backendAzureRmResourceGroupName}}'
backendAzureRmStorageAccountName: '${{ variables.backendAzureRmStorageAccountName}}'
backendAzureRmContainerName: '${{ variables.backendAzureRmContainerName }}'
backendAzureRmKey: 'terraform.tfstate'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- task: TerraformTaskV1@0
displayName: 'plan'
inputs:
provider: 'azurerm'
command: 'plan'
commandOptions: '-input=false -var-file="../$(Environment)/$(Environment).tfvars"'
environmentServiceNameAzureRM: 'tamopstf'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- task: TerraformTaskV1@0
displayName: 'apply'
inputs:
provider: 'azurerm'
command: 'apply'
commandOptions: '-input=false -auto-approve -var-file="../$(Environment)/$(Environment).tfvars"'
environmentServiceNameAzureRM: 'tamopstf'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- stage: test
dependsOn: [apply]
condition: succeeded('apply')
jobs:
- job: Inspec_Testing
steps:
- task: UseRubyVersion@0
displayName: 'Install Ruby'
inputs:
versionSpec: '>= 2.5'
addToPath: true
- script: gem install inspec-bin
displayName: 'Install inspec-bin'
- task: Bash@3
displayName: 'Run inspec tests'
inputs:
targetType: inline
script: |
export AZURE_SUBSCRIPTION_ID=$(AZURE_SUBSCRIPTION_ID)
export AZURE_CLIENT_ID=$(AZURE_CLIENT_ID)
export AZURE_CLIENT_SECRET=$(AZURE_CLIENT_SECRET)
export AZURE_TENANT_ID=$(AZURE_TENANT_ID)
inspec exec ./azure-inspec-tests/ -t azure:// --chef-license=accept --reporter cli junit:inspectestresults.xml
- task: PublishTestResults@2
displayName: Publish inspec test results
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/inspectestresults.xml'
mergeTestResults: true
- stage: bash
dependsOn: [apply]
condition: succeeded('apply')
jobs:
- job: bash_echo
steps:
- task: Bash@3
displayName: 'Echo Test'
inputs:
targetType: inline
script: |
Echo "Test Script!"
- stage: cli
dependsOn: [apply]
condition: succeeded('apply')
jobs:
- job: azcli_resourcegroup_create
steps:
- task: AzureCLI@2
displayName: 'Deploy Resource Group'
inputs:
azureSubscription: 'tamopstf'
scriptType: bash
scriptLocation: inlineScript
addSpnToEnvironment: true
inlineScript: |
#!/bin/bash
az group create -l uksouth -n bicep-rg