我是terraform的新手,创建了3个ec2实例,并创建了6个ebs卷。我们如何将3个ebs卷附加到三个实例中的每一个?
The request sent by the client was syntactically incorrect
错误:
答案 0 :(得分:6)
解决此问题的一种方法,以及如何解决它,是将ebs卷直接附加到实例资源。
您可以通过添加' ebs_block_device'来实现此目的。每个服务器配置的元素,然后运行terraform apply
。例如,您希望添加2个ebs块设备的每个服务器资源看起来像:
resource "aws_instance""example_instance"{
#INSTANCE CONFIGURATION VALUES
ebs_block_device{
device_name = "/dev/sdf"
volume_size = 500
volume_type = "st1"
}
ebs_block_device{
device_name = "/dev/sdg"
volume_size = 500
volume_type = "st1"
}
}
然后运行terraform plan
,看看块设备是否会添加到服务器和服务器中。使用此方法,服务器将被破坏和重新启动。如果这是可接受的,请运行terraform apply
以使用其他卷重建服务器。
Check out the documentation around ebs_block_device and aws_instance here.
答案 1 :(得分:1)
我会用这种格式做点什么:
resource "aws_instance" "example" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
}
resource "aws_ebs_volume" "ebs-volume-1" {
availability_zone = "eu-west-1a"
size = 500
type = "st1"
tags {
Name = "more volume"
}
}
resource "aws_ebs_volume" "ebs-volume-2" {
availability_zone = "eu-west-1a"
size = 500
type = "st1"
tags {
Name = "more volume"
}
}
resource "aws_volume_attachment" "ebs-volume-1-attachment" {
device_name = "/dev/sdf"
volume_id = "${aws_ebs_volume.ebs-volume-1.id}"
instance_id = "${aws_instance.example.id}"
}
resource "aws_volume_attachment" "ebs-volume-2-attachment" {
device_name = "/dev/sdg"
volume_id = "${aws_ebs_volume.ebs-volume-2.id}"
instance_id = "${aws_instance.example.id}"
}
我希望有帮助