dictionary - How to split values of a map in terraform to create lists? -


i have map variable many values (nacl rules). trying add rules accordingly

variable "rules" {   default = {     = "200,false,tcp,allow,0.0.0.0/0,23,23"     b = "100,true,tcp,allow,0.0.0.0/0,1024,65535"   } }   resource "aws_network_acl_rule" "bar" {   network_acl_id = "<id>"   rule_number    = "${split(",",element(values(var.rules),count.index))[0]}"   egress         = "${split(",",element(values(var.rules),count.index))[1]}"   protocol       = "${split(",",element(values(var.rules),count.index))[2]}"   rule_action    = "${split(",",element(values(var.rules),count.index))[3]}"   cidr_block     = "${split(",",element(values(var.rules),count.index))[4]}"   from_port      = "${split(",",element(values(var.rules),count.index))[5]}"   to_port        = "${split(",",element(values(var.rules),count.index))[6]}"   count          = "${length(values(var.rules))}" } 

error: expected "}" found "["

since maps lists values aren't supported, trying split values , iterate

here simpler way deal map rules

variable "rules" {   default = {    "0" = "200,false,tcp,allow,0.0.0.0/0,23,23"    "1" = "100,true,tcp,allow,0.0.0.0/0,1024,65535"   } }  resource "aws_vpc" "main" {   cidr_block = "10.0.0.0/16" }  resource "aws_network_acl" "bar" {   vpc_id = "${aws_vpc.main.id}" }  resource "aws_network_acl_rule" "bar" {   count          = "${length(var.rules)}"   network_acl_id = "${aws_network_acl.bar.id}"   rule_number    = "${element(split(",",var.rules[count.index]),0)}"   egress         = "${element(split(",",var.rules[count.index]),1)}"   protocol       = "${element(split(",",var.rules[count.index]),2)}"   rule_action    = "${element(split(",",var.rules[count.index]),3)}"   cidr_block     = "${element(split(",",var.rules[count.index]),4)}"   from_port      = "${element(split(",",var.rules[count.index]),5)}"   to_port        = "${element(split(",",var.rules[count.index]),6)}" } 

if insist use old map, key "a,b,...", need adjust resource

variable "rules" {   default = {     "a" = "200,false,tcp,allow,0.0.0.0/0,23,23"     "b" = "100,true,tcp,allow,0.0.0.0/0,1024,65535"   } }  resource "aws_network_acl_rule" "bar" {   count          = "${length(var.rules)}"   network_acl_id = "${aws_network_acl.bar.id}"   rule_number    = "${element(split(",",element(values(var.rules),count.index)),0)}"   egress         = "${element(split(",",element(values(var.rules),count.index)),1)}"   protocol       = "${element(split(",",element(values(var.rules),count.index)),2)}"   rule_action    = "${element(split(",",element(values(var.rules),count.index)),3)}"   cidr_block     = "${element(split(",",element(values(var.rules),count.index)),4)}"   from_port      = "${element(split(",",element(values(var.rules),count.index)),5)}"   to_port        = "${element(split(",",element(values(var.rules),count.index)),6)}" } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -