$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
TerraformintermediateNew

Terraform Import

Share

Import existing infrastructure into Terraform state

Works with OpenClaude

You are a Terraform infrastructure engineer. The user wants to import existing cloud resources into Terraform state files so they can be managed by Terraform going forward.

What to check first

  • Run terraform version to confirm Terraform is installed and check your version (import syntax varies slightly between versions)
  • Run aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' (or equivalent for your cloud provider) to list resource IDs you want to import
  • Verify the resource type exists in your Terraform configuration with a resource "aws_instance" "example" {} block (resource must be declared, not yet configured)

Steps

  1. Create or update your Terraform configuration file with an empty resource block matching the resource type you're importing (e.g., resource "aws_instance" "web_server" {})
  2. Initialize your Terraform working directory with terraform init if you haven't already
  3. Run terraform import aws_instance.web_server i-1234567890abcdef0 where the first argument is resource_type.resource_name and the second is the actual resource ID from your cloud provider
  4. After successful import, run terraform state show aws_instance.web_server to view the imported resource attributes
  5. Update your resource block in the .tf file with the attributes shown in state (copy relevant arguments like ami, instance_type, security_groups, etc.)
  6. Run terraform plan to verify Terraform recognizes no changes needed—if plan shows modifications, adjust your configuration to match the actual resource
  7. Repeat steps 1–6 for each additional resource you need to import
  8. Run terraform apply once all imports are complete and your plan shows no changes

Code

# Step 1: Declare empty resource blocks for resources you'll import
resource "aws_instance" "web_server" {
  # Attributes will be populated after import
}

resource "aws_security_group" "allow_http" {
  # Attributes will be populated after import
}

resource "aws_s3_bucket" "app_data" {
  # Attributes will be populated after import
}

# Step 2: Bash script to import multiple resources
#!/bin/bash
set -e

# Define your resources as "resource_type.resource_name:actual_resource_id"
declare -a RESOURCES=(
  "aws_instance.web_server:i-1234567890abcdef0"
  "aws_security_group.allow_http:sg-0987654321fedcba0"
  "aws_s3_bucket.app_data:my-existing-bucket"
)

for resource in "${RESOURCES[@]}"
do
  IFS=':' read -r tf_resource aws_id <<< "$resource"
  echo "Importing $tf_resource with ID $aws_id..."
  terraform import "$tf_resource" "$aws_id"
  echo "✓ Successfully imported $tf_resource"
done

echo

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryTerraform
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
terraformimportinfrastructure

Install command:

curl -o ~/.claude/skills/terraform-import.md https://clskills.in/skills/terraform/terraform-import.md

Related Terraform Skills

Other Claude Code skills in the same category — free to download.

Want a Terraform skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.