我已编写了一些Terraform代码来创建一些服务器。对于AMI,我使用Terraform数据模块获取最新的Ubuntu 16.04映像ID,并将其分配给EC2实例。最近,我想在此环境中添加另一个EC2实例,但是当我运行
terraform plan
时,我可以看到Terraform试图删除现有的EC2实例并重新创建它们。原因是发布了新的Ubuntu镜像,正在尝试删除旧实例并创建具有新AMI ID的新实例。有没有可能解决这个问题,因为我不想意外删除我们的生产服务器?data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
module "jenkins" {
source = "terraform-aws-modules/ec2-instance/aws"
name = "Jenkins"
instance_count = 1
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.small"
associate_public_ip_address = true
disable_api_termination = true
key_name = "${aws_key_pair.ssh_key.key_name}"
monitoring = false
vpc_security_group_ids = "${module.jenkins_http_sg.this_security_group_id}", "${module.jenkins_https_sg.this_security_group_id}", "${module.ssh_sg.this_security_group_id}"]
subnet_id = "${module.vpc.public_subnets[0]}"
iam_instance_profile = "${aws_iam_instance_profile.update-dns-profile.name}"
tags = {
Terraform = "true"
}
}