Note:
#terraform destroy all the resources
terraform destroy
#terraform destroy with -target flag allows us to destroy the specific resource.
terraform destroy -target "Resource Type "."Local Resource Name"
terraform destroy -target aws_instance.HelloWorld
Lab - terraform destroy all the resources
Command output:
PS D:\Blog\Terraform> terraform destroyaws_instance.HelloWorld: Refreshing state... [id=i-0dd6a2401c2e2f4f7]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:- destroyTerraform will perform the following actions:# aws_instance.HelloWorld will be destroyed- resource "aws_instance" "HelloWorld" {- ami = "ami-0c802847a7dd848c0" -> null- arn = "arn:aws:ec2:ap-southeast-1:998644643692:instance/i-0dd6a2401c2e2f4f7" -> null- associate_public_ip_address = true -> null- availability_zone = "ap-southeast-1a" -> null- cpu_core_count = 1 -> null- cpu_threads_per_core = 1 -> null- disable_api_termination = false -> null- ebs_optimized = false -> null- get_password_data = false -> null- hibernation = false -> null- id = "i-0dd6a2401c2e2f4f7" -> null- instance_initiated_shutdown_behavior = "stop" -> null- instance_state = "running" -> null- instance_type = "t2.micro" -> null- ipv6_address_count = 0 -> null- ipv6_addresses = [] -> null- monitoring = false -> null- primary_network_interface_id = "eni-07f115ec41905d38f" -> null- private_dns = "ip-172-31-27-33.ap-southeast-1.compute.internal" -> null- private_ip = "172.31.27.33" -> null- public_dns = "ec2-52-221-199-252.ap-southeast-1.compute.amazonaws.com" -> null- public_ip = "52.221.199.252" -> null- secondary_private_ips = [] -> null- security_groups = [- "default",] -> null- source_dest_check = true -> null- subnet_id = "subnet-0ecb7ab115595e77b" -> null- tags = {- "Name" = "HelloWorld"} -> null- tags_all = {- "Name" = "HelloWorld"} -> null- tenancy = "default" -> null- user_data_replace_on_change = false -> null- vpc_security_group_ids = [- "sg-0fb90cd269c2f142d",] -> null- capacity_reservation_specification {- capacity_reservation_preference = "open" -> null}- credit_specification {- cpu_credits = "standard" -> null}- enclave_options {- enabled = false -> null}- maintenance_options {- auto_recovery = "default" -> null}- metadata_options {- http_endpoint = "enabled" -> null- http_put_response_hop_limit = 1 -> null- root_block_device {- delete_on_termination = true -> null- device_name = "/dev/xvda" -> null- encrypted = false -> null- iops = 100 -> null- tags = {} -> null- throughput = 0 -> null- volume_id = "vol-08ca079f31b0ab5b5" -> nullPlan: 0 to add, 0 to change, 1 to destroy.Do you really want to destroy all resources?Terraform will destroy all your managed infrastructure, as shown above.There is no undo. Only 'yes' will be accepted to confirm.Enter a value: noDestroy cancelled.PS D:\Blog\Terraform>PS D:\Blog\Terraform>
Lab - terraform destroy with -target flag allows us to destroy the specific resource.
PS D:\Blog\Terraform> terraform destroy -target aws_instance.HelloWorldaws_instance.HelloWorld: Refreshing state... [id=i-0dd6a2401c2e2f4f7]Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:- destroyTerraform will perform the following actions:# aws_instance.HelloWorld will be destroyed- resource "aws_instance" "HelloWorld" {- ami = "ami-0c802847a7dd848c0" -> null- arn = "arn:aws:ec2:ap-southeast-1:998644643692:instance/i-0dd6a2401c2e2f4f7" -> null- associate_public_ip_address = true -> null- availability_zone = "ap-southeast-1a" -> null- cpu_core_count = 1 -> null- cpu_threads_per_core = 1 -> null- disable_api_termination = false -> null- ebs_optimized = false -> null- get_password_data = false -> null- hibernation = false -> null- id = "i-0dd6a2401c2e2f4f7" -> null- instance_initiated_shutdown_behavior = "stop" -> null- instance_state = "running" -> null- instance_type = "t2.micro" -> null- ipv6_address_count = 0 -> null- ipv6_addresses = [] -> null- monitoring = false -> null- primary_network_interface_id = "eni-07f115ec41905d38f" -> null- private_dns = "ip-172-31-27-33.ap-southeast-1.compute.internal" -> null- private_ip = "172.31.27.33" -> null- public_dns = "ec2-52-221-199-252.ap-southeast-1.compute.amazonaws.com" -> null- public_ip = "52.221.199.252" -> null- secondary_private_ips = [] -> null- security_groups = [- "default",] -> null- source_dest_check = true -> null- subnet_id = "subnet-0ecb7ab115595e77b" -> null- tags = {- "Name" = "HelloWorld"} -> null- tags_all = {- "Name" = "HelloWorld"} -> null- tenancy = "default" -> null- user_data_replace_on_change = false -> null- vpc_security_group_ids = [- "sg-0fb90cd269c2f142d",] -> null- capacity_reservation_specification {- capacity_reservation_preference = "open" -> null}- credit_specification {- cpu_credits = "standard" -> null}- enclave_options {- enabled = false -> null}- maintenance_options {- auto_recovery = "default" -> null}- metadata_options {- http_endpoint = "enabled" -> null- http_put_response_hop_limit = 1 -> null- http_tokens = "optional" -> null- instance_metadata_tags = "disabled" -> null}- root_block_device {- delete_on_termination = true -> null- device_name = "/dev/xvda" -> null- encrypted = false -> null- iops = 100 -> null- tags = {} -> null- throughput = 0 -> null- volume_id = "vol-08ca079f31b0ab5b5" -> null- volume_size = 8 -> null- volume_type = "gp2" -> null}}Plan: 0 to add, 0 to change, 1 to destroy.╷│ Warning: Resource targeting is in effect││ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.Do you really want to destroy all resources?Terraform will destroy all your managed infrastructure, as shown above.There is no undo. Only 'yes' will be accepted to confirm.Enter a value: yesaws_instance.HelloWorld: Destroying... [id=i-0dd6a2401c2e2f4f7]aws_instance.HelloWorld: Still destroying... [id=i-0dd6a2401c2e2f4f7, 10s elapsed]aws_instance.HelloWorld: Still destroying... [id=i-0dd6a2401c2e2f4f7, 20s elapsed]aws_instance.HelloWorld: Destruction complete after 30s╷│ Warning: Applied changes may be incomplete││ The plan was created with the -target option in effect, so some changes requested in the configuration may have been ignored and the output values may not be fully updated. Run the following command to verify that no other│ changes are pending:│ terraform plan││ Note that the -target option is not suitable for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an error│ message.╵Destroy complete! Resources: 1 destroyed.PS D:\Blog\Terraform>PS D:\Blog\Terraform>
Reference:
1. Terraform Command: destroy
2. Destroy Infrastructure - AWS
3. Terraform Note 01 - Destroy
最初發表 / 最後更新: 2022.07.03 / 2022.07.03
0 comments:
張貼留言