IBM Support

Removing a Resource from the Terraform State Using the "removed" block

How To


Steps

Introduction

This guide outlines how to remove a resource from the Terraform state file using the removed block, introduced in Terraform v1.7. When you delete a resource block from your configuration, Terraform's default behavior is to plan the destruction of the infrastructure. The removed block overrides this behavior, allowing you to remove a resource from Terraform’s state while ensuring the real infrastructure object remains intact.

After applying this change, the resource is no longer tracked by Terraform, but it is not deleted from your cloud environment.

Prerequisites

  • Terraform v1.7 or later.
  • A Terraform workflow, such as local CLI execution or a VCS-driven workflow in HCP Terraform or Terraform Enterprise.

Procedure

Follow these steps to remove a resource from the Terraform state without destroying it.

Step 1: Identify the Resource

First, identify the resource you want to remove from Terraform's management. Note the resource's full address as it appears in your configuration or state file (e.g., aws_instance.example).

Step 2: Update the Terraform Configuration

In your configuration file, remove the original resource block and replace it with a removed block. This block instructs Terraform to stop managing the resource without destroying it.

For example, to remove a resource with the address null_resource.null, you would use the following configuration.

removed {
  from = null_resource.null

  lifecycle {
    destroy = false
  }
}
  • from: Specifies the address of the resource you are removing from state.
  • lifecycle: This block is required and controls Terraform's behavior. The destroy = false argument ensures that the resource is removed from Terraform’s state but the actual infrastructure remains untouched.

Step 3: Apply the Configuration

Run the standard Terraform workflow to apply the configuration change and update the state file.

  1. Initialize your Terraform configuration.

    $ terraform init
  2. Create an execution plan to preview the changes.

    $ terraform plan

    The output shows that the resource will no longer be managed by Terraform but will not be destroyed.

    Terraform will perform the following actions:
    
    # null_resource.null will no longer be managed by Terraform, but will not be destroyed
    # (destroy = false is set in the configuration).
    resource "null_resource" "null2331" {
      id = "1169332259171977768"
    }
  3. Apply the changes to update the state file.

    $ terraform apply

Step 4: Verify the Removal

After the apply completes, confirm that Terraform no longer tracks the resource.

  • CLI Verification: Run the terraform state list command and confirm that the resource address is no longer in the output.
  • UI Verification: In HCP Terraform or Terraform Enterprise, navigate to your workspace's Resources tab in the UI and confirm the resource is no longer listed.

Additional Information

For more details on this feature, refer to the official Removing Resources Documentation.

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB77","label":"Automation Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSGH5YK","label":"IBM Terraform Self-Managed"},"ARM Category":[{"code":"","label":""}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)"}]

Historical Number

34185721057555

Document Information

Modified date:
16 March 2026

UID

ibm17265660