> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/devops/infrastructure-as-a-code-iac/terraform/2.-modify-resources.md).

# 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

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

    tags = {
        Name = "ubuntu"
    }
}
```
