Reputation: 131
Ex: I have created custom module in terraform
main.tf
resource "xyz" "abc" {
name = var.settings[name]
type = var.settings[type]
}
variable.tf
variable "settings" {
type = map(any)
description = "Default variables"
default = {
name = "test"
type = "instance"
}
I am accessing this module and want to override the default values while accessing module
module "xyz" {
source ="../../xyz"
name = "google" // want to override this default value
type = "cloud" //want to override this default value
}
please help how to override the map variable defined on module level
Upvotes: 1
Views: 3081
Reputation: 4837
You pass it in as a map as well, i.e.:
module "xyz" {
source ="../../xyz"
settings = {
name = "google"
type = "cloud"
}
}
Note that your main.tf
in the module is missing ""
:
resource "xyz" "abc" {
name = var.settings["name"]
type = var.settings["type"]
}
And your variables.tf
in the module is missing a closing }
:
variable "settings" {
type = map(any)
description = "Default variables"
default = {
name = "test"
type = "instance"
}
}
Upvotes: 2