Contents


A resource is any infrastructure object you want to create and manage with Terraform, including virtual networks, compute instances, or higher-level components such as DNS records. The kinds of resources you can create depend on the providers you install. Providers are plugins that offer a collection of resource types that you can provision on a single cloud or on-premises infrastructure platform.


Destroying Resources

You can use the following methods to destroy resources that you no longer need:

  • Remove a resource from the configuration. When you apply the configuration, Terraform compares the configuration with the existing state and instructs the cloud provider to destroy the real infrastructure resource that no longer exists in the configuration.
  • Use the terraform destroy command to destroy all resources, or use the -target flag to destroy specific resources.
  • Replace the resource configuration with a removed block and add a destroy-time provisioner to perform additional operations, such as printing custom messages, when Terraform destroys the resource.

Resource Block

resource "<TYPE>" "<LABEL>" {
  # ...
}

You must set the following arguments for every resource block:

  • TYPE — Specifies the type of resource to create. You can declare either a resource type determined by the provider or the built-in terraform_data resource type, which stores values and triggers Terraform operations without creating actual infrastructure.
  • LABEL — Specifies a name for the resource. Terraform uses this label to track the resource in your state file. The label does not affect settings on the actual infrastructure resource.