There are layers of abstraction in IaC projects:
- lowest level: create and manage resources only using API calls. Generally no one is really doing this anymore, although with tools like Ansible people have gone pretty far down this road without using any higher level abstractions …
- CloudFormation: create resources in CloudFormation templates and have state and dependencies managed for you. Or alternatively, Terraform can manage it’s own state and provide a similar level of abstraction. Troposphere fits in here, as it’s just a tool to let you write CloudFormation in Python.
- Terraform - or Stacker/Sceptre: tooling to handle configuration for passing parameters to stacks in different environments, to create/update the stacks in your AWS accounts. This is “terraform plan” or “stacker build” which can let you know things like what resources an update might touch.
- CDK is “a high-level object-oriented abstraction to define AWS resources imperatively using the power of modern programming languages. Using the CDK’s library of infrastructure constructs, you can easily encapsulate AWS best practices in your infrastructure definition and share it without worrying about boilerplate logic.”. CDK is essentially getting you one level of abstraction above declaring everything directly in CloudFormation templates. Terraform has a similar abstraction with Terraform modules.
As CDK is controlled entirely from a programming language, it’s up to you to write some tooling/commands to allow you to orchestrate provisioning and handle your per-environment configuration. It is roughly similar to what stacker_blueprints provides for Stacker, a way to abstract and re-use common CloudFormation template generation patterns.
If you are using CDK, you can do quite a bit fairly quickly. However, you would still need to layer on additional tooling if you were using it for large production environments. For example, Terragrunt and Terratest are tools for Terraform that allow you to do functional testing and DRY configuration. You’d need to create your own analogues for those in CDK (caveat, I see CDK has some built-in test tooling … I haven’t looked at it yet though). In CloudFormation land, people are using Runway to also manage multi-region, multi-account deployments, so you’d need to write some wrapper around your CDK to allow it to work with such a tool.
Finally tools likeCDK, Punchcard and AIM are attempting to take IaC projects to a layer of abstraction above what exists with any of the current tooling today. CDK has the concept of high-level Constructs, so that if you have a Lambda subscribe to an SNS Topic, CDK will auto generate an IAM Policy to allow the topic to invoke the Lambda.
Punchcard by allow you to both define a Lambda and then directly have the Lambda code in the function that defined the Lambda. Essentially letting you freely mix IaC code freely with App code(!).
AIM (which is a tool I’m contributing to) attempts to abstract as much a way as possible. It lets you describe everything in declarative YAML, then feeds that YAML describing your infrastructure and applications into a CDK-like engine, which can do similar time saving features such as IAM policy auto-generation, but also adds on other time saving smart features, such as if you declare you want an ASG to have swap metrics, it will not only auto-generate an IAM Policy to allow the instance to collect metrics, but also configure and install the CloudWatch Agent on those instances.