nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
95 stars 111 forks source link

nutanix_virtual_machine incorrectly casts nic_list and disk_list via the CDKTF #624

Closed bijenkins closed 1 year ago

bijenkins commented 1 year ago

Nutanix Cluster Information

terraform -v ──(Wed,Aug09)─┘ Terraform v1.5.4 on darwin_arm64

Affected Resource(s)

We are using the CDKTF version in the python language:

Install here: https://developer.hashicorp.com/terraform/tutorials/cdktf/cdktf-install

Get Started:

We initialize cdktf, pull down the providers and convert to python:

cdktf init --template=python --providers=nutanix/nutanix@1.9.2 --local
# activate the venv created
# paste the below into main.py

main.py - after above command

#!/usr/bin/env python
from constructs import Construct
from cdktf import App, TerraformStack
from imports.nutanix.data_nutanix_image import DataNutanixImage
from imports.nutanix.data_nutanix_subnet import DataNutanixSubnet
from imports.nutanix.data_nutanix_cluster import DataNutanixCluster
from imports.nutanix.virtual_machine import VirtualMachine
from imports.nutanix.provider import NutanixProvider

from pprint import pprint
class MyStack(TerraformStack):
    def __init__(self, scope: Construct, id: str):
        super().__init__(scope, id)

        # define resources here

        provider = NutanixProvider(
            self,
            "nutanix",
            username="terraform_admin",
            password="NEVATELL",
            endpoint="prism.exist.local",
            insecure=True,
            port="9440",
        )

        image = DataNutanixImage(self, "image", image_id="93b90736-2c40-419d-bd6a-3fcc4ac158cc")

        subnet = DataNutanixSubnet(self, "subnet", subnet_id="6757c686-11cc-40fc-b9be-725f4ca4b547")

        cluster = DataNutanixCluster(self, "cluster", cluster_id="0005f342-2700-150f-467a-7cc25530ad94")

        vm = VirtualMachine(
            self,
            "vm",
            name="cdktf-vm",
            description="cdktf-vm",
            num_vcpus_per_socket=2,
            num_sockets=1,
            memory_size_mib=8092,

            cluster_uuid=cluster.cluster_id,

            nic_list=[{
                "subnet_uuid": subnet.subnet_id
            }],
            disk_list=[{
                "data_source_reference": {
                    "kind": "image",
                    "uuid": image.image_id,
                },

                "device_properties": {
                    "device_type": "DISK",
                    "disk_address": {
                        "device_index": 0,
                        "adapter_type": "SCSI",
                    },
                },
            }]
        )

app = App()
MyStack(app, "nutanix-issue")

app.synth()

this generates the output file for the cdktf: cdktf.out/stacks/nutanix-issue/cdk.tf.json

Output

  "resource": {
    "nutanix_virtual_machine": {
      "vm": {
        "//": {
          "metadata": {
            "path": "nutanix-issue/vm",
            "uniqueId": "vm"
          }
        },
        "cluster_uuid": "${data.nutanix_cluster.cluster.cluster_id}",
        "description": "cdktf-vm",
        "disk_list": [
          {
          }
        ],
        "memory_size_mib": 8092,
        "name": "cdktf-vm",
        "nic_list": [
          {
          }
        ],
        "num_sockets": 1,
        "num_vcpus_per_socket": 2
      }
    }
  },

Expected Behavior

Disk list and Nic list are empty, yet it accepts the input, we have tried a few different things such as not putting it into an array but no luck, it only accepts this type of data structure into the python cdk.

Actual Behavior

Nic list and Disk List are empty.

Steps to Reproduce


# install cdktf
cdktf init --template=python --providers=nutanix/nutanix@1.9.2 --local

# Paste the file contents above into main.py
# then run:
cdktf synth

#

### Important Factors
This is purely on they synth which generates the terraform code in json format. We believe this is a typing issue in the nutanix provider that is incorrectly converting the type of object passed into these terraform "lists".
​

### References
premkarat commented 1 year ago

CDKTF is not within our scope to support. If you are facing issue creating VM using HCL then we can definitely help. If the issue is only while using CDKTF, which seems to be the case here as the conversion seems to fail, you need to contact Terraform/Hashicorp support