Patch for_each loop through template variable.
The for_each loop that builds multiple resources now correctly sets values for each resource. Previously we did not descend into each object.
This commit is contained in:
parent
c6efa83224
commit
dfb31a3d74
@ -7,25 +7,26 @@ module "ec2_ssh_key" {
|
||||
}
|
||||
|
||||
module "standalone_ec2" {
|
||||
for_each = var.ec2_template[*]
|
||||
# Create a new list for each ec2_template object
|
||||
for_each = { for idx, val in var.ec2_template : idx => val }
|
||||
source = "terraform-aws-modules/ec2-instance/aws"
|
||||
|
||||
name = each.value["hostname"]
|
||||
ami = each.value["ami"]
|
||||
name = each.value.hostname
|
||||
ami = each.value.ami
|
||||
|
||||
instance_type = each.value["family"]
|
||||
instance_type = each.value.family
|
||||
key_name = module.ec2_ssh_key.key_pair_name
|
||||
monitoring = true
|
||||
|
||||
vpc_security_group_ids = [module.ec2_rdp_sg.security_group_id]
|
||||
subnet_id = each.value["subnet"]
|
||||
subnet_id = each.value.subnet
|
||||
|
||||
root_block_device = [
|
||||
{
|
||||
volume_size = each.value["disksize"]
|
||||
volume_size = each.value.disksize
|
||||
encrypted = true
|
||||
}
|
||||
]
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
module "db_psql" {
|
||||
source = "terraform-aws-modules/rds/aws"
|
||||
for_each = var.db_template[*]
|
||||
identifier = each.value["name"]
|
||||
for_each = { for idx, val in var.db_template : idx => val }
|
||||
identifier = each.value.name
|
||||
|
||||
engine = each.value["engine"]
|
||||
engine_version = each.value["engine_version"]
|
||||
instance_class = each.value["family"]
|
||||
engine = each.value.engine
|
||||
engine_version = each.value.engine_version
|
||||
family = each.value.family
|
||||
instance_class = each.value.class
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ terraform {
|
||||
|
||||
provider "aws" {
|
||||
|
||||
region = var.region
|
||||
region = var.region
|
||||
|
||||
|
||||
# Configure Terraform to plan
|
||||
|
@ -35,10 +35,11 @@ ec2_template = [
|
||||
|
||||
db_template = [
|
||||
{
|
||||
name = "RDS1"
|
||||
name = "rds1"
|
||||
engine = "postgres"
|
||||
engine_version = 11
|
||||
family = "db.t3.micro"
|
||||
class = "db.t3.micro"
|
||||
family = "postgres"
|
||||
subnet = "10.1.5.0/24"
|
||||
}
|
||||
]
|
||||
@ -52,4 +53,4 @@ tags = {
|
||||
open_to_internet = "true"
|
||||
builder = "terraform"
|
||||
project = "coalfire-3tier"
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ variable "db_template" {
|
||||
name = string
|
||||
engine = string
|
||||
engine_version = number
|
||||
class = string
|
||||
family = string
|
||||
subnet = string
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user