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

provider/aws: Add top-level ELB Attachment resource #3999

Closed
phinze opened this issue Nov 20, 2015 · 5 comments · Fixed by #6879
Closed

provider/aws: Add top-level ELB Attachment resource #3999

phinze opened this issue Nov 20, 2015 · 5 comments · Fixed by #6879

Comments

@phinze
Copy link
Contributor

phinze commented Nov 20, 2015

Based on an ML discussion:

https://groups.google.com/d/msgid/terraform-tool/e9ef8081-db96-4329-9b62-adf8c0b40c81%40googlegroups.com

It seems like it might be worth splitting out instance <-> ELB attachments as their own resource, in the way that we've done in several other scenarios now.

The use case from the thread is the desire to be able to create an ELB w/ instances and to have provisioners on the instances reference details about the ELB. You can't do that today w/o a cycle because the only way to attach instances to an ELB is via the instances parameter on aws_elb.

If we had a top level attachment resource you could do something like this:

# ==> Proposed config, does not work today <==

variable "count" { default = 3 }

resource "aws_elb" "app" {
  # no instances field specified
}

resource "aws_instance" "app" {
  count = "${var.count}"
  # ... provisioners here, reference ELB normally
}

# New proposed resource:
resource "aws_elb_attachment" "app" {
  count    = "${var.count}"
  elb      = "${aws_elb.app.id}"
  instance = "${element(aws_instance.app.*.id, count.index)}"
}
@mberhault
Copy link

@phinze: thanks for filing this, that would definitely solve my problem. From the way ELBs are configured, it should also be fairly straightforward as creation and instance-registration are different steps.

@lvjp
Copy link
Contributor

lvjp commented Nov 22, 2015

I have the same problem when i want to run my configuration with Amazon recommended rules

@amochtar
Copy link

amochtar commented Jan 4, 2016

We have a similar use case, but then with auto scaling groups in stead of instances. To add SSL certificates for new domains, we are adding new ELBs. These ELBs point to existing ASGs. The ASGs are generic infrastructure that are shared between applications, while the new ELBs are application specific.

We are currently trying to modularize our terraform codebase. We would like to create separate plans to create the ASGs and ELBs, where the ASGs are created before the ELBs exist. Currently this is not possible because the the ELBs have to be passed in the load_balancers parameter of the ASG.

An ELB attachment resource would help us out greatly, when it also could support ASGs.

@roderickrandolph
Copy link

To expand on @amochtar's use case, here's an example where aws_elb_attachment would be powerful in managing docker containers across an ASG of docker hosts. This allows one to associate containers with an ELB (for port mapping) while also giving them the ability to destroy the containers and ELB without destroying the underlying docker hosts (which may have other unrelated containers running with their own independent ELB). I also threw wait_for_elb_capacity argument in there as an added bonus 😉

# proposal

resource "aws_autoscaling_group" "docker_hosts" {
    # no load_balancers field specified
}

resource "docker_image" "app" {
    count = "${var.count}"
    name  = "nginx"
    lifecycle {
        create_before_destroy = true
    }
}

resource "docker_container" "app" {
    count = "${var.count}"
    image = "${docker_image.app}"
    ports {
        external = "${var.container_port}"
        internal = "80"
    }
    lifecycle {
        create_before_destroy = true
    }
}

resource "aws_elb" "app" {
    depends_on = ["docker_container.app"]
    listener {
        lb_port     = "80"
        lb_protocol = "http"

        instance_port     = "${var.container_port}"
        instance_protocol = "http"
    }
    # no instances field specified
}

resource "aws_elb_attachment" "app" {
    elb = "${aws_elb.app.id}"
    autoscaling_group = "${aws_autoscaling_group.docker_hosts.id}"
    wait_for_elb_capacity = 1
}

jbardin added a commit that referenced this issue Jun 7, 2016
Add top-level ELB Attachment resource
jbardin added a commit that referenced this issue Jun 7, 2016
add sidebar link for elb_attachment
@ghost
Copy link

ghost commented Apr 18, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

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

Successfully merging a pull request may close this issue.

5 participants