---
title: "Bring hand-made resources under code · Agent Wranglers"
url: https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/import-existing-resources
updated: 2026-10-20
licence: "All rights reserved"
---

# Bring hand-made resources under code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Infrastructure as code](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code)
- Rule: Import every resource that was made by hand into code before you change it. Then tag everything the code manages, so the rest stands out.
- How: Write an `import` block with the resource's ID and let the tool write a first draft with `plan -generate-config-out`. Clean the draft, then apply until the plan shows no changes. Pulumi has `pulumi import`. Set a `managed-by` tag on every resource through the provider's default tags. A search for resources without it then lists what is still hand-made.
- Check: After the import, the plan shows no changes. A resource search in production, such as AWS Resource Explorer, finds no taggable resource without the `managed-by` tag.

Example:

```hcl
import {
  to = aws_s3_bucket.invoices
  id = "example-shop-invoices"
}

provider "aws" {
  region = "eu-north-1"
  default_tags {
    tags = { managed-by = "opentofu", service = "shop", environment = "production" }
  }
}
```

```sh
tofu plan -generate-config-out=generated.tf
# Resources the code does not manage yet
aws resource-explorer-2 search --query-string '-tag.key:managed-by' --query 'Resources[].Arn'
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers infrastructure playbook: https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/import-existing-resources`.

- Previous: [Protect resources that hold data](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/protect-stateful-resources)
- [Infrastructure as code](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code)
