CDKTF Google Provider

raw JSON →
16.12.1 verified Fri May 01 auth: no python

CDKTF (CDK for Terraform) prebuilt bindings for the Google Cloud Platform (GCP) provider. Version 16.12.1 targets Terraform provider google ~> 6.0. Released frequently, follows cdktf provider releases.

pip install cdktf-cdktf-provider-google
error ModuleNotFoundError: No module named 'cdktf_cdktf_provider_google'
cause Package not installed or imported incorrectly.
fix
Run pip install cdktf-cdktf-provider-google and import as from cdktf_cdktf_provider_google import google.
error AttributeError: module 'cdktf_cdktf_provider_google' has no attribute 'ComputeInstance'
cause Direct import of resource without submodule.
fix
Import from submodule: from cdktf_cdktf_provider_google.compute_instance import ComputeInstance.
error TypeError: __init__() takes at least 4 arguments (3 given)
cause Missing or wrong number of positional arguments; often missing construct `id`.
fix
Ensure the second argument is the construct ID string. Example: ComputeInstance(stack, 'my_instance', ...).
error Error: Unsupported attribute: "machineType"
cause Using camelCase property name instead of snake_case.
fix
Replace machineType with machine_type (and similarly for all properties).
error Error: Invalid provider configuration on main.tf.json line X: provider.google: missing required field 'project'
cause GoogleProvider not configured properly.
fix
Add GoogleProvider to stack with required fields: google.GoogleProvider(stack, 'google', project='...').
breaking Version 16.x drops support for Python 3.8 (requires ~=3.9).
fix Upgrade to Python 3.9+.
breaking Breaking changes between major provider versions (e.g., from 5.x to 6.x) reflect upstream Terraform provider changes. Always pin provider version and run `cdktf diff` after upgrades.
fix Check upstream Terraform google provider changelog and update resource configs accordingly.
gotcha Property names use snake_case in Python, not camelCase as in HCL. Common mistake: `machineType` instead of `machine_type`.
fix Use snake_case for all resource properties. Refer to CDKTF documentation for bindings.
gotcha Resource constructor expects `id` as second positional argument (the construct ID). Omitting it or reordering arguments causes cryptic errors.
fix Always provide `id` argument: `Resource(stack, 'id', ...)`.

Minimal stack creating a GCE instance and synthesizing Terraform JSON.

from cdktf import App, TerraformStack
from cdktf_cdktf_provider_google import google
from cdktf_cdktf_provider_google.compute_instance import ComputeInstance

app = App()
stack = TerraformStack(app, "quickstart")
google.GoogleProvider(stack, "provider", project="my-project", region="us-central1")
ComputeInstance(stack, "vm", name="test", machine_type="e2-micro", zone="us-central1-a", boot_disk={"initialize_params": {"image": "debian-cloud/debian-11"}}, network_interface=[{"network": "default"}])
app.synth()