question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can cdktf commands be executed inside python code?

See original GitHub issue

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

0.9.4

Affected Resource(s)

All azure resources in stack

Debug Output

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"])

Expected Behavior

The deploy command should run as it does from CLI

Actual Behavior

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Subhashini2610commented, Mar 30, 2022

@rahulgoud19 I have already implemented such a thing, except it is a primitive way to define this. For example, if I want to get the stack outputs and store it to a variable, it would not be so easy. But definitely, this helps!

0reactions
github-actions[bot]commented, Nov 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLI Commands - CDK for Terraform - HashiCorp Developer
You can now autocomplete cdktf commands by pressing the <TAB> key. ... and converts it to CDK for Terraform content in imported.ts python...
Read more >
Use Your Preferred Programming Language with CDKTF
HashiCorp Terraform now supports writing configurations in HCL or your choice of C#, Python, TypeScript, Java, or Go with Cloud Development ...
Read more >
cdktf-local-exec - PyPI
This is useful to run build steps within your CDKTF Program or to run a ... can be used in a remote execution...
Read more >
CDK for Terraform (CDKTF) on AWS: How to Configure an S3 ...
In this section, we will learn how to use CDKTF CLI commands to ... Run code . on the terminal to open the...
Read more >
Terraform CDK Databricks Provider
The CDKTF is a third-party, infrastructure as code (IaC) platform that ... Run the following commands in your terminal or with PowerShell:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found