0
votes

Actually i created EC2 Vm using terraform by count first time it got created while try to create another one for example if I gave count 2 it creates only one instance and if I gave count 1 it destroy the previous ones please help me regarding.

provider "aws"{

profile = "default"

region = var.region

}

resource "aws_instance" "hello" {

count=1

ami = var.ami

instance_type = "t2.micro"

tags = {

Name = "EC2 instance creation"

}

}

1

1 Answers

0
votes

Terraform creates resources using count based on their index. If you add or subtract from the count it is count to remove the resource at the index positions that were removed.

If you are creating VMs to be used for different purposes and they are not going to be identical in nature they should be created as a separate resource.