forked from KyMidd/AzureDevOps_TerraformPipeline_YML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terraform-YML-Pipeline.yml
84 lines (77 loc) · 2.89 KB
/
Terraform-YML-Pipeline.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
# Terraform release pipeline
variables:
tf_directory: '$(System.DefaultWorkingDirectory)/terraform/envA'
terraform_version: '0.12.18'
tf_init_cli_options: '-input=false'
tf_validate_cli_options: ''
tf_plan_cli_options: '-lock=false -input=false'
tf_apply_cli_options: '-auto-approve -input=false'
# Release instructions
stages:
- stage: Terraform_Plan
jobs:
- deployment: Terraform_Plan
displayName: Terraform Plan
continueOnError: 'false'
environment: 'TerraformPlan_Environment'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-installer.TerraformInstaller@0
displayName: 'Install Terraform'
inputs:
terraformVersion: $(terraform_version)
- task: Bash@3
displayName: 'Terraform Init'
inputs:
targetType: 'inline'
script: 'terraform init $(tf_init_cli_options)'
workingDirectory: $(tf_directory)
failOnStderr: true
- task: Bash@3
displayName: 'Terraform Validation'
inputs:
targetType: 'inline'
script: 'terraform validate $(tf_validate_cli_options)'
workingDirectory: $(tf_directory)
failOnStderr: true
- task: Bash@3
displayName: 'Terraform Plan'
inputs:
targetType: 'inline'
script: 'terraform plan $(tf_plan_cli_options)'
workingDirectory: $(tf_directory)
failOnStderr: true
- stage: Terraform_Apply
jobs:
- deployment: Terraform_Apply
displayName: Terraform Apply
continueOnError: 'false'
# Run this stage if previous stage(s) succeeded and build reason ISN'T a pull request
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
environment: 'YamlTerraformApplyEnvironment'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-installer.TerraformInstaller@0
displayName: 'Install Terraform'
inputs:
terraformVersion: $(terraform_version)
- task: Bash@3
displayName: 'Terraform Init'
inputs:
targetType: 'inline'
script: 'terraform init $(tf_init_cli_options)'
workingDirectory: $(tf_directory)
failOnStderr: true
- task: Bash@3
displayName: 'Terraform Apply'
inputs:
targetType: 'inline'
script: 'terraform apply $(tf_apply_cli_options)'
workingDirectory: $(tf_directory)
failOnStderr: true