hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.79k stars 441 forks source link

hcl synth: cdk.tf.json only one attribute of List Nested Block getting populated #3631

Open tenminus11 opened 1 month ago

tenminus11 commented 1 month ago

Expected Behavior

key value pair "ip_addddress": "8.8.4.4" is missing in cdk.tf.json and cdk.hcl

  "resource": {
    "google_compute_external_vpn_gateway": {
      "ext_vpn_gtw_vpn-ext-gw1": {
        "//": {
          "metadata": {
            "path": "FoundationStack/ext_vpn_gtw_vpn-ext-gw1",
            "uniqueId": "ext_vpn_gtw_vpn-ext-gw1"
          }
        },
        "interface": [
          {
            "id": 0,
            "ip_addddress": "8.8.4.4"
          }
        ],
        "name": "vpn-ext-gw1",
        "project": "vpc-host-hub",
        "redundancy_type": "SINGLE_IP_INTERNALLY_REDUNDANT"
      },

Actual Behavior

  "resource": {
    "google_compute_external_vpn_gateway": {
      "ext_vpn_gtw_vpn-ext-gw1": {
        "//": {
          "metadata": {
            "path": "FoundationStack/ext_vpn_gtw_vpn-ext-gw1",
            "uniqueId": "ext_vpn_gtw_vpn-ext-gw1"
          }
        },
        "interface": [
          {
            "id": 0
          }
        ],
        "name": "vpn-ext-gw1",
        "project": "vpc-host-hub",
        "redundancy_type": "SINGLE_IP_INTERNALLY_REDUNDANT"
      },

Steps to Reproduce

Code sample

        ComputeExternalVpnGateway(
                self,
                "ext_vpn_gtw_vpn-ext-gw1",
                project="vpc-host-hub",
                name="vpn-ext-gw1",
                redundancy_type="SINGLE_IP_INTERNALLY_REDUNDANT",
                interface=[{
                    "id":0,
                    "ip_address":"8.8.8.8",
                }],
            )

Versions

language: python cdktf-cli: 0.20.7 node: v20.12.2 cdktf: 0.20.7 constructs: 10.3.0 jsii: 1.98.0 terraform: 1.5.6 arch: x64 os: linux 6.6.15-2rodete2-amd64 python: Python 3.11.8 pip: pip 24.0 from /xxxxx/lib/python3.11/site-packages/pip (python 3.11) pipenv: pipenv, version 2023.12.1 providers google@~> 5.30.0 (LOCAL) terraform provider version: 5.30.0 googleworkspace@~> 0.7.0 (LOCAL) terraform provider version: 0.7.0 cdktf-cdktf-provider-google (PREBUILT) terraform provider version: 5.27.0 prebuilt provider version: 13.16.0 cdktf version: ^0.20.0

Providers

┌─────────────────┬──────────────────┬─────────┬────────────┬─────────────────────────────┬─────────────────┐ │ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │ ├─────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────────┼─────────────────┤ │ google │ 5.30.0 │ │ ~> 5.30.0 │ │ │ ├─────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────────┼─────────────────┤ │ googleworkspace │ 0.7.0 │ │ ~> 0.7.0 │ │ │ ├─────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────────┼─────────────────┤ │ google │ 5.27.0 │ ^0.20.0 │ │ cdktf-cdktf-provider-google │ 13.16.0 │ └─────────────────┴──────────────────┴─────────┴────────────┴─────────────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

https://developer.hashicorp.com/terraform/plugin/framework/handling-data/blocks/list-nested

Help Wanted

Community Note

nbaju1 commented 1 month ago

Will work if you use the appropriate object corresponding to the interface:

ComputeExternalVpnGateway(
    self,
    "ext_vpn_gtw_vpn-ext-gw1",
    project="vpc-host-hub",
    name="vpn-ext-gw1",
    redundancy_type="SINGLE_IP_INTERNALLY_REDUNDANT",
    interface=[
        ComputeExternalVpnGatewayInterface(
            id=0,
            ip_address="8.8.8.8",
        )
    ],
)

  "resource": {
    "google_compute_external_vpn_gateway": {
      "ext_vpn_gtw_vpn-ext-gw1": {
        "//": {
          "metadata": {
            "path": "example/ext_vpn_gtw_vpn-ext-gw1",
            "uniqueId": "ext_vpn_gtw_vpn-ext-gw1"
          }
        },
        "interface": [
          {
            "id": 0,
            "ip_address": "8.8.8.8"
          }
        ],
        "name": "vpn-ext-gw1",
        "project": "vpc-host-hub",
        "redundancy_type": "SINGLE_IP_INTERNALLY_REDUNDANT"
      }
    }
  },
tenminus11 commented 1 month ago

Thanks a lot! Is this documented, was not able to find in documentation