Search code examples
terraformgoogle-cloud-buildcloudbuild.yaml

Terraform, weird patterns in the log [32m+ [0m


I am following this tutorial from the official GCP repo on how to deploy terraform from a cloud build:

cloudbuils.yaml

steps:
- id: 'branch name'
  name: 'alpine'
  entrypoint: 'sh'  
  args: 
  - '-c'
  - | 
      echo "***********************"
      echo "$BRANCH_NAME"
      echo "***********************"
- id: 'tf init'
  name: 'hashicorp/terraform:1.0.0'
  entrypoint: 'sh'
  args: 
  - '-c'
  - |
      if [ -d "environments/$BRANCH_NAME/" ]; then
        cd environments/$BRANCH_NAME
        terraform init
      else
        for dir in environments/*/
        do 
          cd ${dir}   
          env=${dir%*/}
          env=${env#*/}
          echo ""
          echo "*************** TERRAFORM INIT ******************"
          echo "******* At environment: ${env} ********"
          echo "*************************************************"
          terraform init || exit 1
          cd ../../
        done
      fi 

and I am having the following pattern in the log:

2022-02-21 07:13:13.094 CETStep #3 - "tf apply": [32m+[0m [0m[1m[0munique_id[0m[0m = (known after apply)
2022-02-21 07:13:13.094 CETStep #3 - "tf apply": }
2022-02-21 07:13:13.094 CETStep #3 - "tf apply":
2022-02-21 07:13:13.094 CETStep #3 - "tf apply": [0m[1mPlan:[0m 7 to add, 0 to change, 0 to destroy.

Which makes the debug a lot more painful that it needs to be, I am sure it is a simple formatting issue, but I could not find its origin.


Solution

  • There is a similar issue occur in the link1, link2 and link3 where it has been mentioned that :

    Apparently Terraform attempts to format the output using color. However, Jenkins does not output this formatting correctly and thus you see those unusual characters in the output. was able to make Terraform omit those characters in the output by using the -no-color flag. This option is available for at least three of the major Terraform functions: show, plan, and apply. It resolved by using terraform show -no-color

    For more information on how to manage infrastructure as code with terraform, cloud build and gitops, you can refer to this documentation.