I am recently trying to detect drift in a yaml pipeline in azure. Im currently using a bash script in the pipeline to do a terraform plan and fail the pipeline if there is drift. Im using -detailed-exitcode as an argument to see if there are changes made to the terraform plan file.
However the code doesnt seem to take in the exit code and the terraform plan is simply being exeuted and output to a file even though there was drift detected. Im unsure why it happens... isit because i failed to install something?
Or anyone could give me an alternative other than -detailed-exitcode .
Below is my code
- bash: |
terraform init -reconfigure
terraform validate
terraform plan -detailed-exitcode -out=FILE_NEW || exit_status=$?
if [ $exit_status -eq 0 ]; then
echo "No changes, not applying"
elif [ $exit_status -eq 1 ]; then
echo "Terraform plan failed"
exit 1
elif [ $exit_status -eq 2 ]; then
echo "Drift Detected"
fi
displayName: Detecting Terraform Drift