Skip to content
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

Allow multiple instance expansion syntax when instance count is 1 #115

Closed
gaffneyc opened this issue Jul 30, 2014 · 4 comments
Closed

Allow multiple instance expansion syntax when instance count is 1 #115

gaffneyc opened this issue Jul 30, 2014 · 4 comments
Labels

Comments

@gaffneyc
Copy link

Using the example config below setting up an ELB in front of a set of servers (in this case just 1). Trying to use the splat or expanded syntax (e.g. ${aws_instance.web.*.id}) when count is 1 fails with an error but works fine if count >= 2.

The use case is to have a staging environment with just a single server and scaling that up in production. If we want to have just one instance we need to change the syntax we use depending on the environment or count.

Terraform should allow using the same syntax regardless of what the count it.

resource "aws_elb" "balancer" {
  name = "balancer"

  listener {
    lb_port = 80
    instance_port = 80

    lb_protocol = "http"
    instance_protocol = "http"
  }

  instances = ["${aws_instance.web.*.id}"]
}

resource "aws_instance" "web" {
  ami = "ami-b227efda"
  instance_type = "t2.micro"
  count = 1
}

Running terraform plan errors with:
Error running plan: Resource 'aws_instance.web' does not have attribute 'id' for variable 'aws_instance.web.*.id'

@gaffneyc gaffneyc changed the title Allow multiple instance expansion syntax when and instance count is 1 Allow multiple instance expansion syntax when instance count is 1 Jul 30, 2014
@pearkes
Copy link
Contributor

pearkes commented Jul 30, 2014

Could you just specify count = 1 in your staging env? That should work, let me know if it doesn't.

One issue with treating everything as having multiple resources is you get situations like this (which are equally unintuitive):

${route_53_record.apex.0.value}

There's only ever one apex record, so indexing it feels cumbersome.

Let me know if that works for you!

@pearkes
Copy link
Contributor

pearkes commented Jul 30, 2014

Ah, sorry, misread part of your issue, count=1 should indeed work, re-opening and tagged as a bug.

@mitchellh
Copy link
Contributor

Fixed! Thanks.

@gaffneyc
Copy link
Author

gaffneyc commented Aug 5, 2014

Thanks! 🤘

@ghost ghost locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants