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

Access network_interface generates an error #1698

Closed
lmayorga1980 opened this issue Apr 7, 2022 · 7 comments · Fixed by #1725
Closed

Access network_interface generates an error #1698

lmayorga1980 opened this issue Apr 7, 2022 · 7 comments · Fixed by #1725
Labels
bug Something isn't working

Comments

@lmayorga1980
Copy link

cdktf & Language Versions

cdktf version: 0.10.1
language: python

Affected Resource(s)

Access instance details

  #Query a GCP Image filtered by Family        
        gcp_image = DataGoogleComputeImage(self, id = "windows_image", family = "windows-2019", project="windows-cloud" )

        #Get the network interface
        net_int = ComputeInstanceNetworkInterface(subnetwork ="<SUBNETWORK>",subnetwork_project = "<SHARED-PROJECT>")

        #Create a new vm
        instance = ComputeInstance(self,id = "sample-vm", machine_type="e2-standard-4", name="cdktf-instance-1", 
                        boot_disk= ComputeInstanceBootDisk(initialize_params=ComputeInstanceBootDiskInitializeParams(image=gcp_image.name)),
                        network_interface=[net_int], zone= "us-east4-a"
        )

        #Output 
        TerraformOutput(self, "instance_ip", instance.network_interface[0].network_ip)

Debug Output

    Traceback (most recent call last):
      File "/Users/user/terraform-learning/cdktf-gcp/gcp/main.py", line 37, in <module>
        GcpBasicVmStack(app, "gcp")
      File "/Users/user/.local/share/virtualenvs/gcp-XHqyQSdy/lib/python3.9/site-packages/jsii/_runtime.py", line 86, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/Users/user/terraform-learning/cdktf-gcp/gcp/main.py", line 34, in __init__
        TerraformOutput(self, "instance_ip", instance.network_interface[0].network_ip)
    TypeError: 'InterfaceDynamicProxy' object is not subscriptable

Expected Behavior

Should be able to retrieve the instance ip in the output

Actual Behavior

Exception

Steps to Reproduce

Important Factoids

References

  • #0000
@lmayorga1980 lmayorga1980 added bug Something isn't working new Un-triaged issue labels Apr 7, 2022
@jsteinich
Copy link
Collaborator

This isn't directly supported at this time. A possible workaround:

TerraformOutput(self, "instance_ip", Fn.lookup(Fn.element(instance.network_interface, 0), "network_ip", "default"))

@lmayorga1980
Copy link
Author

TerraformOutput(self, "instance_ip", Fn.lookup(Fn.element(instance.network_interface, 0), "network_ip","default"))
Synth command: pipenv run python main.py
Error:         non-zero exit code 1

Command output on stderr:

    Traceback (most recent call last):
      File "/Users/user/terraform-learning/cdktf-gcp/gcp/main.py", line 38, in <module>
        GcpBasicVmStack(app, "gcp")
      File "/Users/user/.local/share/virtualenvs/gcp-XHqyQSdy/lib/python3.9/site-packages/jsii/_runtime.py", line 86, in __call__
        inst = super().__call__(*args, **kwargs)
      File "/Users/user/terraform-learning/cdktf-gcp/gcp/main.py", line 35, in __init__
        TerraformOutput(self, "instance_ip", Fn.lookup(Fn.element(instance.network_interface, 0), "network_ip",default_value=""))
      File "/Users/user/.local/share/virtualenvs/gcp-XHqyQSdy/lib/python3.9/site-packages/jsii/_runtime.py", line 86, in __call__
        inst = super().__call__(*args, **kwargs)
    TypeError: __init__() takes 3 positional arguments but 4 were given

@jsteinich
Copy link
Collaborator

TerraformOutput(self, "instance_ip", value=Fn.lookup(Fn.element(instance.network_interface, 0), "network_ip", "default"))

Missed explicitly setting the value property on the output.

@lmayorga1980
Copy link
Author

The workaround works.

@ansgarm ansgarm removed the new Un-triaged issue label Apr 12, 2022
@ansgarm
Copy link
Member

ansgarm commented Apr 12, 2022

@jsteinich do we already have another issue that is tracking the work required for this to function without the need for a workaround?

@jsteinich
Copy link
Collaborator

@jsteinich do we already have another issue that is tracking the work required for this to function without the need for a workaround?

#25 or #1610 should cover it.

@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants