Bootstrap FreeKB - Terraform - Destroy resources using the terraform apply command
Terraform - Destroy resources using the terraform apply command

Updated:   |  Terraform articles

The terraform apply command is typically issued after the terraform plan command to create or update or delete resources.

Let's say you have the following files on your Terraform server.

├── main.tf (root module)
├── data.tf
├── locals.tf
├── outputs.tf
├── providers.tf
├── terraform.tfstate
├── variables.tf
├── child (directory)
│   ├── main.tf (child module)
│   ├── data.tf
│   ├── outputs.tf
│   ├── resources.tf

 

Perhaps you are using Terraform to create/update/destory your Amazon Web Services (AWS) Virtual Private Clouds (VPC). Check out my article on Amazon Web Services (AWS) Getting Started with Terraform. Here is an example of what the terraform apply command may return. In this example, Terraform would create a Virtual Private Cloud.

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.modules.aws_vpc.my-vpc will be created
  + resource "aws_vpc" "my-vpc" {
      + arn                                  = (known after apply)
      + cidr_block                           = "10.0.0.0/16"
      + default_network_acl_id               = (known after apply)
      + default_route_table_id               = (known after apply)
      + default_security_group_id            = (known after apply)
      + dhcp_options_id                      = (known after apply)
      + enable_classiclink                   = (known after apply)
      + enable_classiclink_dns_support       = (known after apply)
      + enable_dns_hostnames                 = (known after apply)
      + enable_dns_support                   = true
      + id                                   = (known after apply)
      + instance_tenancy                     = "default"
      + ipv6_association_id                  = (known after apply)
      + ipv6_cidr_block                      = (known after apply)
      + ipv6_cidr_block_network_border_group = (known after apply)
      + main_route_table_id                  = (known after apply)
      + owner_id                             = (known after apply)
      + tags_all                             = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

 

The terraform plan -destroy command can be used to see what resources Terraform will try to destroy.

terraform plan -destroy

 

If you want to destroy resources, the terraform apply -destroy command can be used.

terraform apply -destroy

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1e33a5 in the box below so that we can be sure you are a human.