Moving production infrastructure from CDK to Terraform without downtime
The author, who works on the development team at Levtech, describes how the team moved production infrastructure from AWS CDK to Terraform. The infrastructure had 12 services plus a shared platform, 13 stacks in total, and the migration was completed without stopping them. Three reasons led to the move: support for AWS CDK v1 ended in June 2023, resources were managed by two IaC[1] tools at once, and security work required a single IaC setup.
The method is transferring ownership, not recreating resources. First, the CDK side sets RemovalPolicy to RETAIN and deploys, so that deleting a definition does not delete the AWS resource. Then the definition is removed from CDK, and the resource is imported into Terraform with an import block. After that, the resource is no longer managed by CDK and becomes an orphan[2]. The author recommends applying Terraform first and CDK second, on the same day, so that no resource is left unmanaged or managed by both tools.
The team kept existing settings unchanged, migrated stacks one at a time with the shared platform last, and used AI to generate migration code, checking that the plan showed only imports. Two problems came up: removing service-side definitions caused a replace in the shared platform's Target Group, and Export references from other stacks blocked the deletion of CDK resources.
Sources
-
JPZenn JA
CDKからTerraformへ:所有権移譲による本番インフラ無停止のIaC移行



