amazon-web-services - 将 EBS 快照从一个区域复制到另一个区域
问题描述
我想将我的 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
我不知道我在哪里犯错了。我该如何解决这个问题?
解决方案
这是因为“数据源: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.
推荐阅读
- maven - 在eclipse中工作时删除后创建.m2文件夹
- python - 是否可以通过使用 open3D 在网格表面上显示法线?
- python-3.x - 如何在 Python 3 中比较和可视化两个 .wav 文件?
- c# - 等待持续的 UI 后台轮询任务
- django - 无法在 Django Admin 套装中添加忘记密码链接?
- php - PhpSpreadsheet - 下载文件而不是保存它
- php - 如何打印用户键入的两个输入值之间的所有偶数。请仅在 php 中编写代码提示
- java - 无线路匹配接口 Clip 支持格式 PCM_SIGNED 未知采样率,16 位,立体声,4 字节/帧,支持 big-endian
- javascript - 如何使用角度获取数组中对象的索引?
- javascript - concat 后输出文件 main.min.js 的 Gulp4 问题