Terraform ebs音量

时间:2017-03-05 16:21:53

标签: terraform

我是terraform的新手,创建了3个ec2实例,并创建了6个ebs卷。我们如何将3个ebs卷附加到三个实例中的每一个?

The request sent by the client was syntactically incorrect

错误:

  • aws_volume_attachment.ebs_att#2:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#2:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#2 ::无效或未知密钥:卷
  • aws_volume_attachment.ebs_att#4:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#4:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#4 ::无效或未知密钥:卷
  • aws_volume_attachment.ebs_att#3:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#3:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#3 ::无效或未知密钥:卷
  • aws_volume_attachment.ebs_att#0:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#0:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#0 ::无效或未知密钥:卷
  • aws_volume_attachment.ebs_att#1:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#1:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#1 ::无效或未知密钥:卷
  • aws_volume_attachment.ebs_att#5:“volume_id”:未设置必填字段
  • aws_volume_attachment.ebs_att#5:“device_name”:未设置必填字段
  • aws_volume_attachment.ebs_att#5 ::无效或未知密钥:卷

2 个答案:

答案 0 :(得分:6)

注意:此方法将销毁并重新创建服务器。如果您不能接受,请使用'aws volume attachment' method

解决此问题的一种方法,以及如何解决它,是将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}"
}

我希望有帮助