Skip to content

Instantly share code, notes, and snippets.

@gerrited
Created December 19, 2024 12:19
Show Gist options
  • Save gerrited/b19ca17badc88d44de15fb3e0daa7821 to your computer and use it in GitHub Desktop.
Save gerrited/b19ca17badc88d44de15fb3e0daa7821 to your computer and use it in GitHub Desktop.
trigger:
- none
pr:
- develop
schedules:
- cron: "0 6 * * *"
branches:
include:
- develop
always: true # whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run. The default is false.
pool:
vmImage: ubuntu-latest
variables:
serviceConnection: 'terraform-check'
terraformWorkingDirectory: '$(System.DefaultWorkingDirectory)/terraform'
terraformVersion: 'latest'
steps:
- task: TerraformInstaller@0
inputs:
terraformVersion: '$(terraformVersion)'
- task: TerraformTaskV3@3
displayName: Terraform Init
inputs:
provider: 'azurerm'
command: 'init'
workingDirectory: '$(terraformWorkingDirectory)'
backendServiceArm: '$(serviceConnection)'
backendAzureRmResourceGroupName: 'terraform'
backendAzureRmStorageAccountName: 'terraformstate'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'terraform.azuregermany.tfstate'
- task: TerraformTaskV3@3
displayName: Terraform Validate
inputs:
provider: 'azurerm'
command: 'validate'
workingDirectory: $(terraformWorkingDirectory)
- task: TerraformTaskV3@3
displayName: Terraform Plan
name: terraform_plan
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(terraformWorkingDirectory)'
commandOptions: '-detailed-exitcode -lock=false'
environmentServiceNameAzureRM: '$(serviceConnection)'
- task: Bash@3
displayName: Check Result of Terraform Plan
condition: eq(variables['terraform_plan.changesPresent'], 'true')
inputs:
targetType: 'inline'
script: |
echo Infrastructure changes detected! See step "Terraform Plan" for more information.
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment