In this blog post, I will show you how to update a Terraform deployment in AWS.
If you remember, In the previous post, I created an EC2 instance using Terraform.
The objective now, is to add a name tag to the instance.
Before update
Below, you can see the code before the update, it is a simple code that create an instance.
# Provider configuration provider "aws" { region = "ap-southeast-2" } # Resource configuration resource "aws_instance" "CentOSEC2" { ami = "ami-000a59677875221a3" instance_type = "t2.micro" key_name = "linuxec2" }
As you can see below, the instance has no name and I will fix it.
![](https://ntweekly-3e2e1f4957bdf35452c0-endpoint.azureedge.net/blobntweekly18036ad1fb/wp-content/uploads/2020/06/image-4.png)
Update Process
Below, is the updated code with and addition of a tags section.
The instance name will be CentOS VM.
# Provider configuration provider "aws" { region = "ap-southeast-2" } # Resource configuration resource "aws_instance" "CentOSEC2" { ami = "ami-000a59677875221a3" instance_type = "t2.micro" key_name = "linuxec2" tags = { Name = "CentOS VM" } }
Plan and Update
I will save my code and and test it using the following line.
terraform plan
![](https://ntweekly-3e2e1f4957bdf35452c0-endpoint.azureedge.net/blobntweekly18036ad1fb/wp-content/uploads/2020/06/image-6.png)
Update
To update the instance, I will run the apply command which will update the name of the instance.
terraform apply
![](https://ntweekly-3e2e1f4957bdf35452c0-endpoint.azureedge.net/blobntweekly18036ad1fb/wp-content/uploads/2020/06/image-5.png)
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.