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

Google provider basic compute_instance creation fails #934

Closed
madeddie opened this issue Aug 26, 2021 · 9 comments
Closed

Google provider basic compute_instance creation fails #934

madeddie opened this issue Aug 26, 2021 · 9 comments
Assignees
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working help wanted Community contributions welcome as the core team is unlikely to work on this soon needs-reproduction priority/backlog Low priority (though possibly still important). Unlikely to be worked on within the next 6 months. provider get / generation upstream/jsii Pending upstream work on JSII

Comments

@madeddie
Copy link

madeddie commented Aug 26, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

cdktf 0.5.0 installed with Homebrew
python 3.9.5
google@~> 3.0 with cdktf get Aug 24

Affected Resource(s)

google.ComputeInstance

Expected Behavior

Using the example from https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started

resource "google_compute_instance" "vm_instance" {
  name         = "terraform-instance"
  machine_type = "f1-micro"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    # A default network is created for all GCP projects
    network = "default"
    access_config {
    }
  }
}

I tried to create a basic compute instance.

cdktf convert --language python generates:

google.ComputeInstance(self, "vm_instance",
    boot_disk=[{
        "initialize_params": [{
            "image": "debian-cloud/debian-9"
        }
        ]
    }
    ],
    machine_type="f1-micro",
    name="terraform-instance",
    network_interface=[{
        "access_config": [{}],
        "network": "default"
    }
    ]
)

Which looks fine. I was expecting cdktf synth and deploy to create this instance.

Actual Behavior

cdktf synth generated snippet of the compute instance resource:

  "resource": {
    "google_compute_instance": {
      "vm_instance": {
        "machine_type": "f1-micro",
        "name": "terraform-instance",
        "boot_disk": [
          {}
        ],
        "network_interface": [
          {
            "network": "default"
          }
        ],
        "//": {
          "metadata": {
            "path": "infra/vm_instance",
            "uniqueId": "vm_instance",
            "stackTrace": [
              "new TerraformElement (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/jsii-kernel-1NziaX/node_modules/cdktf/lib/terraform-element.js:21:28)",
              "new TerraformResource (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/jsii-kernel-1NziaX/node_modules/cdktf/lib/terraform-resource.js:17:9)",
              "new ComputeInstance (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/jsii-kernel-1NziaX/node_modules/google/providers/google/compute-instance.js:194:9)",
              "/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:8367:58",
              "Kernel._wrapSandboxCode (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:8795:24)",
              "Kernel._create (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:8367:34)",
              "Kernel.create (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:8108:29)",
              "KernelHost.processRequest (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:9692:36)",
              "KernelHost.run (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:9655:22)",
              "Immediate._onImmediate (/private/var/folders/pv/4vf3cvx91q3gqkr23xgfz0tr0000gn/T/tmpaodynvxk/lib/program.js:9656:46)",
              "processImmediate (node:internal/timers:464:21)"
            ]
          }
        }
      }
    }
  }

which is missing the initialize_params part of bootdisk.

Steps to Reproduce

As described in expected behavior.

@madeddie madeddie added bug Something isn't working new Un-triaged issue labels Aug 26, 2021
@danieldreier danieldreier added feature/convert priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. and removed new Un-triaged issue labels Aug 27, 2021
@danieldreier
Copy link
Contributor

@madeddie thank you for reporting this! If this you're blocked on this before we're able to fix it, one option is to use the escape hatch to fix the generated config.

@madeddie
Copy link
Author

@danieldreier thank you, will do.
I actually tested it with typescript and there's no problem there, so I'm guessing it could be something with the 2 levels of Sequence that happens. Will try to debug myself, although I find jsii quite magically confusing :)

@jsteinich
Copy link
Collaborator

I suspect this may be related to aws/jsii#1919. Could you try explicitly specifying type names where the properties are being omitted?

@madeddie
Copy link
Author

@jsteinich yeah, replacing the boot_disk definition with

boot_disk=[ComputeInstanceBootDisk(
    initialize_params=[ComputeInstanceBootDiskInitializeParams(
        image="debian-cloud/debian-9"
    )]
)],

fixes it.
terraform output then looks like expected:

        "boot_disk": [
          {
            "initialize_params": [
              {
                "image": "debian-cloud/debian-9"
              }
            ]
          }
        ],

@madeddie
Copy link
Author

I guess this should be closed since it's an issue with jsii

@jsteinich
Copy link
Collaborator

I guess this should be closed since it's an issue with jsii

Likely, but we might be able to adjust the intermediate typescript code in a way that generates the working python code.

@danieldreier
Copy link
Contributor

I've removed this from the 0.7 milestone because that release is super full. I'm hoping we can revisit it in 0.8.

@schersh schersh removed this from the 0.10 (tentative) milestone Jan 27, 2022
@xiehan xiehan added the bug/has-workaround A bug with a workaround (may not be elegant) label Nov 22, 2022
@xiehan xiehan added help wanted Community contributions welcome as the core team is unlikely to work on this soon priority/backlog Low priority (though possibly still important). Unlikely to be worked on within the next 6 months. needs-reproduction and removed priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. labels Jun 1, 2023
@DanielMSchmidt
Copy link
Contributor

This seems to be fixed, I tried it in 0.20.1, convert gave me

from constructs import Construct
#
# Provider bindings are generated by running `cdktf get`.
# See https://cdk.tf/provider-generation for more details.
#
from imports.google.compute_instance import ComputeInstance
class MyConvertedCode(Construct):
    def __init__(self, scope, name):
        super().__init__(scope, name)
        ComputeInstance(self, "vm_instance",
            boot_disk={
                "initialize_params": {
                    "image": "debian-cloud/debian-9"
                }
            },
            machine_type="f1-micro",
            name="terraform-instance",
            network_interface=[{
                "access_config": [{}],
                "network": "default"
            }
            ]
        )

I added the provider definition and ran synth and got

{
  "resource": {
    "google_compute_instance": {
      "vm_instance": {
        "//": {
          "metadata": {
            "path": "tmp.678jvplfay/vm_instance",
            "uniqueId": "vm_instance"
          }
        },
        "boot_disk": {
          "initialize_params": {
            "image": "debian-cloud/debian-9"
          }
        },
        "machine_type": "f1-micro",
        "name": "terraform-instance",
        "network_interface": [
          {
            "network": "default"
          }
        ]
      }
    }
  }
}

Which seems correct to me :)

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 Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/has-workaround A bug with a workaround (may not be elegant) bug Something isn't working help wanted Community contributions welcome as the core team is unlikely to work on this soon needs-reproduction priority/backlog Low priority (though possibly still important). Unlikely to be worked on within the next 6 months. provider get / generation upstream/jsii Pending upstream work on JSII
Projects
None yet
Development

No branches or pull requests

7 participants