lifeomic / terraform-plan-parser

Command line utility and JavaScript API for parsing stdout from "terraform plan" and converting it to JSON.
MIT License
149 stars 16 forks source link

Terraform 0.12 doesn't parse correctly (running in node v12.5.0 osx 10.14.5) #31

Open munntjlx opened 5 years ago

munntjlx commented 5 years ago

I was using terraform 0.12.x and get the following:

{
  "errors": [
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"  # aws_instance.kaeptn-eichhorn will be created\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_CHANGE_LINE",
      "message": "Unable to parse \"  + resource \"aws_instance\" \"kaeptn-eichhorn\" {\" (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + ami                          = \"ami-13b8337c\"\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + arn                          = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + associate_public_ip_address  = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + availability_zone            = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + cpu_core_count               = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + cpu_threads_per_core         = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + get_password_data            = false\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + host_id                      = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + id                           = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + instance_state               = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + instance_type                = \"t2.micro\"\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + ipv6_address_count           = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + ipv6_addresses               = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + key_name                     = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + network_interface_id         = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + password_data                = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + placement_group              = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + primary_network_interface_id = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + private_dns                  = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + private_ip                   = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + public_dns                   = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + public_ip                    = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + security_groups              = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + source_dest_check            = true\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + subnet_id                    = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + tenancy                      = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + volume_tags                  = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + vpc_security_group_ids       = (known after apply)\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + ebs_block_device {\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + delete_on_termination = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + device_name           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + encrypted             = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + iops                  = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + snapshot_id           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_id             = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_size           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_type           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"        }\" (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + ephemeral_block_device {\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + device_name  = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + no_device    = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + virtual_name = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"        }\" (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + network_interface {\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + delete_on_termination = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + device_index          = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + network_interface_id  = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"        }\" (ignoring)"
    },
    {
      "code": "ORPHAN_ATTRIBUTE_LINE",
      "message": "Attribute line \"      + root_block_device {\" is not associated with a data source or resource (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + delete_on_termination = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + iops                  = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_id             = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_size           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"          + volume_type           = (known after apply)\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"        }\" (ignoring)"
    },
    {
      "code": "UNABLE_TO_PARSE_LINE",
      "message": "Unable to parse \"    }\" (ignoring)"
    }
  ],
  "changedResources": [],
  "changedDataSources": []
}

Looks

munntjlx commented 5 years ago

output of tfplan in text:

Terraform will perform the following actions:

  # aws_instance.kaeptn-eichhorn will be created
  + resource "aws_instance" "kaeptn-eichhorn" {
      + ami                          = "ami-13b8337c"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.micro"
      + ipv6_address_count           = (known after apply)
      + ipv6_addresses               = (known after apply)
      + key_name                     = (known after apply)
      + network_interface_id         = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      + security_groups              = (known after apply)
      + source_dest_check            = true
      + subnet_id                    = (known after apply)
      + tenancy                      = (known after apply)
      + volume_tags                  = (known after apply)
      + vpc_security_group_ids       = (known after apply)

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }

      + root_block_device {
          + delete_on_termination = (known after apply)
          + iops                  = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
Roms1383 commented 4 years ago

Yes I think Terraform changed output format, I confirm I got the same issue

Roms1383 commented 4 years ago

By the way, just found out that Terraform 0.12 now has its own way of outputting terraform plan to JSON : https://www.terraform.io/docs/internals/json-format.html