Cloud & GCP Engineer Guide: Importing Live AWS/GCP Infrastructure into Terraform IaC

Fast-growing engineering teams often provision their initial AWS or Google Cloud environments manually through the web console or ad-hoc CLI scripts—only to hit a wall when SOC 2 auditors, multi-region disaster recovery, or staging parity require 100% Infrastructure-as-Code (IaC) coverage. Destroying and recreating live production databases, VPCs, or load balancers is out of the question. As a Senior Cloud Engineer and Google Certified Professional Cloud Architect, here is how I codify brownfield AWS and GCP estates into clean, modular Terraform state with zero downtime.

1. Declarative Config Generation with Terraform `import` Blocks

Rather than running imperative `terraform import` commands one by one and manually guessing HCL attributes until `terraform plan` shows zero diff, modern Terraform supports declarative `import` blocks combined with `-generate-config-out` to inspect live cloud APIs and emit the exact HCL resource definitions automatically:

# imports.tf — Declaratively map live GCP & AWS production resources into state
import {
  to = google_sql_database_instance.primary_postgres
  id = "projects/prod-core-410/instances/pg-main-us-east1"
}

import {
  to = google_cloud_run_v2_service.api_gateway
  id = "projects/prod-core-410/locations/us-east1/services/aldianfazrihady"
}

import {
  to = aws_lb.application_alb
  id = "arn:aws:elasticloadbalancing:us-east-1:642656484571:loadbalancer/app/AFCOM-0/89ab12cd34ef56"
}

Running `terraform plan -generate-config-out=generated_resources.tf` queries the Google Cloud and AWS provider schemas, generates the HCL resource blocks, and verifies that importing the resources will result in **0 resources to destroy and 0 in-place mutations**:

#!/usr/bin/env bash
set -euo pipefail

terraform init -upgrade
terraform plan -generate-config-out=generated_resources.tf

# Verify that the import plan performs zero destructive actions before applying
plan_summary=$(terraform plan -no-color | grep -E "Plan:|No changes" || true)
echo "Terraform Import Verification: ${plan_summary}"

2. Refactoring Bulk `Terraformer` Dumps into Reusable Modules

When importing hundreds of IAM bindings, security group rules, and Route53/Cloud DNS records using `terraformer`, raw generated HCL contains hardcoded ARNs and flat files. I use `moved` blocks (`moved { from = aws_subnet.flat_1 to = module.vpc.aws_subnet.public["us-east-1a"] }`) to refactor flat imported state into clean, parameterized modules without detaching or recreating a single live resource.

3. Hire a Senior Cloud & GCP Engineer for Terraform Modernization

Need to bring an existing AWS or GCP production account under Terraform governance? Explore my Cloud Engineer Pillar Guide, review my GCP Engineer Pillar Guide, or book a 1-Day Terraform IaC Audit Sprint.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs