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_appautoscaling_target update detaches any aws_appautoscaling_policy's #8484

Closed
charlesbjohnson opened this issue Aug 25, 2016 · 6 comments

Comments

@charlesbjohnson
Copy link

Hi there,

Updating an aws_appautoscaling_target (which always forces a new resource) does not trigger dependent aws_appautoscaling_policys to be recreated. As a result, updating min_capacity or max_capacity causes all dependent aws_appautoscaling_policys to be deleted/detached, requiring a subsequent terraform apply to reattach them.

Terraform Version

v0.7.0+

Affected Resource(s)

  • aws_appautoscaling_target
  • aws_appautoscaling_policy

Terraform Configuration Files

provider "aws" {
  region = "us-west-2"
}

resource "aws_ecs_cluster" "cluster" {
  name = "demo-85e6a168597c3fe593b335df4c11496afe5dea31"
}

resource "aws_ecs_service" "service" {
  name = "${aws_ecs_cluster.cluster.name}"
  cluster = "${aws_ecs_cluster.cluster.id}"
  task_definition = "${aws_ecs_task_definition.task_definition.arn}"
  desired_count = 1
}

resource "aws_ecs_task_definition" "task_definition" {
  family = "nginx"
  container_definitions = <<EOF
[
  {
    "name": "nginx",
    "image": "nginx:latest",
    "cpu": 10,
    "memory": 500,
    "essential": true
  }
]
EOF
}

resource "aws_appautoscaling_target" "target" {
  name = "${aws_ecs_cluster.cluster.name}"
  service_namespace = "ecs"
  resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.service.name}"
  scalable_dimension = "ecs:service:DesiredCount"
  role_arn = "arn:aws:iam::428324370204:role/ecsAutoscaleRole"
  min_capacity = 1
  max_capacity = 2
}

resource "aws_appautoscaling_policy" "policy" {
  name = "${aws_appautoscaling_target.target.name}"
  resource_id = "service/${aws_ecs_cluster.cluster.name}/${aws_ecs_service.service.name}"
  adjustment_type = "ChangeInCapacity"
  cooldown = 300
  metric_aggregation_type = "Average"
  step_adjustment {
    metric_interval_lower_bound = 0
    scaling_adjustment = 1
  }
}

Expected Behavior

The aws_appautoscaling_target would be updated and the aws_appautoscaling_policy would still be attached.

Actual Behavior

The aws_appautoscaling_target was deleted and re-created, but the aws_appautoscaling_policy was lost in the process. A subsequent terraform apply will add it back, but it either should not have been removed or it should also have been recreated along with the aws_appautoscaling_target.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. change aws_appautoscaling_target.target.max_capacity to 3
  3. terraform apply (causes the policy detachment)
  4. terraform apply (reattaches the policy)

Important Factoids

According to the AWS docs, the aws_appautoscaling_target can be created as well as updated via RegisterScalableTarget. Perhaps this could be used instead of recreating the aws_appautoscaling_target on update.

@redroot
Copy link

redroot commented Oct 4, 2016

I just experienced this as well, +1

@mats16
Copy link

mats16 commented Nov 30, 2016

I also encountered this issue with v0.7.13

@yesteph
Copy link

yesteph commented Dec 16, 2016

Same issue with v0.8.1

@maxblaze
Copy link

maxblaze commented Mar 8, 2017

We're seeing the same issue in v0.8.8.

@maxblaze
Copy link

maxblaze commented Jun 5, 2017

Any update on this issue? This is still happening in v0.9.6 and is really critical for us.

@ghost
Copy link

ghost commented Apr 10, 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 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants