Kiran Patil
Kiran Patil

Reputation: 131

how to override Map variable values defined on module level on terraform

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

Answers (1)

yvesonline
yvesonline

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

Related Questions