hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.6k stars 9.54k forks source link

0.15.4 successful apply leaves the terminal cursor green #28762

Open StephenWithPH opened 3 years ago

StephenWithPH commented 3 years ago

Terraform Version

Terraform v0.15.4
on linux_amd64
+ provider registry.terraform.io/hashicorp/null v3.1.0

Terraform Configuration Files

resource "null_resource" "foo" {}

Expected Behavior

Terraform should disable its colorized output after terraform apply.

Actual Behavior

A successful terraform apply leaves the cursor green.

Steps to Reproduce

  1. with the configuration above, terraform init
  2. terraform apply
apparentlymart commented 3 years ago

Hi @StephenWithPH! Thanks for reporting this.

Unfortunately I can't reproduce what you've described on my linux_amd64 system. :confounded: When I run terraform apply with the configuration you included here, Terraform produces colored text as part of its output but includes a reset sequence after each one.

Are there any other details that might be relevant here? For example, did Terraform crash in some way which might've caused its output to be incomplete on your system?

StephenWithPH commented 3 years ago

@apparentlymart thank you for looking into this. It's clearly the lowest-of-low priority bug reports to investigate. :laughing:

I can consistently reproduce it with apply and destroy. Interestingly, once I hit enter on the terminal, the green cursor goes away. Chasing that clue with:

$ terraform apply -auto-approve > am-i-crazy.txt

... and cating am-i-crazy.txt gives me the same behavior: green cursor until <enter>.

vim tells me that the final line of that output is not terminated with a newline (vim's noeol warning). If I fix that, cating the file no longer leaves a green cursor.

I speculate that my terminal (XTerm on NixOS) must want a newline before applying the ansi codes, so the final zero doesn't apply until I hit enter.

Here is the captured output (ignore the vim relative line numbers) for reference; Terraform properly zeros out the coloring:

  1   
    1 Terraform used the selected providers to generate the following execution
    2 plan. Resource actions are indicated with the following symbols:
    3   ^[[32m+^[[0m create
    4 ^[[0m
    5 Terraform will perform the following actions:
    6 
    7 ^[[1m  # null_resource.foo^[[0m will be created^[[0m^[[0m
    8 ^[[0m  ^[[32m+^[[0m^[[0m resource "null_resource" "foo" {
    9       ^[[32m+^[[0m ^[[0m^[[1m^[[0mid^[[0m^[[0m = (known after apply)
   10     }
   11 
   12 ^[[0m^[[1mPlan:^[[0m 1 to add, 0 to change, 0 to destroy.
   13 ^[[0m^[[0m^[[1mnull_resource.foo: Creating...^[[0m^[[0m
   14 ^[[0m^[[1mnull_resource.foo: Creation complete after 0s [id=930432790861529261]^[[0m
   15 ^[[0m^[[1m^[[32m
   16 Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
   17 ^[[0m
davetustin commented 3 years ago

I seem to be facing the same problem in VSCode on Windows. All the formatting has gone weird and I get no green + or yellow - etc.

Here is a basic example of running terraform init.

[0m[1mInitializing the backend...[0m

[0m[1mInitializing provider plugins...[0m
- Reusing previous version of hashicorp/azurerm from the dependency lock file
- Using previously-installed hashicorp/azurerm v2.69.0

[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
[0m[32m
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.[0m

I have reinstalled VSCode and updated the version of terraform to the latest. I think this started happening when I updated to 1.0.3.

I am still trying to get to the bottom of it, but I think it is an environmental issue.

iamBhushan10 commented 2 years ago

I am also facing same issue please suggest how to resolve it

iamBhushan10 commented 2 years ago

[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m [0m[32m