I am using cdktf for provisioning my resources using Python and Terraform. I want to automate this entire process and hence, asking for the "cdktf deploy" to be part of the python code, as below:
from constructs import Construct
from cdktf import App, TerraformStack
from imports.azurerm import AzurermProvider, ResourceGroup
import subprocess
class MyStack(TerraformStack):
def __init__(self, scope: Construct, ns: str):
super().__init__(scope, ns)
# define resources here
loca="West Europe"
rg_name="example-rg1"
tag = {
"ENV": "Dev",
"PROJECT": "AZ_TF"
}
AzurermProvider(self, "Azurerm", \
features={}
)
example_rg = ResourceGroup(self, 'example-rg1', \
name=rg_name,
location = loca,
tags = tag
)
app = App()
name = "cdktf5"
MyStack(app, name)
app.synth()
subprocess.run(["cdktf", "deploy"])
However, this does not work as expected, with the following output:
⠼ synthesizing...
⠙ synthesizing...
⠇ synthesizing...
⠸ synthesizing...
⠇ synthesizing...
⠦ synthesizing...
Needless to say, the resources are not created.
Try subprocess.run(["cdktf", "deploy", "--skip-synth"]) instead of subprocess.run(["cdktf", "deploy"])