Terraform plan - Changes Validation

Hello,

I’m new here and on terraform.

I’m working on making changes on virtual Machines (provider vsphere)

  • i can import existing resources with terraform import it’s OK
  • i build python a script that generate my main.tf file
  • my terraform plan said : no changes → Expected.

Now i’d like to perform changes on somes VM specs (like remove a nic card or something like that).

When i ran terraform plan i got an output that show which is going to be added,removed, changed.

Is there a way to get these informations in a “code situation” ?

I mean i can get return code of terraform plan execution (0, 1, 2) but can i get the output in a structured format ?

I’d like to ensure that only changes i want to do are going to be made before using terraform apply. (in a fully automated workflow)

Which are your practices ?

Thanks for your help :slight_smile:

Hi @tpjurnoe,

I assume by “code situation” you mean machine readable? You can use the -json flag to read the plan output as json, which has a well-defined structure. You can see details about the output format here.

1 Like

Hello jbardin,

Thanks for your answer, yes i want a machine readable of the output.

I tried the -json output here is what i got

{
  "@level": "info",
  "@message": "Terraform 1.9.8",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:05.292395+01:00",
  "terraform": "1.9.8",
  "type": "version",
  "ui": "1.2"
}
{
  "@level": "info",
  "@message": "vsphere_virtual_machine.vm: Refreshing state... [id=4210012c-c2ea-095e-a090-7411e3ccf2cb]",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:06.010155+01:00",
  "hook": {
    "resource": {
      "addr": "vsphere_virtual_machine.vm",
      "module": "",
      "resource": "vsphere_virtual_machine.vm",
      "implied_provider": "vsphere",
      "resource_type": "vsphere_virtual_machine",
      "resource_name": "vm",
      "resource_key": null
    },
    "id_key": "id",
    "id_value": "4210012c-c2ea-095e-a090-7411e3ccf2cb"
  },
  "type": "refresh_start"
}
{
  "@level": "info",
  "@message": "vsphere_virtual_machine.vm: Refresh complete [id=4210012c-c2ea-095e-a090-7411e3ccf2cb]",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:06.370466+01:00",
  "hook": {
    "resource": {
      "addr": "vsphere_virtual_machine.vm",
      "module": "",
      "resource": "vsphere_virtual_machine.vm",
      "implied_provider": "vsphere",
      "resource_type": "vsphere_virtual_machine",
      "resource_name": "vm",
      "resource_key": null
    },
    "id_key": "id",
    "id_value": "4210012c-c2ea-095e-a090-7411e3ccf2cb"
  },
  "type": "refresh_complete"
}
{
  "@level": "info",
  "@message": "vsphere_virtual_machine.vm: Drift detected (update)",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:06.421384+01:00",
  "change": {
    "resource": {
      "addr": "vsphere_virtual_machine.vm",
      "module": "",
      "resource": "vsphere_virtual_machine.vm",
      "implied_provider": "vsphere",
      "resource_type": "vsphere_virtual_machine",
      "resource_name": "vm",
      "resource_key": null
    },
    "action": "update"
  },
  "type": "resource_drift"
}
{
  "@level": "info",
  "@message": "vsphere_virtual_machine.vm: Plan to update",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:06.421483+01:00",
  "change": {
    "resource": {
      "addr": "vsphere_virtual_machine.vm",
      "module": "",
      "resource": "vsphere_virtual_machine.vm",
      "implied_provider": "vsphere",
      "resource_type": "vsphere_virtual_machine",
      "resource_name": "vm",
      "resource_key": null
    },
    "action": "update"
  },
  "type": "planned_change"
}
{
  "@level": "info",
  "@message": "Plan: 0 to add, 1 to change, 0 to destroy.",
  "@module": "terraform.ui",
  "@timestamp": "2025-03-26T09:06:06.421494+01:00",
  "changes": {
    "add": 0,
    "change": 1,
    "import": 0,
    "remove": 0,
    "operation": "plan"
  },
  "type": "change_summary"
}

it’s pretty cool, it’ll help me to process the plan in my code :slight_smile:

is there a way to get this summary in a json format too ?

That is the machine readable CLI output stream, but what you want is to see actual plan data. The plan representation is described in the documentation linked above, and you can use the show -json PLANFILE command to access the contents of the plan.

1 Like

Hello,

Thank you so much for your help !