I’m using the
terraform state show command, but I’m having issues with coloured output when there is an error.
Take the following example, which fist checks the Terraform state to see if a resource is already managed by Terraform, and then imports the resource if it is not -
terraform state show module.x.y.z 2>&1 if [[ $? > 0 ]]; then terraform import module.x.y.z abc else echo " -- Resource is already managed by Terraform." fi
In cases where the resource is not managed by Terraform, an error is redirected to stdout. However, when this is output to the console the colour still remains, and in logs (Octopus) colour flags are added to the output and it messes it up.
Most Terraform commands seem to have the
-no-color option, but not
terraform state show.
Is there a more global way to get rid of the coloured output, as it’s really not wanted/required in most cases when using Terraform win CI/CD.