Skip to content

Instantly share code, notes, and snippets.

@archmangler
Last active September 26, 2018 15:20
Show Gist options
  • Select an option

  • Save archmangler/cca6ade02409a02f540c3444d36e7148 to your computer and use it in GitHub Desktop.

Select an option

Save archmangler/cca6ade02409a02f540c3444d36e7148 to your computer and use it in GitHub Desktop.
terraform-fun-puzzles-and-problems

Terraform puzzles and problems

Problem #1

Statement:

  • Given a default map variable, how do we override individual values in the map when such individual values are defined?
  • Other than using "map merge" ?
  • E.g:

(default map)


variable "default_tags" {
	type = "map"
	default = {
		"tag1" ="Tag 1",
		"tag2" ="Tag 2",
		"tag3" ="Tag 3"
	}
}

(map to use if values defined)


variable "my_custom_tags" {
	type = "map"
	default = {
		"tag1" ="Tag A",
		"tag2" ="Tag B"
	}
}

Outcome:


the_tags="${var.my_custom_tags}"

Where essentially this results:

variable "the_tags" {
	type = "map"
	default = {
		"tag1" ="Tag A",    ... overridden
		"tag2" ="Tag B",	... overridden
		"tag3" = "Tag 3"	... retained
	}
}

Notes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment