1

我想将我的 EBS 快照从一个区域复制到另一个区域。但是在过滤快照 ID 时,它会返回名为 1411205605 的 ID,但我希望它返回类似:snap-.....。

这是我的代码:

data "aws_ebs_snapshot_ids" "ebs_volumes" {

  filter {
    name   = "tag:Name"
    values = ["EBS1_snapshot"]
  }

  filter {
    name   = "volume-size"
    values = ["2"]
  }
}

output "ebs_snapshot_ids"{
    value = ["${data.aws_ebs_snapshot_ids.ebs_volumes.ids}"]
}


resource "aws_ebs_snapshot_copy" "example_copy" {
  source_snapshot_id = "${data.aws_ebs_snapshot_ids.ebs_volumes.id}"
  source_region      = "ap-southeast-1"

  tags {
    Name = "aaa_copy_snap"
  }

}

运行 terraform apply 时的输出是:

aws_ebs_snapshot_copy.example_copy:InvalidParameterValue:参数 snapshotId 的值 (1411205605) 无效。预期:'snap-...'。状态码:400,请求 ID:bd577049-8b4e-45bc-8415-59e22b4d26d5

我不知道我在哪里犯错了。我该如何解决这个问题?

4

1 回答 1

1

这是因为“数据源:aws_ebs_snapshot_ids”返回一个属性“ids” ,该属性设置为 EBS 快照 ID 列表,按创建时间降序排列。

Now in your case it is safe to assume that "ids" contains a single snapshot id since you are using name as a filter. Hence change the code as shown below to retrieve that id.

source_snapshot_id = "${data.aws_ebs_snapshot_ids.ebs_volumes.ids.0}"

The "0" used here is to retrieve the 1st element from the list of ids. In your case it's the only element.

于 2018-11-04T10:00:03.087 回答