How to split values of a map and create lists?

888 views
Skip to first unread message

Anudeep Reddy

unread,
Jul 27, 2017, 8:27:48 PM7/27/17
to Terraform
Hello,

I have a map variable with many values (NACL rules). I am trying to add rules accordingly

    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" {
      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 "}" but found "["


Since maps with lists as values aren't supported, how do we split the values and iterate? 

Thanks

Lowe Schmidt

unread,
Jul 28, 2017, 9:19:16 AM7/28/17
to terrafo...@googlegroups.com
Wouldn't a list fit the problem better?

--
Lowe Schmidt | +46 723 867 157

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/3f4a60cd-11f4-44d9-9705-02a981856728%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Anudeep Reddy

unread,
Jul 28, 2017, 9:57:14 AM7/28/17
to Terraform
Hello Lowe,

I just wanted to name the keys after rules (what the rule is for)

Someone answered my question on stackoverflow.

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)}" 
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages