有人能告诉我如何自动装载使用Terraform创建的EBS卷并使其在/custom
上可用吗?
resource "aws_instance" "ec201" {
...
ebs_block_device {
device_name = "/dev/sdd"
volume_type = "gp2"
volume_size = 10
delete_on_termination = true
encrypted = true
}
...
可以自动安装吗?
我读过这些页面:
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
- 启动Amazon EC2 Linux实例时自动装载EBS卷
当我进行时
> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
...
nvme1n1 259:0 0 10G 0 disk
nvme0n1 259:1 0 250G 0 disk
└─nvme0n1p1 259:2 0 250G 0 part /
我有一个10GB的分区没有安装。可以用地形自动安装吗?
正如您所看到的,SO将nvme1n1
读取为设备名称(而不是/dev/sdd
(。
因此,您可以为您的EC2实例应用带有云初始化指令的user_data
:
resource "aws_instance" "your-instance" {
..
user_data = file("user_data/ebs-mount.sh")
..
}
其中user_data/ebs-mount.sh
具有下一个内容(考虑到EBS磁盘具有xfs格式(:
#cloud-config
hostname: your-instance
runcmd:
- sudo mkdir /custom -p
- sudo echo '/dev/nvme1n1 /custom xfs defaults 0 0' >> /etc/fstab
- sudo mount -a
output : { all : '| tee -a /var/log/cloud-init-output.log' }