Part 2: Splitting a 1,600-line imported main.tf into seven modules with HashiCorp Agent Skills, the Terraform MCP Server and moved blocks, then retiring the CloudFormation stack that started it all
At the end of Part 1 I made a confession: I had a managed application, not a well-structured one. Everything was in Terraform state, the app never went down, and the code was still one enormous main.tf that I would not wish on a colleague.
Here is what that file looked like by the time I started the refactor:
Resource names like stack_subnets_3 , iam_roles_33 and ingress_rules_in_stack_groups_1_5 . They describe the query that found the resource, not what the resource does.
Hardcoded IDs and ARNs everywhere. Terraform did not know the subnets belonged to the VPC. The strings just happened to match.
45 import blocks still sitting next to the resources they imported.
Nothing I could reuse for a second environment.
Part 1 closed with about 40 resources in state.…