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

intermittent issue with aws_appautoscaling_target and aws_appautoscaling_policy creation #10737

Closed
brikis98 opened this issue Dec 14, 2016 · 3 comments

Comments

@brikis98
Copy link
Contributor

Terraform Version

Terraform v0.7.7

Affected Resource(s)

  • aws_appautoscaling_target
  • aws_appautoscaling_policy

Terraform Configuration Files

resource "aws_appautoscaling_target" "target" {
  name = "MyService"
  resource_id = "service/MyCluster/MyService"
  role_arn = "${aws_iam_role.role.arn}"
  min_capacity = 1
  max_capacity = 10
}

resource "aws_appautoscaling_policy" "scale_out" {
  name = "MyServiceScaleOut"
  resource_id = "service/MyCluster/MyService"

  adjustment_type = "ChangeInCapacity"
  cooldown = 60
  metric_aggregation_type = "Average"

  step_adjustment {
    metric_interval_lower_bound = 0
    scaling_adjustment = 1
  }

  depends_on = ["aws_appautoscaling_target.target"]
}

Expected Behavior

The auto scaling policy and target are both created successfully.

Actual Behavior

Intermittently, you get an error like this:

Error putting scaling policy: ObjectNotFoundException: No scalable target registered for service namespace: ecs (... sorry, I forgot to copy/paste the rest of the error ...)

If you re-run terraform apply, the error usually goes away.

Steps to Reproduce

  1. terraform apply

Important Factoids

If you re-run terraform apply, sometimes multiple times, it works. I suspect this is a classic issue with the fact that AWS is asynchronous and eventually consistent and Terraform is not properly waiting for the aws_appautoscaling_target resource to be created.

@yesteph
Copy link

yesteph commented Dec 16, 2016

Hello,

No problem with 0.7.13 and the following declarations:

resource "aws_appautoscaling_target" "scale_tgt" {
  name = "${var.env_prefix}-mlk-ms-brand-scale-tgt"
  service_namespace = "ecs"
  resource_id = "service/${var.cluster_name}/${aws_ecs_service.mlk_ms_brand.name}"
  scalable_dimension = "ecs:service:DesiredCount"
  role_arn = "${var.ecs_autoscale_role}"
  min_capacity = 1
  max_capacity = "${lookup(var.autoscaling_max_size, var.env_prefix, "1")}"

  depends_on = ["aws_ecs_service.mlk_ms_brand"]
}

resource "aws_appautoscaling_policy" "scale_in" {
  name = "${aws_ecs_service.mlk_ms_brand.name}-scale-in"
  service_namespace = "ecs"
  resource_id = "service/${var.cluster_name}/${aws_ecs_service.mlk_ms_brand.name}"
  scalable_dimension = "ecs:service:DesiredCount"

  adjustment_type = "ChangeInCapacity"
  cooldown = 60
  metric_aggregation_type = "Average"

  step_adjustment {
    metric_interval_upper_bound = 0
    scaling_adjustment = -2
  }

  depends_on = ["aws_appautoscaling_target.scale_tgt"]
}

@brikis98
Copy link
Contributor Author

It's an intermittent problem, so it won't always happen.

FWIW, as most timing issues with Terraform and AWS, it may make a difference where you're located. When I saw the error above, I was in the US, but deploying to the eu-central-1 data center, which would increase replication lag.

@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

4 participants