Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform JSON Disk block issues #728

Open
1 of 5 tasks
Unfairz opened this issue Apr 15, 2020 · 3 comments · May be fixed by #942
Open
1 of 5 tasks

Terraform JSON Disk block issues #728

Unfairz opened this issue Apr 15, 2020 · 3 comments · May be fixed by #942

Comments

@Unfairz
Copy link

Unfairz commented Apr 15, 2020

System Information

Linux distribution

Centos7

Terraform version

Terraform v0.12.24

Provider and libvirt versions

./terraform-provider-libvirt 0.6.2+git.1585292411.8cbe9ad0
Compiled against library: libvirt 4.1.0
Using library: libvirt 4.5.0

Checklist

  • Is your issue/contribution related with enabling some setting/option exposed by libvirt that the plugin does not yet support, or requires changing/extending the provider terraform schema?

    • Make sure you explain why this option is important to you, why it should be important to everyone. Describe your use-case with detail and provide examples where possible.
    • If it is a very special case, consider using the XSLT support in the provider to tweak the definition instead of opening an issue
    • Maintainers do not have expertise in every libvirt setting, so please, describe the feature and how it is used. Link to the appropriate documentation
  • Is it a bug or something that does not work as expected? Please make sure you fill the version information below:

Description of Issue/Question

Setup

{
  "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"
            }
          ]
        }
      ]
    }
  ]
}

Steps to Reproduce Issue

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.

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.

I thought it would be caused due to the way JSON maps values, however, in my testing I wasn't able to get it working.

Odd part is that if I go ahead and change the "volume_id" to a "block_device", for example, the error message changes to:

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

If I delete the disk block, the rest works perfectly fine, without the disk (to be expected).

Huge thanks for taking your time to take a look into this and sorry if it's something really simple that I might have missed!

@Unfairz
Copy link
Author

Unfairz commented Apr 16, 2020

Following up, I have double-checked and it seems like, in order to get the disk block to function, I would need to apply all of the attributes and set the ones that I don't need to null, as this doesn't set it automatically:

              "disk": [
                {
                 "volume_id": "${libvirt_volume.vps-001.id}",
                 "block_device": null,
                 "file": null,
                 "scsi": null,
                 "url": null,
                 "wwn": null
                }
              ],

This works and seems to be caused by the #665 merge which included the different mapping. Not sure this can be resolved due to the specific JSON syntax and the way it handles mapping.

@MalloZup
Copy link
Collaborator

@Unfairz thx for issue.We might needt to check if we can make json happy.

However the json format has less prio then the others since it is less used. But we might check if we can find a solution where there both compatible. it should exists one

@RouxAntoine
Copy link
Contributor

Hello,

I notice same error with hcl format.

--> terraform apply

Error: Incorrect attribute value type

  on computes.tf line 18, in resource "libvirt_domain" "db1":
  18:   disk = [
  19:     {
  20:       volume_id = libvirt_volume.my_root_centos.id
  21:     },
  22:     {
  23:       volume_id = libvirt_volume.my_root_debian.id
  24:     }
  25:   ]

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

I try to look at code but here https://github.com/dmacvicar/terraform-provider-libvirt/blob/v0.6.2/libvirt/resource_libvirt_domain.go#L146 attributes are marked as optional. and i fail to find error message Inappropriate value for attribute "disk". Does it had anything to do with non set value Computed: true ?

@dmacvicar dmacvicar removed the prio/low label Jul 3, 2021
@voanhduy1512 voanhduy1512 linked a pull request Apr 1, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants