hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.8k stars 443 forks source link

Reduce/document differences between cdktf synth and running app directly #798

Open jsteinich opened 3 years ago

jsteinich commented 3 years ago

Community Note

Description

We should document the differences between cdktf synth vs running application directly and then eliminate differences where it makes sense. Starting list of differences:

References

onitake commented 3 years ago

For the use case of writing a cdktf script that generates Terraform code, it looks like the CLI is not needed. I haven't used feature flags so far, so the output from cdktf-cli and running scripts directly has been the same for me.

I'm processing the generated JSON with Terraform afterwards. cdktf still requires Terraform to do the grunt work too, so the added benefit is somewhat limited.

It's understandable that more advanced features, such as Terraform Cloud integration, wouldn't work, but I think it would make sense to support the basic use case described above as well.

Comparison with other IaC toolkits:

skorfmann commented 3 years ago
  • Feature flags aren't applied when running app directly. This impacts the naming of resources. I don't have a good reason for the discrepancy.

This just bit me hard and essentially destroyed an entire stack with lots of stuff requiring manual fixes now. That's really something we'll have to address.

vitoravancini commented 2 years ago
  • Feature flags aren't applied when running app directly. This impacts the naming of resources. I don't have a good reason for the discrepancy.

This just bit me hard and essentially destroyed an entire stack with lots of stuff requiring manual fixes now. That's really something we'll have to address.

Is there any workaround for this? I was developing my app using 'cdktf synth' and wrote quite a large infrasctructure with it, now i'm trying to run the app and I think i'm hitting the situation youre describing.

the modules names changed from: module.quero2pay-dataplatform-eks-eks-cluster.module.node_groups.aws_launch_template.workers["main"] to module.baseinfrastructurestack_quero2paydataplatformeksekscluster_F8C7987B.module.node_groups.aws_launch_template.workers["main"]

Not sure it's the same situation but it looks like it.

thank you!

jsteinich commented 2 years ago

Is there any workaround for this? I was developing my app using 'cdktf synth' and wrote quite a large infrasctructure with it, now i'm trying to run the app and I think i'm hitting the situation youre describing.

You could try setting the CDKTF_CONTEXT_JSON environment variable to a json string of your cdktf.json file.

kemalizing commented 1 year ago

hi, I'm hit by https://github.com/hashicorp/terraform-cdk/issues/2550 issue which looks like related to this one. Any news about this issue?

kemalizing commented 1 year ago

I saw a great work around for naming inconsistencies in another issue: https://github.com/hashicorp/terraform-cdk/issues/2341#issuecomment-1326760534

shinebayar-g commented 5 months ago

Hi. What are the actual differences of running the cdktf code directly vs using the cdktf cli? (Apart from the CLI flags ofc) I just did a quick comparison and I can't tell the difference. Both yarn run cdktf synth --app 'yarn run tsx main.ts' and yarn run tsx main.ts still generated the cdktf json files.