SCC

Brasil

os cloud gurus

Software Cloud Consulting

Your software development, cloud, consulting & shoring company

IaC - infrastructure as Code


7

By Wolfgang Unger


What is AWS CloudFormation? What is Terraform? What is the CDK?
If you want to create Resources on AWS not just for your first steps on AWS, but for live environments, you probably already know, you should use IaC to do so.
Let's have a look on the alternatives in this blog. We will discuss CloudFormation, Terraform and the CDK. To see which one might be the best fit for your use case.

CloudFormation


SMM

AWS native

- Yaml or Json Format
- AWS only
- Group resources in CFN Templates
- Zero-Client (Stateless)
Adv. Options:
- CFN Language Features
- Nested Stacks
- StackSets

Advantages
- Easy to learn and apply
- Good documentation and lots of examples
- Zero-Client. No local installations required. Just edit Yaml or Json Files. No conflicts with different versions in your team.
- Automated tagging of all CFN created Resources
- You can see the deployed stacks in the CloudFormation Web-Console, you can also see possible drifts there
- No state issues

Disadvantages
- Only for AWS
- Text bases, limited possibilites to avoid code dublications

When to use
- Best tool to start with IaC
- You don't have a team with strong coding abilities ( Python, Java, Go, Typescript or .NET) and want to keep IaC simple, using text files.
- You have no plans to migrate to a different cloud provider

Terraform


SMM

Hashicorp

- HCL Format (Hashicorp Definition Language)
- Cloud agnostic
- Group resources in Terraform files
- Local terraform installation, state either local or with backend (AWS)
Adv Options:
- Modules, ForEach

Advantages
- Bit more advanced than CloudFormation, but still kind of easy to learn and apply
- Good documentation and lots of examples
- Cloud agnostic ( at least in theory)

Disadvantages
- Text based, limited possibilites to avoid code dublications
- Local installation required. Terraform releases frequently new versions. If your team members use different versions you might run into trouble.
- State issues. Problems with the state (locally or on AWS) are hard to resolve.

When to use
- You don't have a team with strong coding abilities ( Python, Java, Go, Typescript or .NET) and want to keep the IaC simple, using text files.
- You don't want to stick to one cloud provider and keep the possibility to switch to another cloud
- You might already have some terraform know how

CDK


SMM
AWS native

- Programmatic resource creation, in either - Python, Java, Go, Typescript or .NET
- Support on all language features ( loops, conditions etc)
- Usage of object orientated features is possible to avoid code dublication. Inheritence, polymorphism etc

CDK Language Basics
-Constructs :
represents resources
There a the default contructs of type L1, L2, L3
But you can write your own constructs
Can be sub-classed to use object orientated features

Stacks :
-represent the CFN stack to be generated, group your L1,L2, L3 constructs in these stacks

Advantages
- If you want to use Infrastrusture as Code, the CDK is the real deal. CloudFormation and Terraform are indeed more infrastructure as Text
- All object orientated language feature available. Use Inheritence and polymorphism to avoid code dublications and structure your Code
- Create pip module for often used constructs (Python)
- Great for really advanced environments and a good trained DevOps team
- You can see the deployed stacks in the CloudFormation Web-Console, you can also see possible drifts there ( CDK generates CFN Templates which will be deployed in the account)
Disadvantages
- More difficult to learn than CFN or terraform
- Local installation, versions on team members must be equal to avoid trouble
When to use
You have a team with strong coding abilities (in either Python, Java, Go, Typescript or .NET)
You want write to your IaC in the same language your are already familiar or using ( for example Python or Java)
You want to really code your infrastructure and avoid duplications in the definition files

Resume


My personal favourite is the CDK in python. But you have to make your choice what tool is best for your company, team or use case. If you don't have a skilled development team in one of the CDK languages, go for CloudFormation or Terraform.
If you don't want to commit on AWS for 100%, use terraform, otherwise use CloudFormation, which is the tool most easy to get started

See also these blogs about the CDK :
Get started with the AWS CDK (Python)
CDK - Overview on Stacks and Constructs
CodePipeline with CDK Python and generic Superclass
API Gateway with CDK

  • Back to Blog Overview
  • Autor


    ...

    Wolfgang Unger

    AWS Architect & Developer

    6 x AWS Certified

    1 x Azure Certified

    A Cloud Guru Instructor

    Certified Oracle JEE Architect

    Certified Scrum Master

    Certified Java Programmer

    Passionate surfer & guitar player