New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring Private IP Addresses on aws instance #861

Closed
changwuf31 opened this Issue Jan 24, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@changwuf31

changwuf31 commented Jan 24, 2015

Hi,

Suppose I configure aws_instance with count = 5,
how can I assign ip addresses on these instances ?

@knuckolls

This comment has been minimized.

Show comment
Hide comment
@knuckolls

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.

Contributor

knuckolls commented Jan 24, 2015

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.

@changwuf31

This comment has been minimized.

Show comment
Hide comment
@changwuf31

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:

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..

@phinze

This comment has been minimized.

Show comment
Hide comment
@phinze

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.

Member

phinze commented Jan 24, 2015

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.

phinze added a commit that referenced this issue Jan 25, 2015

@mitchellh mitchellh closed this in #862 Jan 25, 2015

yahyapo pushed a commit to yahyapo/terraform that referenced this issue Mar 13, 2015

@cnoffsin

This comment has been minimized.

Show comment
Hide comment
@cnoffsin

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:

private_ip = "${lookup(var.data_node_ips,count.index)}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment