github.com/kanishk98/terraform@v1.3.0-dev.0.20220917174235-661ca8088a6a/website/docs/cli/state/taint.mdx (about)

     1  ---
     2  page_title: Forcing Re-creation of Resources - Terraform CLI
     3  description: Commands that allow you to destroy and re-create resources manually.
     4  ---
     5  
     6  # Forcing Re-creation of Resources
     7  
     8  During planning, by default Terraform retrieves the latest state of each
     9  existing object and compares it with the current configuration, planning
    10  actions only against objects whose current state does not match the
    11  configuration.
    12  
    13  However, in some cases a remote object may become damaged or degraded in a
    14  way that Terraform cannot automatically detect. For example, if software
    15  running inside a virtual machine crashes but the virtual machine itself is
    16  still running then Terraform will typically have no way to detect and respond
    17  to the problem, because Terraform only directly manages the machine as a whole.
    18  
    19  If you know that an object is damaged, or if you want to force Terraform to
    20  replace it for any other reason, you can override Terraform's default behavior
    21  using [the `-replace=...` planning option](/cli/commands/plan#replace-address)
    22  when you run either `terraform plan` or `terraform apply`:
    23  
    24  ```shellsession
    25  $ terraform apply -replace=aws_instance.example
    26  # ...
    27  
    28    # aws_instance.example will be replaced, as requested
    29  -/+ resource "aws_instance" "example" {
    30        # ...
    31      }
    32  ```
    33  
    34  ## The "tainted" status
    35  
    36  Sometimes Terraform is able to infer automatically that an object is in an
    37  incomplete or degraded state. For example, if creation of a complex object
    38  fails in such a way that parts of it already exist in the remote system, or
    39  if object creation succeeded but a provisioner step subsequently failed,
    40  Terraform must remember that the object exists but may not be fully-functional.
    41  
    42  Terraform represents this situation by marking an object in the state as
    43  "tainted". When an object is marked with this status, the next plan will force
    44  replacing that object in a similar way to if you had specified that object's
    45  address using `-replace=...` as described above.
    46  
    47  ```
    48    # aws_instance.example is tainted, so must be replaced
    49  -/+ resource "aws_instance" "example" {
    50        # ...
    51      }
    52  ```
    53  
    54  If Terraform has marked an object as tainted but you consider it to be working
    55  correctly and do not want to replace it, you can override Terraform's
    56  determination using [the `terraform untaint` command](/cli/commands/untaint),
    57  after which Terraform will consider the object to be ready for use by any
    58  downstream resource declarations.
    59  
    60  You can also _force_ Terraform to mark a particular object as tainted using
    61  [the `terraform taint` command](/cli/commands/taint), but that approach is
    62  deprecated in favor of the `-replace=...` option, which avoids the need to
    63  create an interim state snapshot with a tainted object.