重新绘制标题,如何不是必须猜测EC2附加的卷/设备的名称在生成的 aws_instance
's user_data
中?也就是说,如何将不是 被迫具有附加的 enacted_device_actual_name
在Terraform locals
中的变量?
这是相关的Terraform配置:
locals {
attached_device_name = "/dev/sdf" # Used in `aws_volume_attachment`.
attached_device_actual_name = "/dev/nvme1n1" # Used in `templatefile`.
}
resource "aws_instance" "foo" {
user_data = templatefile("./user-data.sh.tpl", {
attached_device_name = local.attached_device_actual_name
})
}
resource "aws_volume_attachment" "foo" {
device_name = local.attached_device_name
instance_id = aws_instance.foo.id
}
说
使用NVME设备名称(/dev/dev/nvme [0-26] N1
),您为块设备映射中指定的NVME EBS卷指定的设备名称。
上述零件“设备名称[...]被更名为“
”也暗示一个人应该 not 使用这些,保留/dev/nvme .. 。
名称?确实,如果我将 local.attached_device_name
设置为/dev/dev/nvme1n1
,在这种情况下,这是“正确”的猜测,此错误会弹出:
错误:错误附加卷(vol-some_id)到实例(i-some_id),消息:“参数设备的值(/dev/nvme1n1)无效。/dev/nvme1n1不是有效的ebs设备名称。” ,代码:“ InvalidParameTervalue”
“/dev/nvme1n1不是有效的EBS设备名称。”
目标是使 user_data
与附件 - 卷的名称同步,然后能够等待卷:
DEVICE="${attached_device_name}"
while [ ! -e "$${DEVICE}" ] ; do
echo "Waiting for $DEVICE ..."
sleep 1
done
env:env:
Terraform 1.1.2
hashicorp/aws 4.10.0
Rephrasing the title, how to not have to guess the EC2 attached volume/device's name in generated aws_instance
's user_data
? That is, how to not be forced to have an additional attached_device_actual_name
variable in below Terraform locals
?
Here's the relevant Terraform configuration:
locals {
attached_device_name = "/dev/sdf" # Used in `aws_volume_attachment`.
attached_device_actual_name = "/dev/nvme1n1" # Used in `templatefile`.
}
resource "aws_instance" "foo" {
user_data = templatefile("./user-data.sh.tpl", {
attached_device_name = local.attached_device_actual_name
})
}
resource "aws_volume_attachment" "foo" {
device_name = local.attached_device_name
instance_id = aws_instance.foo.id
}
The docs say
The device names that you specify for NVMe EBS volumes in a block device mapping are renamed using NVMe device names (/dev/nvme[0-26]n1
).
Does the above-quoted part "device names [...] are renamed"
also imply that one should not use these, reserved /dev/nvme...
names? Indeed, if I set local.attached_device_name
to /dev/nvme1n1
, which is a "correct" guess in this case, this error pops up:
Error: Error attaching volume (vol-some_id) to instance (i-some_id), message: "Value (/dev/nvme1n1) for parameter device is invalid. /dev/nvme1n1 is not a valid EBS device name.", code: "InvalidParameterValue"
"/dev/nvme1n1 is not a valid EBS device name."
The goal was to have user_data
synced with the attached-volume's name and then be able to wait for the volume:
DEVICE="${attached_device_name}"
while [ ! -e "${DEVICE}" ] ; do
echo "Waiting for $DEVICE ..."
sleep 1
done
Env:
Terraform 1.1.2
hashicorp/aws 4.10.0
发布评论