terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Reduce/document differences between cdktf synth and running app directly

Open jsteinich opened this issue 3 years ago • 7 comments

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

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:

  • 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.
  • Terraform Cloud automation. There's quite a bit to make using Terraform Cloud easier. Probably best to just leave alone
  • #682 proposes adding hooks which would be cli only

References

jsteinich avatar Jun 24 '21 21:06 jsteinich

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:

  • Pulumi: CLI required, plus either running agent or state storage required
  • AWS CDK: CLI required, plus CloudFormation as deployment infrastructure required. Although, there's a similar discussion here: https://github.com/aws/aws-cdk-rfcs/issues/300

onitake avatar Jul 07 '21 12:07 onitake

  • 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.

skorfmann avatar Jul 17 '21 13:07 skorfmann

  • 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!

vitoravancini avatar Jan 07 '22 12:01 vitoravancini

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.

jsteinich avatar Jan 07 '22 14:01 jsteinich

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 avatar Feb 20 '23 10:02 kemalizing

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

kemalizing avatar Mar 02 '23 05:03 kemalizing

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.

shinebayar-g avatar Feb 14 '24 06:02 shinebayar-g