Home > database >  Dynamodb Autoscaling terraform import
Dynamodb Autoscaling terraform import

Time:12-11

I have created dynamodb autoscaling out of terraform and I want to import this to terraform. But it says the object does not exists. I used the similar command for other terraform and it worked. But for this , it says autoscaling doesnt exists. No issues with the read and write target. Able to import.

Command:

terraform import aws_appautoscaling_policy.dynamodb_table_read_policy dynamodb/table/Table_v3/dynamodb:table:ReadCapacityUnits/DynamoDBReadCapacityUtilization:table/Table_v3

Terraform Code:

resource "aws_appautoscaling_target" "dynamodb_table_read_target" {
  max_capacity       = var.read_max_capacity
  min_capacity       = var.read_min_capacity
  resource_id        = "table/${var.table_name}"
  scalable_dimension = "dynamodb:table:ReadCapacityUnits"
  service_namespace  = "dynamodb"
}

resource "aws_appautoscaling_policy" "dynamodb_table_read_policy" {
  name               = "DynamoDBReadCapacityUtilization:${aws_appautoscaling_target.dynamodb_table_read_target.resource_id}"
  policy_type        = "TargetTrackingScaling"
  resource_id        = aws_appautoscaling_target.dynamodb_table_read_target.resource_id
  scalable_dimension = aws_appautoscaling_target.dynamodb_table_read_target.scalable_dimension
  service_namespace  = aws_appautoscaling_target.dynamodb_table_read_target.service_namespace

  target_tracking_scaling_policy_configuration {
    predefined_metric_specification {
      predefined_metric_type = "DynamoDBReadCapacityUtilization"
    }

    target_value = var.read_target_util
  }
}

Error:

aws_appautoscaling_policy.dynamodb_table_read_policy: Importing from ID "dynamodb/table/Table_v3/dynamodb:table:ReadCapacityUnits/DynamoDBReadCapacityUtilization:table/Table_v3"... aws_appautoscaling_policy.dynamodb_table_read_policy: Import prepared! Prepared aws_appautoscaling_policy for import aws_appautoscaling_policy.dynamodb_table_read_policy: Refreshing state... [id=DynamoDBReadCapacityUtilization:table/Table_v3] ╷ │ Error: Cannot import non-existent remote object │ │ While attempting to import an existing object to "aws_appautoscaling_policy.dynamodb_table_read_policy", the provider detected that no object exists with the │ given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to │ create a new remote object for this resource.

CodePudding user response:

Your PolicyName (i.e. DynamoDBReadCapacityUtilization:table/Table_v3) looks strange. Sadly, since you haven't provide any information about how exactly you've created the scaling policy outside of TF, I would suggest running:

aws application-autoscaling describe-scaling-policies  --service-namespace dynamodb

and verifying the PolicyName.

  • Related