# Issues with Terraform JSON

**URL:** <https://discuss.hashicorp.com/t/issues-with-terraform-json/7704>\
**Category:** Terraform\
**Created:** [April 15, 2020, 9:00pm UTC](https://discuss.hashicorp.com/t/issues-with-terraform-json/7704 "2020-04-15T21:00:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unfairz](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/unfairz/32/6043_2.png) [@Unfairz](https://discuss.hashicorp.com/u/Unfairz)\
**Post date:** [April 15, 2020, 9:00pm UTC](https://discuss.hashicorp.com/t/issues-with-terraform-json/7704/1 "2020-04-15T21:00:04Z")

</div>

Hello folks! I have been dealing with this problem for quite some time now and am hoping to be missing something really simple at this point!

Basically, when I use the JSON syntax of building the terraform files,I cannot get the disk portition to function correctly and the error given is quite odd. When I use the HLC2 format, it works like a charm!

I am not using one of the known providers but the libvirt one for creating VMs with KVM:

> **[dmacvicar/terraform-provider-libvirt](https://github.com/dmacvicar/terraform-provider-libvirt/)**
>
> Terraform provider to provision infrastructure with Linux's KVM using libvirt - dmacvicar/terraform-provider-libvirt

```
{
  "data": [
    {
      "template_file": [
        {
          "user_data": [
            {
              "template": "$file(\"/home/terraform/config/cloud_init.cfg\")"
            }
          ]
        }
      ]
    },
    {
      "template_file": [
        {
          "meta_data": [
            {
              "template": "file(\"/home/terraform/config/network_config.cfg\")"
            }
          ]
        }
      ]
    }
  ],
  "resource": [
    {
      "libvirt_volume": [
        {
          "vm-001": [
            {
              "format": "qcow2",
              "name": "vm-001.qcow2",
              "pool": "vm-storage",
              "source": "/home/terraform/images/CentOS-7.qcow2"
            }
          ]
        }
      ]
    },
    {
      "libvirt_cloudinit_disk": [
        {
          "cloudinit": [
            {
              "meta_data": "${data.template_file.meta_data.rendered}",
              "name": "cloudinit.iso",
              "pool": "vm-storage",
              "user_data": "${data.template_file.user_data.rendered}"
            }
          ]
        }
      ]
    },
    {
      "libvirt_domain": [
        {
          "vm-001": [
            {
              "autostart": "true",
              "cloudinit": "${libvirt_cloudinit_disk.cloudinit.id}",
              "memory": "2048",
              "name": "vm-001",
              "network_interface": [
                {
                   "bridge": "br0"
                }
              ],
              "disk": {
              [
                {
                 "volume_id": "${libvirt_volume.vm-001.id}"
                }
              ]
              },
              "running": "true",
              "vcpu": "2"
            }
          ]
        }
      ]
    }
  ]
}

```

This is my .tf.json file and the error given is:

```
Error: Incorrect attribute value type

  on vm.tf.json line 69, in resource[2].libvirt_domain[0].vm-001[0]:
  69: "disk": [
  70: {
  71: "volume_id": "${libvirt_volume.vm-001.id}"
  72: }
  73: ],

Inappropriate value for attribute "disk": element 0: attributes
"block_device", "file", "scsi", "url", and "wwn" are required.

```

If someone would give me a hand with this it would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [April 15, 2020, 11:36pm UTC](https://discuss.hashicorp.com/t/issues-with-terraform-json/7704/2 "2020-04-15T23:36:34Z")

</div>

Hi @Unfairz,

It looks like (as of [GitHub issue #665](https://github.com/dmacvicar/terraform-provider-libvirt/issues/665) being closed) the provider is using the special [attributes as blocks](https://www.terraform.io/docs/configuration/attr-as-blocks.html) processing mode for this particular argument, which causes it to behave in some unusual ways as described on that documentation page. In particular, you’re running into the quirk described under [the _In JSON Syntax_ heading](https://www.terraform.io/docs/configuration/attr-as-blocks.html#in-json-syntax):

> Due to the ambiguity of the JSON syntax, there is no way to distinguish based on the input alone between argument and nested block usage, so the JSON syntax cannot support the nested block processing mode for these arguments. This is, unfortunately, one necessary concession on the equivalence between native syntax and JSON syntax made pragmatically for compatibility with existing provider design patterns. Providers may phase out such patterns in future major releases.

To make it work, you’ll need to write the object representing this block as if it were a normal object construction expression, rather than using the JSON conventions for nested blocks. That means the object value must have all of the attributes that the object type of the argument expects, with the ones you don’t need set to `null`. (The block syntax normally sets these to `null` automatically for you in the background, but the provider has disabled that processing mode here).

```auto
              "disk": {
              [
                {
                 "volume_id": "${libvirt_volume.vm-001.id}",
                 "block_device": null,
                 "file": null,
                 "scsi": null,
                 "url": null,
                 "wwm": null
                }
              ]
              },

```

This unusual requirement could be fixed at the provider level by disabling the special processing mode, but from reading the issue linked above it looks like opting into it was intentional in order to restore some behavior that was possible under Terraform 0.11 (I didn’t follow exactly what), and so it’s perhaps unlikely that it would be reverted back to the standard processing mode at this point.

---

<div class="post-metadata">

**Author:** ![Unfairz](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/unfairz/32/6043_2.png) [@Unfairz](https://discuss.hashicorp.com/u/Unfairz)\
**Post date:** [April 16, 2020, 7:20am UTC](https://discuss.hashicorp.com/t/issues-with-terraform-json/7704/3 "2020-04-16T07:20:58Z")

</div>

Hello! @apparentlymart

Thank you so much for explaining this so well and showing me where the problem is! You have truly helped me a lot!

Hope you have a wonderful day and once again, thank you!!

---

<div class="post-metadata">

**Author:** ![MagicRB](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/magicrb/32/16401_2.png) [@MagicRB](https://discuss.hashicorp.com/u/MagicRB)\
**Post date:** [March 31, 2023, 8:16pm UTC](https://discuss.hashicorp.com/t/issues-with-terraform-json/7704/4 "2023-03-31T20:16:19Z")

</div>

i just stumbled upon this in the `vault_auth_backend.tune`, but setting the fields as `null` doesn’t seem to do it. It fails type checking. Terraform fails with

```auto
│ Error: expected 'tune.0.max_lease_ttl' to be a valid duration string

```
