Hi
I need to update one ec2 instance. The flow I’m trying to implement is getting one instance using “aws_instance” data source, destoying it and creating another one with different ami,type or whatever I want and then attaching the volumes I have in the older one. The question is, how can I destroy one instance, without using terraform destroy on the console. The code I have until now is this.
data "aws_ami" "latest_ubuntu_ami" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"]
}
data "aws_instance" "get_specific_instance" {
filter {
name = "tag:Name"
values = ["Application"]
}
}
module "update_instance" {
source = "../modules/ec2"
ami_id = data.aws_instance.get_specific_instance.ami
instance_type = data.aws_instance.get_specific_instance.instance_type
availability_zoneEc2 = data.aws_instance.get_specific_instance.availability_zone
}
resource "aws_instance" "destroy" {
#Don't know how to implement
}