-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
107 lines (85 loc) · 2.56 KB
/
azure-pipelines.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
# Pipeline for provisioning and deployment of infrastructure.
trigger: none
variables:
terraformStateName: terraformState
terraformStateVersion: 1.0
databaseBackupName: databaseBackup
databaseBackupVersion: 1.0
# If setting up the whole infra for the first time
freshSetup: true
resources:
pipelines:
- pipeline: FrontEndPipeline
source: ziaurrehman72.hello-rest-api
trigger:
branches:
- refs/heads/master
- pipeline: BackEndPipeline
source: ziaurrehman72.hello-fe
trigger:
branches:
- refs/heads/main
pool:
vmImage: ubuntu-latest
steps:
- script: |
echo Creating Directory 'terraform'
mkdir terraform
echo Creating Directory 'database'
mkdir database
ls -lrt
displayName: 'Create directory structure'
- task: DownloadPackage@1
displayName: Download Terraform State file
condition: eq(variables.freshSetup, false)
inputs:
packageType: 'upack'
feed: '861dcca4-4ec2-450d-9a1e-3da6589aaed3/88f2c9de-f3d7-411b-8a5b-eff9807a7bcc'
definition: $(terraformState)
version: $(terraformStateVersion)
downloadPath: 'terraform/'
extract: true
- task: DownloadPackage@1
displayName: Download datbase backup
condition: eq(variables.freshSetup, false)
inputs:
packageType: 'upack'
feed: '861dcca4-4ec2-450d-9a1e-3da6589aaed3/3f5ab7a3-6c73-4098-894f-ddfcfac00b01'
definition: $(databaseBackup)
version: $(databaseBackupVersion)
downloadPath: 'database/'
extract: true
#TODO: decrypt terraform state file (if freshSetup)
#TODO: decrypt database file (if freshSetup)
- task: TerraformInstaller@0
inputs:
terraformVersion: '0.14.10'
#TODO: Run terraform
- task: Bash@3
inputs:
targetType: 'inline'
script: |
cd terraform/
terraform init
displayName: 'terraform init'
- task: Bash@3
inputs:
targetType: 'inline'
script: |
cd terraform/
terraform plan -var="client_id=$(client_id)" -var="tenant_id=$(tenant_id)" -var="client_secret=$(client_secret)" -var="subscription_id=$(subscription_id)"
displayName: 'terraform plan'
- task: Bash@3
displayName: Zip Terraform State
inputs:
targetType: 'inline'
script: |
zip $(Build.ArtifactStagingDirectory)/$(terraformStateName).zip terraform/.terraform terraform/.terraform terraform/.terraform.lock.hcl
- script: |
ls -alrt -R
unzip $(Build.ArtifactStagingDirectory)/$(terraformStateName).zip
echo unzipping
ls -alrt -R
displayName: Check Directory
#TODO: publish terraform state file to az feeds
#-var="image_id=ami-abc123"