Setting the file. One moment.
Skill 17 · Terraform Search Import
Subchapter 17.1
references/MANUAL-IMPORT.mdMarkdown2 KBView on GitHub
Use this workflow when your target resource type isn’t supported by Terraform Search.
AWS CLI examples:
# RDS instances (not yet supported by Terraform Search)
aws rds describe-db-instances --query 'DBInstances[].DBInstanceIdentifier'
# DynamoDB tables (not yet supported by Terraform Search)
aws dynamodb list-tables --query 'TableNames[]'
# API Gateway REST APIs (not yet supported by Terraform Search)
aws apigateway get-rest-apis --query 'items[].id'
# SNS topics (not yet supported by Terraform Search)
aws sns list-topics --query 'Topics[].TopicArn'# Example for RDS instance
resource "aws_db_instance" "existing_db" {
identifier = "my-existing-db"
# Add other required attributes
}
# Example for DynamoDB table
resource "aws_dynamodb_table" "existing_table" {
name = "my-existing-table"
# Add other required attributes
}
# Example for SNS topic
resource "aws_sns_topic" "existing_topic" {
name = "my-existing-topic"
}# Example for RDS instance
resource "aws_db_instance" "existing_db" {
identifier = "my-existing-db"
# Add other required attributes
}
import {
to = aws_db_instance.existing_db
id = "my-existing-db"
}
# Example for DynamoDB table
resource "aws_dynamodb_table" "existing_table" {
name = "my-existing-table"
# Add other required attributes
}
import {
to = aws_dynamodb_table.existing_table
id = "my-existing-table"
}# Plan the import to see what will happen
terraform plan
# Apply to import the resources
terraform applyFor multiple resources of the same type:
#!/bin/bash
# bulk-import-dynamodb.sh
# Get all table names
tables=$(aws dynamodb list-tables --query 'TableNames[]' --output text)
# Generate import configuration
cat > dynamodb-imports.tf << 'EOF'
# DynamoDB Table Resources and Imports
EOF
for table in $tables; do
# Create resource and import blocks
cat >> dynamodb-imports.tf << EOF
resource "aws_dynamodb_table" "table_${table//[-.]/_}" {
name = "$table"
}
import {
to = aws_dynamodb_table.table_${table//[-.]/_}
id = "$table"
}
EOF
done
echo "Generated dynamodb-imports.tf with import blocks"
echo "Run 'terraform plan' to review, then 'terraform apply' to import"