Changing and Destroying a Resource – Terraform

Changing a Resource

Sometimes we might need to make some changes to our resources. In that case, we just need to make changes to our terraform configuration file.

  • We can also make some changes to our instance by simply changing the configuration.
  • Terraform is declarative, i.e., we don’t need to tell terraform how to move from one state to another. It finds out itself.

In our case, we are changing our instance from Ubuntu to some other. For that, we are changing the AMI code in the terra.tf file like below

Changes done in configuration file (terra.tf in our case) :

Now if we will run and see Terraform plan, what we will find out :

Now, let’s implement this change by terraform apply command and see what will happen with our compute instance :

Before applying the changes :

After applying the changes :

Destroying a Resource

To destroy resource which you have created you just need to run terraform destroy command :

Check AWS console and you’ll see changes being implemented :

Leave a Reply

Your email address will not be published. Required fields are marked *