We are getting very strange issue while using count in conjunction with Module. Below code doesn’t instantiate the module even if both the variable values are matching, we tried to assign static value i.e. count = 1, but in that case as well we don’t see the module getting instantiated. Please suggest what could be the possible fix.
Is this that it is not appearing as a resource to add when running a plan or apply, or that it is not provisioning the resources in the module, or something else?
Can you share your output from a plan/apply and can you share a more complete example than above?
It does not get executed in plan/apply phases, resulting in no resource creation.
Not sure if there is any bug or any setting missing in TF package configuration
Without some further example of your Terraform code it is difficult to determine for sure. If you are able to most a minimum reproducible example and also the output of your plan command it may help.
However, two things immediately spring to mind:
You are running your terraform plan/apply from the incorrect folder/directory which contains no terraform files and therefore is treating it as an empty module with nothing to deploy.
or
At some point you have already applied/deployed this successfully and the module/resources are in your state. Therefore, as Terraform determines there are no changes (or at least changes relevant to the module/resources in question) it will not show the module in a plan or apply (Outside of during the state refresh progress lines). Perhaps run a terraform state list to see if the module/resources are already in your state.
Official Terraform 1.8.5 Repo via JARaaS Hybrid RAG - Documentation - code current 6/17/2024
Note: Sources at the end of the response
It appears that you are facing an issue with the conditional instantiation of a module using the count parameter in Terraform. This issue might stem from the way Terraform evaluates the condition and handles the count argument. Here are some potential reasons and fixes for the problem you are experiencing:
Potential Issues:
Variable Definition: Ensure that var.xyz and var.abc are correctly defined and have the expected values.
Parentheses Usage: Sometimes, Terraform might require explicit grouping using parentheses for condition expressions.
Terraform Version: Compatibility issues might arise from different versions of Terraform. Ensure you are using a version that supports this syntax.
Solution Suggestions:
Check Variable Definitions: Ensure that var.xyz and var.abc are defined and their values are what you expect.
variable "xyz" {
description = "A description for xyz"
type = string
}
variable "abc" {
description = "A description for abc"
type = string
}
Using Parentheses: Try adding parentheses around the condition in the count argument.