> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ubiquex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# lifecycle rules

> Control resource lifecycle behaviour with prevent_destroy, ignore_changes, and create_before_destroy.

The `lifecycle` block controls how Pulumi manages a resource's create, update, and delete operations. Supported on `unit` and `component` blocks.

## Syntax

```hcl theme={null}
unit "resource_type" "name" {
  # ... attributes ...

  lifecycle {
    prevent_destroy       = true
    ignore_changes        = ["attribute1", "attribute2"]
    create_before_destroy = true
  }
}
```

Only one `lifecycle` block is allowed per resource.

## Rules

### `prevent_destroy`

Blocks `pulumi destroy` and `ubx destroy` from deleting the resource. Useful for production databases and critical infrastructure.

```hcl theme={null}
unit "aws_rds_instance" "db" {
  engine         = "postgres"
  instance_class = "db.t3.micro"

  lifecycle {
    prevent_destroy = true
  }
}
```

Generated TypeScript: `{ retainOnDelete: true }`

### `ignore_changes`

Tells Pulumi to ignore drift on specified attributes. The resource won't be updated even if these attributes change outside of ubx.

```hcl theme={null}
unit "aws_rds_instance" "db" {
  engine   = "postgres"
  password = secret("aws_secrets_manager", "prod/db/password")

  lifecycle {
    ignore_changes = ["password", "latest_restorable_time"]
  }
}
```

Generated TypeScript: `{ ignoreChanges: ["password", "latestRestorableTime"] }`

### `create_before_destroy`

Creates the replacement resource before destroying the original. Minimises downtime during replacements.

```hcl theme={null}
unit "aws_instance" "web" {
  ami           = ~data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  lifecycle {
    create_before_destroy = true
  }
}
```

Generated TypeScript: `{ deleteBeforeReplace: false }`

## All Three Combined

```hcl theme={null}
unit "aws_rds_instance" "db" {
  engine         = "postgres"
  instance_class = "db.r6g.xlarge"

  lifecycle {
    prevent_destroy       = true
    ignore_changes        = ["password"]
    create_before_destroy = true
  }
}
```

```typescript theme={null}
const db = new aws.rds.Instance("db", {
    engine: "postgres",
    instanceClass: "db.r6g.xlarge",
}, { retainOnDelete: true, ignoreChanges: ["password"], deleteBeforeReplace: false });
```

## Constraints

* All lifecycle field values must be `Resolved&lt;T&gt;` — no `~` pending references
* `ignore_changes` takes a list of attribute name strings
* Only one `lifecycle` block per resource
