My Terraform resource file looks like this :
resource "aws_instance" "ubuntu14" {
instance_type = "t2.medium"
ami = "${lookup(var.aws_amis_ubuntu14,var.aws_region)}"
tags {
Name = "${var.user_label} - Ubuntu 14 - Fresh Agent Install - ${count.index}"
}
key_name = "${var.aws_key_name}"
vpc_security_group_ids = ["${lookup(var.security_group_id,var.aws_region)}"]
count = "${var.count}"
....
I already have a machine running and do not want to destroy it .
How do i achieve that in terraform apply?
Terraform plan shows the following : Plan: 2 to add, 0 to change, 1 to destroy.
I want to keep all 3
Unfortunately you'll have to take the information out of your state file. You can do this by hand (tedious and not recommended) or you can use Terraform state rm.
See documentation at: https://www.terraform.io/docs/commands/state/rm.html
I already have a machine running and do not want to destroy it
There are two ways to interpret this statement:
Depending on which of these statements is true, you need to take different actions:
You can use the Terraform import command to allow Terraform to manage this existing instance. Look up the existing instance's ID in the EC2 console and run the following command:
terraform import aws_instance.ubuntu14 <YOUR_INSTANCE_ID>
Now, when you run terraform plan
, the only changes will be any differences in the code versus what's actually running.
For most changes to an EC2 Instance, such as changing the AMI ID, user data, or IAM role, Terraform will destroy the old Instance and deploy a new one. There is no way to update those parameters "in place" with Terraform, as AWS itself doesn't let you update them!
Therefore, you have a few options:
apt-get install
to add some new dependency), SSH to the Instance and make your updates on it directly. Alternatively, you could use a configuration management tool such as Chef, Puppet, or Ansible to manage all of that for you.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With