CDKTF Provider Random
raw JSON → 12.0.1 verified Fri May 01 auth: no python
Prebuilt Terraform CDK (CDKTF) provider for random resources (random_pet, random_string, random_password, etc.). Used to generate random values in infrastructure. Version 12.0.1 supports CDKTF >= 0.20.0. Breaking changes between major versions often mirror the upstream provider version bumps.
pip install cdktf-cdktf-provider-random Common errors
error ModuleNotFoundError: No module named 'cdktf_cdktf_provider_random' ↓
cause Package not installed or wrong import path.
fix
pip install cdktf-cdktf-provider-random (note hyphen vs underscore in package name).
error ImportError: cannot import name 'RandomPet' from 'cdktf_cdktf_provider_random' ↓
cause Attempting to import resource class from package root instead of submodule.
fix
from cdktf_cdktf_provider_random.pet import RandomPet
error TypeError: 'NoneType' object is not iterable ↓
cause Missing required 'keepers' argument in RandomPet or similar resource with required attributes.
fix
Provide all required arguments as per Terraform provider docs.
Warnings
breaking Version 12.0.0+ requires cdktf >= 0.20.0. Older cdktf versions are incompatible. ↓
fix Update cdktf to >=0.20.0, or pin cdktf-cdktf-provider-random to <12.0.0.
gotcha Resource classes (RandomPet, RandomString, etc.) are not exported from the package root. Importing directly from root will raise ModuleNotFoundError. ↓
fix Use correct import paths: from cdktf_cdktf_provider_random.pet import RandomPet
deprecated Some attributes like 'length' in RandomString require explicit type casting in Python due to Terraform type system. ↓
fix Use integer values directly: length=8 (not '8' string).
Imports
- RandomPet wrong
from cdktf_cdktf_provider_random import RandomPetcorrectfrom cdktf_cdktf_provider_random.pet import RandomPet - RandomString wrong
from cdktf_cdktf_provider_random import RandomStringcorrectfrom cdktf_cdktf_provider_random.string import RandomString - RandomPassword
from cdktf_cdktf_provider_random.password import RandomPassword
Quickstart
from cdktf import App, TerraformStack
from cdktf_cdktf_provider_random.pet import RandomPet
from constructs import Construct
class MyStack(TerraformStack):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
RandomPet(self, "pet", keepers={"key": "value"})
app = App()
MyStack(app, "random-pet-stack")
app.synth()