Below is my terraform yaml file for to deploy the resource in terraform via Azure Devops Pipeline.
The problem in below yaml file is "terraform apply" command is running automatically. I am afraid to do that the reason is if the terraform destroy any resources it will delete the resources and it will be a big issue.
How to add the "terraform apply" command manually or by running any approve "terraform apply" command?
trigger:
- main
pool:
vmImage: ubuntu-latest
jobs:
- job: Validate
displayName: Terraform Validate
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- task: TerraformInstaller@0
displayName: Install Terraform latest
- task: TerraformTaskV2@2
displayName: 'Terraform : Init'
inputs:
backendServiceArm: 'serviceaccount-test'
backendAzureRmResourceGroupName: dowd-resourcegroup-test
backendAzureRmStorageAccountName: dowdtftestest
backendAzureRmContainerName: tfstatedowd
backendAzureRmKey: terraform.tfstate
- task: TerraformTaskV2@2
displayName: 'Terraform : Validate'
inputs:
command: validate
- job: Deploy
displayName: Terraform Deploy
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- task: TerraformInstaller@0
displayName: Install Terraform latest
- task: TerraformTaskV2@2
displayName: 'Terraform : Init'
inputs:
backendServiceArm: 'serviceaccount-test'
backendAzureRmResourceGroupName: dowd-resourcegroup-test
backendAzureRmStorageAccountName: dowdtftestest
backendAzureRmContainerName: tfstatedowd
backendAzureRmKey: terraform.tfstate
- task: TerraformTaskV2@2
displayName: 'Terraform : Plan'
inputs:
command: plan
environmentServiceNameAzureRM: 'serviceaccount-test'
- task: TerraformTaskV2@2
displayName: 'Terraform : Validate and Apply'
inputs:
command: apply
environmentServiceNameAzureRM: 'serviceaccount-test'
2
Answers
You can add a manual intervention step in pipeline before terraform apply so it will pause the pipeline until you approve.
Its solved here –
How to add a manual intervention step in Azure Pipelines yaml
You can use the environment and approval.
Sample yaml:
Steps:
Another option is to a manual intervention step mentioned by Virendra Kumar.
For this option, please note that manual intervention step just notifies users, but it will not restrict who can approve the validation step. Users with ‘Queue builds’ permission on the pipeline can resume or reject the run of a Manual Intervention.
Sample yaml:
Result: