> ## 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.

# import block

> Bring existing cloud resources under ubx management.

The `import` block annotates a `unit` block so Pulumi adopts an already-existing cloud resource instead of creating a new one. Equivalent to Terraform's `import` block.

## Syntax

```hcl theme={null}
import "resource_type" "name" {
  id = "cloud-resource-id"
}
```

Two labels required, matching a `unit` block exactly. Only `id` is allowed — any other attribute is a compile error.

## Example

```hcl theme={null}
import "aws_s3_bucket_v2" "assets" {
  id = "my-existing-bucket-name"
}

unit "aws_s3_bucket_v2" "assets" {
  bucket = "my-existing-bucket-name"
  tags   = { managed_by = "ubx" }
}
```

Generated TypeScript:

```typescript theme={null}
const assets = new aws.s3.BucketV2("assets", {
    bucket: "my-existing-bucket-name",
    tags: { managedBy: "ubx" },
}, { import: "my-existing-bucket-name" });
```

## `id` Must be Resolved

The `id` attribute must be `Resolved&lt;T&gt;` — a plain string or `input` reference. Cloud resource IDs must be known before apply starts:

```hcl theme={null}
# ✓ plain string
import "aws_s3_bucket_v2" "b" { id = "my-bucket" }

# ✓ input reference
import "aws_s3_bucket_v2" "b" { id = input.bucket_id }

# ✗ Pending ref — compile error
import "aws_s3_bucket_v2" "b" {
  id = ~unit.aws_s3_bucket_v2.src.bucket
}
```

## Combined with lifecycle

```hcl theme={null}
import "aws_s3_bucket_v2" "assets" { id = "my-bucket" }
unit "aws_s3_bucket_v2" "assets" {
  bucket = "my-bucket"
  lifecycle { prevent_destroy = true }
}
```

```typescript theme={null}
const assets = new aws.s3.BucketV2("assets", {
    bucket: "my-bucket",
}, { retainOnDelete: true, import: "my-bucket" });
```

## Error Cases

| Situation                  | Error                                             |
| -------------------------- | ------------------------------------------------- |
| `id` is missing            | `import block "T" "N" requires an "id" attribute` |
| `id` is `Pending&lt;T&gt;` | `the import block "id" must be a resolved value`  |
| No matching `unit` block   | `import "T" "N" requires a matching unit block`   |
| Duplicate `import`         | `import "T" "N" is declared more than once`       |
