-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Feature Request: Explode object properties into module options #32184
Comments
Hi @marceloboeira! Thanks for sharing this feature request. In today's Terraform we see folks solve this problem by passing all of the "common" items together in a single input variable: variable "common" {
type = object({
region = string
environment = string
network = object({
# ...
})
authentication = object({
# ...
})
monitoring = object({
# ...
})
})
} module "redis" {
source = "../../../modules/redis/cluster"
common = local.defaults
name = "foo"
} This structure has the advantage of still allowing Terraform to statically validate the contents of Would passing some sort of "common object" to your modules work to address your problem, or is there an additional detail that makes that design not viable for your situation? Thanks! |
Hi ! Glad I'm not the only one with such a use case. I've faced your exact situation before. I just created all the code for a python lambda. I would like to use this lambda through a custom tf module that creates the lambda function, some of its environment variables, the role it is using etc... My custom module uses the official Terraform lambda module behind the scene.
Now I still want my custom module to be flexible and users to be able to pass any argument to my custom module that is not overwritten and forward it to the official lambda module. The only way I can reach my goal right now would be to manually list all the existing parameters in the official module in my custom module and forward them one by one. For now, my custom module is something around the lines of:
I wish I could tell terraform: here are my forced values, and I would accept and forward any other parameter here to be used in this object.
Then anytime someone using my module passes through a parameter with undeclared key name, it would be interpreted as a parameter for this resource. I am clueless about the layers under this and maybe what I am requesting is way out of Terraform capabilities but I feel like my use case might not be that unusual. |
Terraform Version
Use Cases
As companies grow/environments grow, it is relevant to create generic modules to orchestrate end-to-end provisioning of multiple parts of the infrastructure. However, those modules tend to evolve to have many parameters and, most importantly, NOT to make assumptions about the underlying environment, being flexible in accepting different cloud-platforms accounts, environments, network configuration, security, monitoring, and so on...
Once you create a local setup folder/module for a specific environment, most infra pieces under that folder will likely share the same region/environment/network setup, making it easier for non-platform contributors to have that "default" setup available simply.
Attempted Solutions
For instance, we've created our internal setup with something like the following:
locals.tf
Then, we have hundreds of modules using those defaults, but they need to do that line by line:
Proposal
Allow exploding object properties from a shared object:
the
local.defaults&
would have the same effect as:References
No response
The text was updated successfully, but these errors were encountered: