Skip to content

Latest commit

 

History

History
43 lines (27 loc) · 1.67 KB

README.md

File metadata and controls

43 lines (27 loc) · 1.67 KB

terraform-terraform-nested-maps

Youtube Video

A small Terraform module to build a nested map to use withfor_each resource declarations.

I wanted to condence 100+ lines of remote data sources to pull in resources, and I wanted to utilize the new for_each feature.

This could easily go in one file and not be a module, but this allows me to use the same method for things like vpc_peering_connections.

I wanted to use this module method because it now gives me really neat names like aws_security_group.this['cms-dev']. This makes it pretty easy to move and refactor these as they still have the same name:

tf plan > plan.tfplan
cat plan.tfplan | grep "destroyed" # creates output like `data.aws_security_group.cms-dev`
cat plan.tfplan | grep "created" # creates output like `data.aws_security_group.this["cms-dev"]`

You can then take the above grep'd output and paste it into a Text Editor and match up the names for easy state move commands.

Requirements

No requirements.

Providers

No provider.

Inputs

Name Description Type Default Required
map A map of resource names and element names map(string) n/a yes
replace A map of information for string replacement
map(object({
string_find = string
string_replace = map(string)
}))
n/a yes

Outputs

Name Description
map A map to use in a for_each loop