teluzia.Cloud Engineer · Day 95
CHAPTER 14 · ADVANCED TERRAFORM

Imports and existing resources

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Import is adding an existing building to the inventory, not building a duplicate or automatically redesigning it. Import associates an existing remote object with a Terraform resource address. The object must have one clear ownership mapping; importing the same object into multiple states creates conflicting management. Provider-specific identifiers and resource import support must be checked in official documentation. Import alone does not make configuration perfectly match the existing resource. Import blocks support reviewed workflows, and configuration generation can provide a starting draft where supported. Inspect generated attributes and provider defaults, then review the resulting plan for unintended changes before applying.

Think of it this way

Import is adding an existing building to the inventory, not building a duplicate or automatically redesigning it.

TOPIC 01 / 03Step by step

Import mapping

Import associates an existing remote object with a Terraform resource address. The object must have one clear ownership mapping; importing the same object into multiple states creates conflicting management. Provider-specific identifiers and resource import support must be checked in official documentation. For example, an existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

WORKED EXAMPLE
An existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

An existing bucket was created outside Terraform. The team selects one intended resource address and uses the provider-supported import identifier to associate that address with the bucket. No second bucket needs to be created. The state mapping now says that this logical resource manages the existing remote identity, but configuration still determines the desired settings.

Import adopts an existing object into management. A resource address identifies its place in configuration. An import identifier is provider-specific and may not match an arbitrary display name. Check support and ownership before execution. Importing the same object into two states makes both managers believe they control it, creating conflicting plans. Secure state backups and a reviewed import plan help adoption, but importing is not a backup of object contents. Agree that any previous automation or manual process stops competing for the same settings, or deliberately document which attributes remain externally managed.

Why this matters

An existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

A common trap

Do not overlook this operational distinction: Provider-specific identifiers and resource import support must be checked in official documentation.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Import mapping

Import associates an existing remote object with a Terraform resource address. The object must have one clear ownership mapping; importing the same object into multiple states creates conflicting management. Provider-specific identifiers and resource import support must be checked in official documentation. For example, an existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

WORKED EXAMPLE
An existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

An existing bucket was created outside Terraform. The team selects one intended resource address and uses the provider-supported import identifier to associate that address with the bucket. No second bucket needs to be created. The state mapping now says that this logical resource manages the existing remote identity, but configuration still determines the desired settings.

Import adopts an existing object into management. A resource address identifies its place in configuration. An import identifier is provider-specific and may not match an arbitrary display name. Check support and ownership before execution. Importing the same object into two states makes both managers believe they control it, creating conflicting plans. Secure state backups and a reviewed import plan help adoption, but importing is not a backup of object contents. Agree that any previous automation or manual process stops competing for the same settings, or deliberately document which attributes remain externally managed.

Why this matters

An existing bucket ID maps to aws_s3_bucket.logs in one intended state, not two competing environment states.

A common trap

Do not overlook this operational distinction: Provider-specific identifiers and resource import support must be checked in official documentation.

Configuration and generated drafts

Import alone does not make configuration perfectly match the existing resource. Import blocks support reviewed workflows, and configuration generation can provide a starting draft where supported. Inspect generated attributes and provider defaults, then review the resulting plan for unintended changes before applying. For example, after import, a draft says versioning disabled while the real bucket has it enabled; the plan may propose an unwanted change.

WORKED EXAMPLE
After import, a draft says versioning disabled while the real bucket has it enabled; the plan may propose an unwanted change.

After an import, a bucket's real configuration enables versioning, but the handwritten configuration omits or disagrees with related settings. A later plan may propose a change the team never intended. Import establishes identity mapping; it does not automatically infer every desired business rule. Generated configuration, where supported, is a draft to inspect rather than an unquestionable design.

The baseline is the agreed starting configuration. A generated draft is tool-produced configuration needing review. A no-change plan indicates agreement under the current provider reads and configuration, not a permanent guarantee. Compare important security, encryption, logging, lifecycle, and ownership settings with actual requirements. Provider defaults can differ from existing resources. Avoid applying the first post-import plan merely because import succeeded. Separate adoption from redesign: first achieve an understood baseline, then propose intentional configuration changes with their own operational review and validation.

Why this matters

After import, a draft says versioning disabled while the real bucket has it enabled; the plan may propose an unwanted change.

A common trap

Do not overlook this operational distinction: Inspect generated attributes and provider defaults, then review the resulting plan for unintended changes before applying.

Adoption and drift control

Adopting resources requires agreement about future ownership and how outside changes will be handled. Record previous creation context, sensitive dependencies, and rollback options. A no-change plan is useful baseline evidence, but future provider or configuration changes still need ordinary review. For example, a team documents that Terraform now owns the bucket while another automation must stop changing the same configuration.

WORKED EXAMPLE
A team documents that Terraform now owns the bucket while another automation must stop changing the same configuration.

A networking team manages a shared subnet while an application team wants to use it. Reading its ID through a data source preserves networking ownership. Importing it into the app state without agreement gives both teams competing control. Later, one team adds a tag and the other plan removes it, producing a recurring conflict.

Ownership assigns management responsibility. Drift policy decides how external changes are treated. Adoption transfers or establishes control with agreement. Document previous creator, other automations, expected manual changes, and recovery procedures. Ignoring selected changes can represent intentional shared responsibility, but broad ignores can conceal security drift. A resource should have one clear state owner wherever possible, with consumers receiving stable interfaces rather than duplicate imports. After adoption, maintain ordinary change reviews; imported resources can still be destroyed or replaced by later configuration edits, even though their original creation occurred long before Terraform entered the workflow.

Why this matters

A team documents that Terraform now owns the bucket while another automation must stop changing the same configuration.

A common trap

Do not overlook this operational distinction: A no-change plan is useful baseline evidence, but future provider or configuration changes still need ordinary review.

KEEP THESE WITH YOU

Today’s takeaways

Import mapping: Import associates an existing remote object with a Terraform resource address. The object must have one clear ownership mapping; importing the same object into multiple states creates conflicting management. Provider-specific identifiers and resource import support must be checked in official documentation.

Configuration and generated drafts: Import alone does not make configuration perfectly match the existing resource. Import blocks support reviewed workflows, and configuration generation can provide a starting draft where supported. Inspect generated attributes and provider defaults, then review the resulting plan for unintended changes before applying.

Adoption and drift control: Adopting resources requires agreement about future ownership and how outside changes will be handled. Record previous creation context, sensitive dependencies, and rollback options. A no-change plan is useful baseline evidence, but future provider or configuration changes still need ordinary review.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed