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

AWS AutoScaling Group health_check_type if always "EC2" even if you pass "ELB" #1259

Closed
rusllonrails opened this issue Mar 20, 2015 · 2 comments · Fixed by #1262
Closed

AWS AutoScaling Group health_check_type if always "EC2" even if you pass "ELB" #1259

rusllonrails opened this issue Mar 20, 2015 · 2 comments · Fixed by #1262

Comments

@rusllonrails
Copy link

Hey Guys

I got issue with setting health_check_type for AWS Auto-Scaling Group.
I use latest version of terraform from github.

$ terraform -v
Terraform v0.4.0-dev (dc4abb48fad02c4b93d1185599812af32b0e31fb)

My code:

# SECURITY GROUPS
# EC-2 instances access over SSH
resource "aws_security_group" "staging_web_security_group" {
  name = "StagingWebServerSG"
  description = "Allow SSH only from my IP

  # SSH access from my IP only
  ingress {
    from_port = 22
    to_port = 22
    protocol = "tcp"
    cidr_blocks = ["<MY IP>/32"]
  }
}

# EC-2 instances access over HTTP/ HTTPS from LB only
resource "aws_security_group" "staging_web_http_security_group" {
  name = "StagingWebServerHTTPSG"
  description = "Allow HTTP, HTTPS inbound traffic from LB only"

  # HTTP access from anywhere
  ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    security_groups = ["${aws_security_group.staging_lb_security_group.id}"]
  }

  # HTTPS access from anywhere
  ingress {
    from_port = 443
    to_port = 443
    protocol = "tcp"
    security_groups = ["${aws_security_group.staging_lb_security_group.id}"]
  }
}

# LOAD BALANCER security group with access over HTTP/ HTTPS
resource "aws_security_group" "staging_lb_security_group" {
  name = "StagingLoadBalancerSG"
  description = "Allow HTTP, HTTPS inbound traffic from anythere and allow all outbound traffic"

  # HTTP access from anywhere
  ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  # HTTPS access from anywhere
  ingress {
    from_port = 443
    to_port = 443
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

# LOAD BALANCER
resource "aws_elb" "staging_load_balancer" {
  name = "StagingLoadBalancer"

  availability_zones = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
  security_groups = ["${aws_security_group.staging_lb_security_group.id}"]
  cross_zone_load_balancing = true

  listener {
    instance_port = 80
    instance_protocol = "http"
    lb_port = 80
    lb_protocol = "http"
  }

  health_check {
    healthy_threshold = 10
    unhealthy_threshold = 2
    timeout = 5
    target = "HTTP:80/"
    interval = 30
  }
}

# Create Launch Configuration
resource "aws_launch_configuration" "staging_launch_configuration" {
  name = "staging_launch_configuration"
  image_id = "${var.aws_ami}"
  instance_type = "${var.ec2_instance_type}"
  security_groups = [
    "${aws_security_group.staging_web_security_group.name}",
    "${aws_security_group.staging_web_http_security_group.name}"
  ]

  key_name = "${var.key_name}"
}

#  Configure Auto Scaling group
resource "aws_autoscaling_group" "staging_autoscaling_group" {
  name = "staging_autoscaling_group"
  availability_zones = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
  max_size = 3
  min_size = 2
  health_check_grace_period = 300
  health_check_type = "ELB"
  desired_capacity = 2
  force_delete = true
  launch_configuration = "${aws_launch_configuration.staging_launch_configuration.id}"
  load_balancers = ["${aws_elb.staging_load_balancer.name}"]
}

Steps:

  1. terraform plan
+ aws_autoscaling_group.staging_autoscaling_group
    availability_zones.#:          "" => "3"
    availability_zones.1924028850: "" => "eu-west-1b"
    availability_zones.3953592328: "" => "eu-west-1a"
    availability_zones.94988580:   "" => "eu-west-1c"
    default_cooldown:              "" => "<computed>"
    desired_capacity:              "" => "2"
    force_delete:                  "" => "1"
    health_check_grace_period:     "" => "300"
    health_check_type:             "" => "ELB"
    launch_configuration:          "" => "staging_launch_configuration"
    load_balancers.#:              "" => "1"
    load_balancers.3065915641:     "" => "StagingLoadBalancer"
    max_size:                      "" => "3"
    min_size:                      "" => "2"
    name:                          "" => "staging_autoscaling_group"
    termination_policies.#:        "" => "<computed>"
    vpc_zone_identifier.#:         "" => "<computed>"
  1. terraform apply
aws_autoscaling_group.staging_autoscaling_group: Creating...
  availability_zones.#:          "" => "3"
  availability_zones.1924028850: "" => "eu-west-1b"
  availability_zones.3953592328: "" => "eu-west-1a"
  availability_zones.94988580:   "" => "eu-west-1c"
  default_cooldown:              "" => "<computed>"
  desired_capacity:              "" => "2"
  force_delete:                  "" => "1"
  health_check_grace_period:     "" => "300"
  health_check_type:             "" => "ELB"
  launch_configuration:          "" => "staging_launch_configuration"
  load_balancers.#:              "" => "1"
  load_balancers.3065915641:     "" => "StagingLoadBalancer"
  max_size:                      "" => "3"
  min_size:                      "" => "2"
  name:                          "" => "staging_autoscaling_group"
  termination_policies.#:        "" => "<computed>"
  vpc_zone_identifier.#:         "" => "<computed>"
aws_autoscaling_group.staging_autoscaling_group: Creation complete

Then I'm checking on AWS EC-2 console and see that "Health Check Type" is "EC2".

  1. Run terraform plan again:
-/+ aws_autoscaling_group.staging_autoscaling_group
    availability_zones.#:          "3" => "3"
    availability_zones.1924028850: "eu-west-1b" => "eu-west-1b"
    availability_zones.3953592328: "eu-west-1a" => "eu-west-1a"
    availability_zones.94988580:   "eu-west-1c" => "eu-west-1c"
    default_cooldown:              "300" => "<computed>"
    desired_capacity:              "2" => "2"
    force_delete:                  "true" => "1"
    health_check_grace_period:     "300" => "300"
    health_check_type:             "EC2" => "ELB" (forces new resource)
    launch_configuration:          "staging_launch_configuration" => "staging_launch_configuration"
    load_balancers.#:              "1" => "1"
    load_balancers.3065915641:     "StagingLoadBalancer" => "StagingLoadBalancer"
    max_size:                      "3" => "3"
    min_size:                      "2" => "2"
    name:                          "staging_autoscaling_group" => "staging_autoscaling_group"
    termination_policies.#:        "1" => "<computed>"
    vpc_zone_identifier.#:         "1" => "<computed>"

=> And see in plan that terraform going to change "Health Check Type":

health_check_type:             "EC2" => "ELB" (forces new resource)
  1. terraform apply again:
aws_autoscaling_group.staging_autoscaling_group: Creating...
  availability_zones.#:          "" => "3"
  availability_zones.1924028850: "" => "eu-west-1b"
  availability_zones.3953592328: "" => "eu-west-1a"
  availability_zones.94988580:   "" => "eu-west-1c"
  default_cooldown:              "" => "<computed>"
  desired_capacity:              "" => "2"
  force_delete:                  "" => "1"
  health_check_grace_period:     "" => "300"
  health_check_type:             "" => "ELB"
  launch_configuration:          "" => "staging_launch_configuration"
  load_balancers.#:              "" => "1"
  load_balancers.3065915641:     "" => "StagingLoadBalancer"
  max_size:                      "" => "3"
  min_size:                      "" => "2"
  name:                          "" => "staging_autoscaling_group"
  termination_policies.#:        "" => "<computed>"
  vpc_zone_identifier.#:         "" => "<computed>"
aws_autoscaling_group.staging_autoscaling_group: Error: 1 error(s) occurred:

* Error creating Autoscaling Group: AutoScalingGroup by this name already exists - A group with the name staging_autoscaling_group already exists and is pending delete.  Please wait until Autoscaling completes the deletion process before creating another group with the same name.
Error applying plan:

* Error creating Autoscaling Group: AutoScalingGroup by this name already exists - A group with the name staging_autoscaling_group already exists and is pending delete.  Please wait until Autoscaling completes the deletion process before creating another group with the same name.
  1. terraform apply again:
aws_autoscaling_group.staging_autoscaling_group: Creating...
  availability_zones.#:          "" => "3"
  availability_zones.1924028850: "" => "eu-west-1b"
  availability_zones.3953592328: "" => "eu-west-1a"
  availability_zones.94988580:   "" => "eu-west-1c"
  default_cooldown:              "" => "<computed>"
  desired_capacity:              "" => "2"
  force_delete:                  "" => "1"
  health_check_grace_period:     "" => "300"
  health_check_type:             "" => "ELB"
  launch_configuration:          "" => "staging_launch_configuration"
  load_balancers.#:              "" => "1"
  load_balancers.3065915641:     "" => "StagingLoadBalancer"
  max_size:                      "" => "3"
  min_size:                      "" => "2"
  name:                          "" => "staging_autoscaling_group"
  termination_policies.#:        "" => "<computed>"
  vpc_zone_identifier.#:         "" => "<computed>"
aws_autoscaling_group.staging_autoscaling_group: Creation complete

Checking in AWS EC-2 console again and still see "Health Check Type" = "EC2"

Thanks 🍻

@catsby
Copy link
Member

catsby commented Mar 20, 2015

This should be fixed in #1262

@ghost
Copy link

ghost commented May 4, 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 May 4, 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.

2 participants