Friday, September 22, 2023
HomeSoftware EngineeringHow one can Delete a Particular Useful resource in Terraform

How one can Delete a Particular Useful resource in Terraform


Working terraform destroy will tear down the entire stack related to some terraform code.

Nevertheless, generally you would possibly solely need to take away a particular piece of your infrastructure.

To do that, you need to use the terraform destroy -target object.

Step 1 – Record the State

Get a listing of all of the sources from the state:

terraform state record

#information.aws_ami.webserver_ami
#aws_autoscaling_group.asg-web[0]
#random_string.rand3
#...

Step 2 – Take away a Particular Useful resource

Run a terraform destroy -target and move a useful resource from the state record above:

terraform destroy -target aws_autoscaling_group.asg-web[0] -auto-approve

We additionally added a -auto-approve within the above command to robotically delete the useful resource with out prompting us for affirmation.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments