Skip to main content

atmos terraform import

Use this command to import existing infrastructure resources into the Terraform state for an Atmos component in a stack.

atmos terraform import --help

Usage​

Execute the terraform import command like this:

atmos terraform import <component> <ADDRESS> <ID> -s <stack> [options]

This command imports existing infrastructure into your Terraform state. This allows you to bring resources created outside of Terraform under Terraform management. Atmos automatically sets AWS_REGION if a region variable is found.

Atmos Enhancements

Atmos provides several enhancements for the import command:

  • Automatic terraform init before importing
  • Workspace selection and management
  • Variable file generation and passing
  • Automatic AWS_REGION environment variable setting based on the component's region variable
  • Component locking support (blocks import if metadata.locked: true)

Examples​

Basic Import​

# Import an AWS instance
atmos terraform import vpc -s dev aws_instance.web i-1234567890abcdef0

Import with ID Containing Spaces​

# Import resources with complex IDs
atmos terraform import vpc -s dev 'aws_iam_role_policy.example' 'role-name:policy-name'

Import to Specific Index​

# Import to a specific index in a list
atmos terraform import app -s dev 'aws_instance.web[0]' i-1234567890abcdef0

Arguments​

component (required)

Atmos component name.

ADDRESS (required)

Terraform resource address to import to. This follows the format [module.]resource_type.resource_name[index]. Examples:

  • aws_instance.web - Simple resource
  • module.vpc.aws_subnet.private - Resource in a module
  • aws_instance.web[0] - Resource with index
  • module.app["prod"].aws_instance.web - Module with key
ID (required)

Provider-specific resource ID to import. This is the unique identifier from your cloud provider. Examples:

  • i-1234567890abcdef0 - AWS instance ID
  • role-name:policy-name - AWS IAM role policy (composite ID)
  • projects/my-project/zones/us-central1-a/instances/my-instance - GCP instance ID Note: Quote the ID if it contains spaces or special characters.

Flags​

--stack / -s (required)

Atmos stack name where the component is defined.

--skip-init (optional)

Skip running terraform init before executing the command.

atmos terraform import vpc -s dev --skip-init
--dry-run (optional)

Show what would be executed without actually running the command.

atmos terraform import vpc -s dev --dry-run

Native Terraform Flags​

This command supports native terraform import flags such as -input=false to disable interactive input, -var to set variables, -var-file to specify variable files.