-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
don't validate a resource block when there is a static count = 0
#36776
Comments
Using a static I feel like there is a duplicate of this somewhere, but likely quite old. The edge case of statically writing |
count = 0
The real config is a bit more complex. I just simplified it here. The block depends on the configuration and looks like:
Where |
I think that shows why it's not possible to skip in general, which is why I assumed that we could reduce this to |
I tried different solution here without success. The idea was to move all these configuration files into separate module and disable it. Unfortunately this does not work. I expected that TF just skip TF files at the disabled module, but TF unfortunately still process them. Here is minimized part of configuration: locals {
enable_cdn = local.cluster.domain.cdn_ssl_domains == ""
}
module "cdn" {
count = local.enable_cdn ? 1 : 0
source = "./modules/cdn"
project_name = local.project_name
}
module "dns" {
source = "./modules/dns"
...
cloudfront_domain = local.enable_cdn ? module.cdn[0].cloudfront_domain : {}
} The errors I faced:
and for files inside module:
This error happens when
It seems TF during static checks do some dynamic processing. Here we can see that TF sees that value is "". Thus configuration was read and thus configuration analysis is not completely static. Expected result:
|
That is still the same fundamental issue, expansion is not handled during validation. Adding a module exposes a slightly different version of the situation though, because modules themselves are not a single entity within Terraform, they are really just a namespace for the resources they contain, so the configuration for the resources exists regardless of whether the module itself is expanded. |
Terraform Version
Terraform Configuration Files
Debug Output
Expected Behavior
When
count = 0
all checks for the resource should be disabled, because it will not be created.Actual Behavior
TF tries to verify parameters even if resource was disabled.
Steps to Reproduce
Additional Context
Even more it is not clear not to disable for_each which refers that disabled resource:
I can not use
count=0
withfor_each
:And If
count=0
forfor_each
is removed then I receive the next error:References
No response
Generative AI / LLM assisted development?
No response
The text was updated successfully, but these errors were encountered: