Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdktf: Cannot suppress undeclared variables warning without making a bad refactor #3537

Open
1 task
AlastairMiller opened this issue Mar 4, 2024 · 0 comments
Labels
bug Something isn't working new Un-triaged issue

Comments

@AlastairMiller
Copy link

AlastairMiller commented Mar 4, 2024

Expected Behavior

I have an cdktf app with multiple environments and providers. The native terraform way to inject these values is by using a .tfvars file. Currently all values are stored in a single file as a single point of truth. This causes variable values that are not consumed in that stack to be flagged as undeclared.

The compact warning flag also appears to not decrease the verboseness of the warnings either?

another-example-prod-stack  ╷
                            │ Warning: Value for undeclared variable
                            │ 
                            │ The root module does not declare a variable named "DEV_EXAMPLE_VARIABLE"
                            │ but a value was found in file
                            │ "/cdktf-undeclared-var-bug-replication/terraform.tfvars".
                            │ If you meant to use this value, add a "variable" block to the
                            │ configuration.
                            │ 
                            │ To silence these warnings, use TF_VAR_... environment variables to provide
                            │ certain "global" settings to all configurations in your organization. To
                            │ reduce the verbosity of these warnings, use the -compact-warnings option.
                            ╵
                            ╷
                            │ Warning: Value for undeclared variable
                            │ 
                            │ The root module does not declare a variable named "PROD_EXAMPLE_VARIABLE"
                            │ but a value was found in file
                            │ "./cdktf-undeclared-var-bug-replication/terraform.tfvars".
                            │ If you meant to use this value, add a "variable" block to the
                            │ configuration.
                            │ 
                            │ To silence these warnings, use TF_VAR_... environment variables to provide
                            │ certain "global" settings to all configurations in your organization. To
                            │ reduce the verbosity of these warnings, use the -compact-warnings option.
                            ╵
                            ╷
                            │ Warning: Values for undeclared variables
                            │ 
                            │ In addition to the other similar warnings shown, 1 other variable(s)
                            │ defined without being declared.
                            ╵

Actual Behavior

There seems to be no way to suppress this warning even using the HCL approach of explicitly defining the variables in a .tf file. This feel like an anti-pattern in CDK TF as well, as I am declaring the variables in ts.

Steps to Reproduce

I have created a minimal replication. https://github.com/AlastairMiller/cdktf-undeclared-var-bug-replication

Versions

language: typescript
cdktf-cli: 0.20.4
node: v20.11.0
cdktf: 0.20.4
constructs: 10.3.0
jsii: null
terraform: 1.7.4

Providers

N/A

Gist

No response

Possible Solutions

I assume using TF_VAR_ environment variables would resolve this, but AFAIK there is no elegant implementation in Multiplatform scenarios. I think this would involve running a prescript which would suitable permissions to set environment variables.

Using a .tfvars file per stack I suspect would also satisfy the error. Again this is not elegant as some secrets are not environment dependent so would be duplicated between files. Also not sure how scalable this is considering a stack per provider and environment.

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

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
@AlastairMiller AlastairMiller added bug Something isn't working new Un-triaged issue labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Un-triaged issue
Projects
None yet
Development

No branches or pull requests

1 participant