Skip to main content
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

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

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:
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<T> — a plain string or input reference. Cloud resource IDs must be known before apply starts:
# ✓ 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

import "aws_s3_bucket_v2" "assets" { id = "my-bucket" }
unit "aws_s3_bucket_v2" "assets" {
  bucket = "my-bucket"
  lifecycle { prevent_destroy = true }
}
const assets = new aws.s3.BucketV2("assets", {
    bucket: "my-bucket",
}, { retainOnDelete: true, import: "my-bucket" });

Error Cases

SituationError
id is missingimport block "T" "N" requires an "id" attribute
id is Pending<T>the import block "id" must be a resolved value
No matching unit blockimport "T" "N" requires a matching unit block
Duplicate importimport "T" "N" is declared more than once