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.53k stars 9.52k forks source link

Concise diff hides important identifying information in some complex nested data structures #27139

Open Interessierter opened 3 years ago

Interessierter commented 3 years ago

Current Terraform Version

terraform version
Terraform v0.14.0
+ provider registry.terraform.io/hashicorp/google v3.44.0
+ provider registry.terraform.io/hashicorp/google-beta v3.44.0...

Use-cases

I want to be able to see in the terraform output what actually changed - the new concise output makes that impossible in certain cases (I would consider this a bug but the upgrade notes said a feature-request should be opened). I wanted to add some descriptions to a Google BigQuery tables schema which is given as JSON in the TF file. With the new output it is impossible to check if terraform is doing the right thing:

 # google_bigquery_table.view_audit_monitoring_stage will be updated in-place
  ~ resource "google_bigquery_table" "view_audit_monitoring_stage" {
        id                  = "projects/myveryfineproject/datasets/mydataset/tables/view_audit_monitoring_stage"
      ~ schema              = jsonencode(
          ~ [
              ~ {
                  + description = "timestamp of the log entry, required for meaningful grafana grouping"
                    # (3 unchanged elements hidden)
                },
              ~ {
                  + description = "some description"
                    # (3 unchanged elements hidden)
                },
              ~ {
                  + description = "some other description"
                    # (3 unchanged elements hidden)
                },
...

Compare that with the output of Terraform v0.13 (or v0.14 with TF_X_CONCISE_DIFF=0) where the required context (the field name in this case) is visible:

  # google_bigquery_table.view_audit_monitoring_stage will be updated in-place
  ~ resource "google_bigquery_table" "view_audit_monitoring_stage" {
        creation_time       = 1594980376803
        dataset_id          = "mydataset"
        etag                = "XXXXXXXXXX=="
        expiration_time     = 0
        id                  = "projects/myveryfineproject/datasets/mydataset/tables/view_audit_monitoring_stage"
        labels              = {}
        last_modified_time  = 1607075944923
        location            = "europe-west1"
        num_bytes           = 0
        num_long_term_bytes = 0
        num_rows            = 0
        project             = "myveryfineproject"
      ~ schema              = jsonencode(
          ~ [
              ~ {
                  + description = "timestamp of the log entry, required for meaningful grafana grouping"
                    mode        = "NULLABLE"
                    name        = "when"
                    type        = "TIMESTAMP"
                },
              ~ {
                  + description = "some description"
                    mode        = "NULLABLE"
                    name        = "service_id"
                    type        = "STRING"
                },
              ~ {
                  + description = "some other description"
                    mode        = "NULLABLE"
                    name        = "service_name"
                    type        = "STRING"
                },
...

Attempted Solutions

Using v0.14 TF_X_CONCISE_DIFF=0 does the trick for me but when this option is removed in later versions I am out of luck checking what is actually being changed :(

Proposal

If really many users find the concise option useful (I dont, the changed/added/deleted indications are clearly visible and searchable, everything else can be skipped) please keep at least the option to show the full output (v0.14 TF_X_CONCISE_DIFF=0). Maybe display both - first the full output like it was in TF 0.13 and afterwards the shortened summary.

References

Came here because it was requested in https://www.terraform.io/upgrade-guides/0-14.html#concise-terraform-plan-output

ppanyukov commented 3 years ago

Hit the same issue recently.

It would be nice if on terraform.io we could toggle between full and short plans. Surely that should be quite doable on the backend, just write two outputs and small adjustment to the UI?

Even better, how about having expandable regions? By default they are collapsed, thus showing "short" plan. But users can expand regions of interest. Say similar to how github PR diffs work.

One downside of using TF_X_CONCISE_DIFF with terraform.io is that this needs to be set as a var in each workspace (unless there is another way?), thus having quasi-permanent setting, either full or short plan. It is quite awkward to maintain this on per-run basis.