Dynamodb 自动缩放地形导入

Dynamodb Autoscaling terraform import

我已经从 terraform 中创建了 dynamodb autoscaling,我想将其导入到 terraform 中。但它说该对象不存在。我对其他 terraform 使用了类似的命令并且它有效。但是对于这个,它说自动缩放不存在。读写目标没有问题。可以导入。

命令:

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

地形代码:

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
  }
}

错误:

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.

您的 PolicyName(即 DynamoDBReadCapacityUtilization:table/Table_v3)看起来很奇怪。遗憾的是,由于您没有提供任何关于您在 TF 之外究竟如何创建缩放策略的信息,我建议 运行:

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

并验证 PolicyName