Hi,
I’m tried to create a EC2 from snapshot, but I don’t attach the new volume to new vm via terraform script.
data "aws_ebs_volume" "prod_volume" {
most_recent = true
filter {
name = "volume-id"
values = ["vol-xxxxxxxxxxxx"]
}
}
resource "aws_ebs_snapshot" "production_snapshot" {
volume_id = "${data.aws_ebs_volume.prod_volume.id}"
}
resource "aws_ebs_volume" "from_production_snapshot" {
availability_zone = "us-east-1a"
snapshot_id = "${aws_ebs_snapshot.production_snapshot.id}"
size = 40
}
resource "aws_instance" "non_production" {
ami = "ami-0b898040803850657"
availability_zone = "us-east-1a"
instance_type = "t2.micro"
key_name = "mykey"
vpc_security_group_ids = [ "sg-xxxxxx","sg-xxxxxxrr" ]
tags = {
Name = "MyNew-Server"
Server = "MyNew-Server"
}
}
resource "aws_volume_attachment" "non_production" {
device_name = "/dev/xvda"
volume_id = "${aws_ebs_volume.from_production_snapshot.id}"
instance_id = "${aws_instance.non_production.id}"
}