{"id":15663593,"url":"https://github.com/rafalwilinski/terraform-vs-cdk","last_synced_at":"2025-08-05T23:13:13.953Z","repository":{"id":46064602,"uuid":"188706557","full_name":"RafalWilinski/terraform-vs-cdk","owner":"RafalWilinski","description":"Terraform vs AWS CDK comparison","archived":false,"fork":false,"pushed_at":"2022-12-10T15:30:54.000Z","size":284,"stargazers_count":17,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T18:15:15.048Z","etag":null,"topics":["aws","aws-ecs","cloud","cloudformation","nodejs","s3","terraform"],"latest_commit_sha":null,"homepage":"https://rwilinski.me","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RafalWilinski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-26T16:26:35.000Z","updated_at":"2021-05-10T18:44:22.000Z","dependencies_parsed_at":"2023-01-26T08:45:12.633Z","dependency_job_id":null,"html_url":"https://github.com/RafalWilinski/terraform-vs-cdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RafalWilinski%2Fterraform-vs-cdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RafalWilinski%2Fterraform-vs-cdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RafalWilinski%2Fterraform-vs-cdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RafalWilinski%2Fterraform-vs-cdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RafalWilinski","download_url":"https://codeload.github.com/RafalWilinski/terraform-vs-cdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252741474,"owners_count":21797027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-ecs","cloud","cloudformation","nodejs","s3","terraform"],"created_at":"2024-10-03T13:38:33.547Z","updated_at":"2025-05-06T18:15:18.834Z","avatar_url":"https://github.com/RafalWilinski.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform vs AWS CDK - Comparison by building 2-tier Web Application\n\nSource code for article: [https://rwilinski.me/blog/cdk-vs-terraform/](https://rwilinski.me/blog/cdk-vs-terraform/)\n\nGoal of this repo is to compare provisioning of 2-tier web app with CDK and Terraform.\n\n## Intro\n\nWhat we'll be building:\n![Infra](assets/infra.svg?sanitize=true 'Infra')\n\nKey points:\n\n- VPC with two subnets (public and private) in each AZ, IPGW in Public, NAT Gateway in private\n- ECS Cluster in Public Subnet running Fargate cluster with Node.js service and task\n- Application Load Balancer exposed to the public connected to the Fargate service\n- Public S3 bucket with assets\n- IAM Role for task to manipulate S3 Bucket\n- Serverless RDS Aurora MySQL-compatible instance in private subnet, accessible only from ECS tasks\n\nFor this comparison's sake we'll need a Docker image with a simple Express.js stored in ECR. Simply execute `./build-and-push.sh` to create an AWS Elastic Container Registry, build the Docker image and push it to the cloud.\n\n## Prerequisites\n\n- AWS CLI\n- AWS CDK\n- Docker\n- Terraform\n\n## CDK\n\n- Imperative (consequences? code flow etc.)\n- Can be written in TS, Java, Python\n- Make sure that CDK and construct libraries are the same version\n- API Changes pretty quickly, examples are outdated and require some adjustments like `loadBalancer.loadBalancerDnsName` vs loadBalancer.dnsName`\n- Nested Stacks and 200 resources limit is cumbersome, still not resolved https://github.com/awslabs/aws-cdk/issues/239\n- Can write custom resources which are like modules in Terraform\n- Some of the constructs are really explicit making you wonder how you should correctly plug all the parts\n- With higher level of abstraction you end up having more circular dependencies, e.g. ECS Service wants Database URL but database's SG needs to know from which SG it should allow the traffic\n\n#### Initialization\n\n```sh\ncdk init app --language=typescript\n```\n\nWe'll need ECS, EC2, S3 and RDS packages:\n\n```\nnpm i @aws-cdk/aws-ecs @aws-cdk/aws-ec2 @aws-cdk/aws-s3 @aws-cdk/aws-rds\n```\n\nTo render CloudFormation file:\n\n```sh\nnpm run build \u0026\u0026 cdk synth\n```\n\nTo deploy\n\n```sh\ncdk deploy\n```\n\n## Terraform\n\n...\n\n```sh\n➜  find ./cdk/lib -name \"*.ts\" | xargs cat | wc -l\n105\n➜  find ./terraform -name \"*.tf\" | xargs cat | wc -l\n516\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafalwilinski%2Fterraform-vs-cdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafalwilinski%2Fterraform-vs-cdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafalwilinski%2Fterraform-vs-cdk/lists"}