Terraform Azure & Python

I am new to terraform
I am trying to manage my Azure resources using terraform

I want to use python
I see this example

However, I am stuck on where I can find and install the python libraries mentioned in this example

from imports.azurerm.provider import AzurermProvider
from imports.azurerm.resource_group import ResourceGroup
from imports.azurerm.virtual_network import VirtualNetwork

Hi @shiva.gopalakrishnan :wave:

Those are generated using cdktf get (based on what’s specified in the cdktf.json config).

This docs page explains this and also explains pre-built providers, which you also could use: Providers - CDK for Terraform | Terraform | HashiCorp Developer

– Ansgar

Thank you Ansgar

I have done this however my code has issues with the imports I have indicated


There is another way to import the providers, I prefer using Poetry to manage dependencies so my cdktf.json does not have any providers, the list is empty, in my pyproject.toml I have this:

python = "^3.10"
cdktf = "^0.16"
cdktf-cdktf-provider-azuread = "^7"
cdktf-cdktf-provider-azurerm = "^7"
cdktf-cdktf-provider-helm = "^6"
cdktf-cdktf-provider-kubernetes = "^6"
cdktf-cdktf-provider-random = "^7"
cdktf-cdktf-provider-time = "^6"

and to import the modules I do this, for example:

from cdktf import AzurermBackend, Fn, TerraformStack, TerraformVariable, TerraformOutput
from cdktf_cdktf_provider_azuread.provider import AzureadProvider
from cdktf_cdktf_provider_azurerm.data_azurerm_kubernetes_cluster import DataAzurermKubernetesCluster
from cdktf_cdktf_provider_azurerm.provider import AzurermProvider
from cdktf_cdktf_provider_helm.provider import HelmProvider, HelmProviderKubernetes, HelmProviderKubernetesExec
from cdktf_cdktf_provider_kubernetes.provider import KubernetesProvider, KubernetesProviderExec
from cdktf_cdktf_provider_random.provider import RandomProvider
from cdktf_cdktf_provider_time.provider import TimeProvider
from constructs import Construct