terraform-cdk
terraform-cdk copied to clipboard
Support for CLI variables
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
Add CLI args: -var foo=bar and -var-file=foo to be passed to Terraform.
For commands that wrap Terraform, such as cdktf deploy, it would be nice to be able to pass in variables at runtime.
For instance, you might want to deploy a new container to Fargate/ECS/EKS and pass in something like app_version=1.0.
While it's good to have native support to generate native Terraform variables, I see the use-case for these more in the direction of generating hybrid modules and perhaps when using Terraform CDK as some sort of template generator. However, both use-cases are not in the focus at the moment.
Terraform variables are not a primary objective for Terraform CDK workflows. If you're using the cdktf cli to orchestrate your Terraform workflows, there are plenty of other ways to configure your stacks dynamically already:
- ENV
- Custom configuration files
- Remote calls (e.g. APIs)
I do agree that it'd be good to have a way to provide custom arguments to the cdktf cli. However, I would think more of something like Context to address this need.
For instance, you might want to deploy a new container to Fargate/ECS/EKS and pass in something like
app_version=1.0.
How about APP_VERSION=1.0 cdktf deploy?
I agree that for fresh projects Terraform variables don't really seem like the best use of cdktf; however, I think they could be useful in migrating existing Terraform workflows into cdktf. This would allow easy separation of hcl -> typescript/python/etc and the configuration values used. Maybe it's a mute point since running cdktf will already be a change, but worth considering.
Yeah, Iām using ENV vars and Yaml input files now. That is good enough for me.
@cmclaughlin how did you get this to work? do you have a sample code I can use? I am having similar requirement
I ended up using environment variables.
I think it is already possible to set Terraform variables via environment variables (TF_VAR_app_version=0.1 cdktf deploy). A quick win here would be to document this in our docs ā however, we should also figure out what we want to recommend in which case (e.g. environment variables accessed in synth vs. Terraform variables).
Is there any intention of adding this to the vars files? Just trying to plan how we should approach this and also if it would be welcomed if we did a PR to add it?
Is there any intention of adding this to the vars files? Just trying to plan how we should approach this and also if it would be welcomed if we did a PR to add it?
This comes up often enough (recently https://github.com/hashicorp/terraform-cdk/issues/734), that it seems worthwhile to come up with a proposal and evaluate more fully. Even though falling back to direct Terraform execution is always a possibility, it is a disruption.
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.