2. Modify Resources

  • Terraform works in a declearative manner

  • If we re apply a terraform file, it is not going to re apply the config like some code

  • Like in previous example, if we applied that file multiple times, it was not going to deploy multiple ec2 machines each time we apply it

  • We can modify the config file and terraform will update the resource

  • Take the previous example and add a tag and apply the config, terraform will update the ec2 instance with the tag specified

#####################
# Modifying EC2 Instance Tag
#####################
resource "aws_instance" "my-first-server" {
    ami = "ami-052efd3df9dad4825"
    instance_type = "t2.micro"

    tags = {
        Name = "ubuntu"
    }
}

Last updated