Creating Security Group with CIDR Block with /32

412 views
Skip to first unread message

Cyber Corp

unread,
Jul 31, 2019, 3:43:42 AM7/31/19
to Terraform
Hello

I have two terraform resource: AWS EIP and AWS Security Group. I want that EIP should automatically be whitelisted in the security group.

Since I am using the 0.12 version of Terraform, I thought to avoid using ${..} approach and tried referencing follow in cidr_block with the latest configuration language, however, the following block gives an error:


Error: Invalid operand

  on reference.tf line 19, in resource "aws_security_group" "mysg":
  19:    cidr_blocks = [aws_eip.lb.public_ip/32]
    |----------------
    | aws_eip.lb.public_ip is "52.88.235.110"

Unsuitable value for left operand: a number is required.


resource "aws_eip" "lb" {
  vpc      
= true
}


resource
"aws_security_group" "mysg" {
   name
= "terraform-sg"


   ingress
{
   from_port  
= 443
   to_port    
= 443
   protocol    
= "tcp"
   cidr_blocks
= [aws_eip.lb.public_ip/32]

 
}


}

When I specify ["${aws_eip.lb.public_ip}/32"], it works perfectly but I want to know is using ${..} the right approach even with 0.12?


Andrew Jeffree

unread,
Jul 31, 2019, 3:49:18 AM7/31/19
to terrafo...@googlegroups.com
Using “${}” is correct in this case as you’re making it a string when you add the ‘/32’. Doing it the initial way you tried initially has it trying to treat it as a math operation at a guess.

--
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-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/0e16d377-67d1-4d42-84a4-20730e0e0c56%40googlegroups.com.

⁞ Fernando Miguel

unread,
Jul 31, 2019, 4:15:14 AM7/31/19
to terrafo...@googlegroups.com
You are interpolating a var and a string. 
So you still need to do it with ${} 

--
Fernando Miguel

Reply all
Reply to author
Forward
0 new messages