Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upConfiguring Private IP Addresses on aws instance #861
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
knuckolls
Jan 24, 2015
Contributor
I have not personally done this, but I believe this is how something like that is meant to be done. You'll use a variable that has a map of values:
variable "ips" {
default = {
0 = "10.1.1.5"
1 = "10.1.1.6"
...
}
}
and then look them up via an interpolation function within your aws_instance provider:
resource "aws_instance" "example" {
...
count = 5
private_ip = "lookup(ips,count.index)"
...
}
The syntax above might not be exactly right, but it's close.
|
I have not personally done this, but I believe this is how something like that is meant to be done. You'll use a variable that has a map of values:
and then look them up via an interpolation function within your aws_instance provider:
The syntax above might not be exactly right, but it's close. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
changwuf31
Jan 24, 2015
@knuckolls: Thanks a lot! It works !!!
For the record, the correct syntax is like this:
variable "ips" {
default = {
"0" = "10.1.1.5"
"1" = "10.1.1.6"
...
}
}
And
resource "aws_instance" "example" {
...
count = 5
private_ip = "${lookup(ips,count.index)}"
...
}
Should I close this ? I think this should go to the docs though..
changwuf31
commented
Jan 24, 2015
|
@knuckolls: Thanks a lot! It works !!! For the record, the correct syntax is like this:
And
Should I close this ? I think this should go to the docs though.. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
phinze
Jan 24, 2015
Member
Glad you got this figured out!
I think this should go to the docs though..
Agreed. The pieces are mentioned under Interpolation Syntax and called out when describing count meta-parameter but it seems like the pattern is common enough to call out specifically somewhere.
|
Glad you got this figured out!
Agreed. The pieces are mentioned under Interpolation Syntax and called out when describing count meta-parameter but it seems like the pattern is common enough to call out specifically somewhere. |
added a commit
that referenced
this issue
Jan 25, 2015
phinze
referenced this issue
Jan 25, 2015
Merged
docs: add example of using variables with count #862
mitchellh
closed this
in
#862
Jan 25, 2015
pushed a commit
to yahyapo/terraform
that referenced
this issue
Mar 13, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
cnoffsin
Apr 13, 2017
I copied this code directly into my code and it didn't work and I realize this issue is 2 years old.
For someone who got here from google searching the syntax that does work here is:
private_ip = "${lookup(var.data_node_ips,count.index)}"
cnoffsin
commented
Apr 13, 2017
|
I copied this code directly into my code and it didn't work and I realize this issue is 2 years old. For someone who got here from google searching the syntax that does work here is:
|
changwuf31 commentedJan 24, 2015
Hi,
Suppose I configure aws_instance with count = 5,
how can I assign ip addresses on these instances ?