CloudFormation vs CDK vs Terraform
Compare the same secure bucket in CloudFormation, the AWS CDK (C#) and Terraform, score the tools against a bank's real criteria with a small C# decision scorer, and write an architecture decision record you could defend to your team.
Assumes: .NET 10 LTS · Amazon.CDK.Lib 2.277.0 · Terraform 1.17.2 · Terraform AWS provider 6.73.0 · AWS CLI v2 · Region us-east-1. Verified against official sources on 2026-11-18.
Learning objectives
By the end of this lesson you can:
- Describe, for CloudFormation, the AWS CDK and Terraform, where the desired state lives, how a change is previewed, what happens when an apply fails and how drift is found.
- Write the same secure S3 bucket in all three tools and point out what each hides and what each makes you spell out.
- Choose a tool for a given team using weighted criteria, and say which criteria you would change for a different team.
- Explain multi-cloud, licensing and skills considerations without slogans.
- Run a small C# program that scores the tools and turn its result into an architecture decision record (ADR).
Prerequisites
- Lessons 1 to 7 of this module (Why infrastructure as code, CloudFormation fundamentals, then drift, CDK in C#, constructs, stacks and testing). Start from the module overview for the full list.
- Terraform fundamentals and Terraform state.
- Terraform modules.
- Tools: .NET 10 SDK (or the
mcr.microsoft.com/dotnet/sdk:10.0Docker image) for the scorer. No AWS account is needed.
Why this matters in banking
Choosing an IaC tool is a ten-year decision. The code you write will outlive three reorganisations. At Harbourline the choice shows up in awkward places:
- A new engineer asks, "Why do half our stacks use CDK and the other half Terraform?" Nobody remembers; two teams chose differently in 2024.
- An auditor asks how a change to a KMS key policy is reviewed. The answer differs by tool (a change set, a
cdk diff, aterraform plan), and each team has built its own evidence trail. - The bank signs a contract with another cloud for one workload, and someone says "Terraform is multi-cloud, so we should have used it all along". Is that true, and does it matter?
None of the three tools is "best". Each is a reasonable answer to a different set of constraints. Your job is to make the constraints explicit, score honestly, and write the decision down so the next person understands why.
The idea in plain language
All three tools do the same job: you describe the infrastructure you want, and the tool makes the real world match. They differ in how you describe it and where they remember what they built.
- CloudFormation is AWS's own engine. You write a declarative template in JSON or YAML. AWS stores the stack, its state and its history inside the service. You never see a state file.
- The AWS CDK is a way to write CloudFormation in a real programming language. You write C# classes;
cdk synthturns them into a CloudFormation template; CloudFormation deploys it. The CDK has no engine of its own for AWS resources. - Terraform (from HashiCorp, now part of IBM) has its own engine and its own language (HCL). It calls cloud APIs directly through providers and records what it built in a state file that you store and protect.
Analogy: think of building a branch. CloudFormation is the bank's own construction department: you hand over a drawing and they keep the project file. The CDK is an architect who writes the drawing for you from a rulebook (code), then hands it to that same department. Terraform is an independent contractor who works with any council, and keeps their own site diary that you must look after.
What problem each tool solves
| CloudFormation | AWS CDK | Terraform | |
|---|---|---|---|
| Language | JSON or YAML, plus intrinsic functions | C#, TypeScript, Python, Java, Go | HCL (with a JSON form) |
| Engine | AWS service | AWS service (CloudFormation) | Terraform CLI, local or in a runner |
| Desired state | Template | C# code, compiled to a template | .tf files |
| Recorded state | Inside CloudFormation, per stack | Inside CloudFormation, per stack | A state file you store (S3 with locking) |
| Preview | Change set | cdk diff (shows the template difference, and can create a change set) | terraform plan (saved plan file) |
| Failed apply | Automatic rollback to last good state (by default) | Same as CloudFormation | No rollback; partial apply stays, you fix and re-apply |
| Drift detection | Built in (drift detection API and console) | Same as CloudFormation | terraform plan / plan -refresh-only compare state and real world |
| Multi-account | StackSets, cross-account roles | CDK Pipelines, bootstrap trust, StackSets | Provider aliases, assume-role per workspace or pipeline |
| Beyond AWS | No (AWS and some registry extensions) | No for AWS constructs | Yes: thousands of providers (SaaS, other clouds, Kubernetes) |
| Day-one coverage of new AWS features | Usually same day or soon after launch ⚠ VERIFY per feature | Follows CloudFormation; L2 constructs may lag, L1 constructs appear with CloudFormation | AWS provider follows the API; often within days, and some features lag |
| Testing | cfn-lint, Guard, taskcat | Unit tests in xUnit, snapshot tests, cdk-nag | terraform test, Checkov, tflint |
Honest limitations:
- CloudFormation: verbose; logic is limited to conditions, mappings and
Fn::functions; reuse is clumsy (nested stacks and modules). - CDK: an abstraction on top of an abstraction. When something fails you read an error about a CloudFormation resource that you did not write by hand. Construct libraries move quickly, and upgrades need care.
- Terraform: you own state. Locking, encryption, access and recovery are your job (see Terraform state). A failed apply leaves a half-built environment that you must reason about.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS equivalent | What's different |
|---|---|---|
| ARM templates | CloudFormation templates | Both are JSON/YAML engines owned by the cloud vendor; both keep deployment history in the service |
| Bicep | AWS CDK (C#) | Bicep is a nicer syntax that compiles to ARM; the CDK is full C# that compiles to CloudFormation, so you get loops, types, unit tests and NuGet packages |
| Terraform with azurerm | Terraform with the AWS provider | Identical tool and workflow; only the provider and the resource names change |
| Azure Deployment Stacks | CloudFormation stacks | Both group resources for lifecycle and deletion |
| What-if | Change set / terraform plan / cdk diff | Always read the preview before approving |
| Azure Resource Graph for drift hunting | CloudFormation drift detection / Config | CloudFormation drift is per stack; AWS Config is account-wide |
| Pulumi (C#) | CDK (C#) or CDK for Terraform | Pulumi and the CDK both let you write C#. CDK for Terraform was announced as sunset by HashiCorp ⚠ VERIFY current status before choosing it |
If your team already uses Bicep and likes it, the closest AWS feeling is the CDK: a typed language over the vendor engine. If your team uses Terraform on Azure, Terraform on AWS will feel familiar within a day.
Architecture
The three paths to the same stack of resources:
Security-boundary view. In the CloudFormation and CDK paths, the deploying identity needs permission to call CloudFormation, which then acts with a service or execution role. You can give the pipeline a narrow "may deploy stacks" permission and keep the powerful execution role separate. In Terraform the identity that runs apply makes the AWS API calls itself, and also needs access to the state bucket. That identity therefore needs the union of all permissions the configuration requires. Both are manageable, but the shape of the least-privilege role is different (see Policy-as-code and secure deployment).
Step-by-step implementation
Read the same bucket in three tools
Open the three code listings below side by side. Count the resources you wrote by hand: CloudFormation two (the bucket carries most settings inline, plus the policy), CDK two constructs (a key and an L2 bucket that expands to several resources), Terraform six.
Preview each one without deploying
CloudFormation: aws cloudformation validate-template for syntax, and a change set to preview against a real account. CDK: cdk synth and cdk diff. Terraform: terraform plan. Note what each shows you and what it does not (none of them proves the IAM permissions will be sufficient).
Define your criteria and weights
Write down the five to eight things that matter to your team, and give each a weight from 1 to 5. Do this before you look at scores, otherwise you will pick weights that favour the tool you already prefer.
Score and compare
Run the C# decision scorer, then change one assumption (for example "we will run a second cloud") and watch the ranking move.
Write the ADR
Record the context, options, decision, consequences and the trigger that would make you revisit the decision. One page, in the repository, reviewed like code.
AWS Console instructions
You compare tools in an editor, not the console, but you will look at the result of CloudFormation-based tools there:
- Console → CloudFormation → Stacks, choose a stack deployed by the CDK. The Template tab shows the generated YAML or JSON. Compare its size with your C# source.
- Stack info → Drift (and Stack actions → Detect drift) shows what CloudFormation reports. Terraform has no equivalent screen; its "drift report" is the output of
plan. - Console → CloudFormation → Stacks → Change sets shows the preview CloudFormation computed. A
terraform planis the same idea, held in your pipeline instead.
AWS CLI
# CloudFormation: syntax check a template (does not call any resource APIs)
aws cloudformation validate-template --template-body file://bucket.yaml --profile learn-sandbox
# CloudFormation: preview a change by creating a change set, then read it
aws cloudformation create-change-set --stack-name hl-m10-l11 --change-set-name preview \
--template-body file://bucket.yaml --change-set-type CREATE \
--parameters ParameterKey=BucketName,ParameterValue=hl-m10-l11-cfn-111122223333 \
ParameterKey=KmsKeyArn,ParameterValue=arn:aws:kms:us-east-1:111122223333:key/11111111-2222-3333-4444-555555555555 \
--tags Key=Project,Value=cea-lab Key=Lab,Value=m10-l11 Key=Environment,Value=learn Key=Owner,Value=your-name \
--profile learn-sandbox
aws cloudformation describe-change-set --stack-name hl-m10-l11 --change-set-name preview \
--query "Changes[].ResourceChange.[Action,LogicalResourceId,Replacement]" --output table \
--profile learn-sandbox
# CDK: generate the template and see the diff against what is deployed
cdk synth
cdk diff
# Terraform: preview and save the plan
terraform plan -out=tfplanInfrastructure as Code
The same encrypted, versioned, private bucket in all three tools. The bucket policy that refuses plain HTTP is generated by EnforceSSL in the CDK, and written out in the other two.
AWSTemplateFormatVersion: "2010-09-09"
Description: Harbourline secure audit bucket (lesson 11 comparison)
Parameters:
BucketName:
Type: String
AllowedPattern: "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$"
KmsKeyArn:
Type: String
Description: ARN of the customer managed key used for SSE-KMS.
Resources:
AuditBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
BucketName: !Ref BucketName
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
ServerSideEncryptionByDefault:
SSEAlgorithm: "aws:kms"
KMSMasterKeyID: !Ref KmsKeyArn
AuditBucketTlsOnly:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref AuditBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: DenyInsecureTransport
Effect: Deny
Principal: "*"
Action: "s3:*"
Resource:
- !GetAtt AuditBucket.Arn
- !Sub "${AuditBucket.Arn}/*"
Condition:
Bool:
"aws:SecureTransport": "false"
Outputs:
BucketArn:
Value: !GetAtt AuditBucket.ArnWhat the three listings tell you:
- The CDK version is shortest because the L2
Bucketconstruct bundles the policy, ownership and public access block behind properties. The cost is that the generated template is larger than your source and you must know whatEnforceSSL = truecreates. - The CloudFormation version shows everything and is easy to read in an audit, but you repeat yourself in every template.
- The Terraform version spells out each setting as its own resource (the AWS provider split S3 settings into separate resources).
prevent_destroyprotects against a Terraform destroy only; it does not stop someone deleting the bucket in the console, whereasDeletionPolicy: Retainprotects against a stack delete.
Decision criteria for a bank
| Criterion | Question to ask | Why a bank cares |
|---|---|---|
| Team skills | Do your engineers write C# all day? Do they already know HCL? | The best tool is one your team can review confidently |
| Review evidence | What artefact do reviewers and auditors read? | Change set, cdk diff or saved plan should attach to the change ticket |
| Failure behaviour | What happens when an apply fails halfway? | Automatic rollback is valuable for a payment system; a half-applied Terraform run needs a runbook |
| State handling | Who owns state, and how is it protected? | State can contain secrets; a managed service removes a class of risk |
| AWS coverage | How quickly are new services usable? | Matters when you need a new security feature quickly |
| Multi-cloud | Do you really run workloads on another cloud, or SaaS you want to manage as code? | Terraform's real advantage; do not pay for it if you do not use it |
| Testing | Can you unit test infrastructure with your normal test framework? | The CDK in C# lets you use xUnit; Terraform has terraform test |
| Ecosystem and licence | What is the licence and the vendor risk? | See below |
| Multi-account rollout | How do you push a baseline to 80 accounts? | StackSets and Control Tower use CloudFormation natively |
| Hiring and support | Who can you hire? What does AWS Support help with? | AWS Support can look at your CloudFormation stack events directly; it cannot see your Terraform state |
Multi-cloud, honestly
"Terraform is multi-cloud" is true in a narrow sense: the tool and the language are the same, but the resources are not. An aws_instance and an azurerm_linux_virtual_machine are different resources with different arguments. You reuse the workflow and the skills, not the code. Terraform is genuinely valuable when you manage things that are not AWS in the same pipeline: DNS providers, identity platforms, monitoring SaaS, Kubernetes. If your bank is AWS-only for infrastructure, multi-cloud should carry little weight.
Licensing and vendor risk
HashiCorp changed Terraform's licence from MPL to the Business Source License in 2023, and the community fork OpenTofu (governed by the Linux Foundation) continues under an open licence ⚠ VERIFY current licence terms and OpenTofu compatibility before you decide. The CDK and CloudFormation tooling are published by AWS under open-source licences for the CLI and libraries; the CloudFormation service itself is a managed service. A bank's legal and procurement teams should review licence terms for any tool, not just Terraform.
Skills and staffing
A C# team writing CDK in C# keeps its IDE, debugger, NuGet, code review habits and xUnit. Terraform adds a second language and a second toolchain, but one that many infrastructure engineers already know. A mixed approach is common and legitimate: CloudFormation or CDK for the AWS landing zone and platform baseline (because StackSets, Control Tower and AWS Support all speak CloudFormation) and Terraform for the parts that include non-AWS providers. The failure mode is not the mix; it is having no written rule for who uses what.
Complete code
A tiny scorer in a single file. Save as decision.cs and run dotnet run decision.cs with .NET 10 (file-based apps), or use the Docker image shown below. It is deliberately small: the value is in the conversation about weights, not the arithmetic.
// A transparent weighted decision matrix. Weights and scores are 1 (poor) to 5 (strong).
// Edit the numbers to match YOUR team; the defaults describe a C#-heavy, AWS-only bank platform team.
var weights = new Dictionary<string, int>
{
["Team C# skills"] = 5,
["Failure rollback"] = 4,
["Managed state (no state file to protect)"] = 3,
["Multi-account baseline (StackSets, Control Tower)"] = 4,
["Unit testing with xUnit"] = 4,
["Manages non-AWS providers"] = 1,
["Readable audit evidence"] = 4,
};
var scores = new Dictionary<string, Dictionary<string, int>>
{
["CloudFormation"] = new()
{
["Team C# skills"] = 2, ["Failure rollback"] = 5, ["Managed state (no state file to protect)"] = 5,
["Multi-account baseline (StackSets, Control Tower)"] = 5, ["Unit testing with xUnit"] = 2,
["Manages non-AWS providers"] = 1, ["Readable audit evidence"] = 4,
},
["AWS CDK (C#)"] = new()
{
["Team C# skills"] = 5, ["Failure rollback"] = 5, ["Managed state (no state file to protect)"] = 5,
["Multi-account baseline (StackSets, Control Tower)"] = 4, ["Unit testing with xUnit"] = 5,
["Manages non-AWS providers"] = 1, ["Readable audit evidence"] = 3,
},
["Terraform"] = new()
{
["Team C# skills"] = 2, ["Failure rollback"] = 2, ["Managed state (no state file to protect)"] = 2,
["Multi-account baseline (StackSets, Control Tower)"] = 3, ["Unit testing with xUnit"] = 2,
["Manages non-AWS providers"] = 5, ["Readable audit evidence"] = 4,
},
};
// Refuse silent mistakes: every tool must be scored on every criterion, within range.
foreach (var (tool, toolScores) in scores)
{
foreach (var criterion in weights.Keys)
{
if (!toolScores.TryGetValue(criterion, out var s) || s is < 1 or > 5)
{
throw new InvalidOperationException($"{tool}: missing or out-of-range score for '{criterion}'.");
}
}
}
var maxPossible = weights.Values.Sum() * 5;
var ranking = scores
.Select(t => new
{
Tool = t.Key,
Total = weights.Sum(w => w.Value * t.Value[w.Key]),
})
.OrderByDescending(r => r.Total)
.ToList();
Console.WriteLine($"{"Tool",-18} {"Score",6} {"Percent",8}");
foreach (var r in ranking)
{
Console.WriteLine($"{r.Tool,-18} {r.Total,6} {100.0 * r.Total / maxPossible,7:F0}%");
}
var gap = ranking[0].Total - ranking[1].Total;
Console.WriteLine();
Console.WriteLine(gap <= 5
? "The top two are within 5 points. Treat this as a tie and decide on the criteria you did not model."
: $"{ranking[0].Tool} leads by {gap} points. Check which single weight would have to change to flip the result.");Run it in Docker with no local .NET install:
# Run from the folder that contains decision.cs
MSYS_NO_PATHCONV=1 docker run --rm -v "$PWD:/work" -w /work mcr.microsoft.com/dotnet/sdk:10.0 dotnet run decision.csCode explained line by line
weightscaptures what your team values. Weights add up; the scorer multiplies each weight by each score. Changing "Manages non-AWS providers" from 1 to 5 is the single edit that flips the ranking for a team that manages many SaaS providers.scoresis a nested dictionary: tool, then criterion, then a number from 1 to 5. The defaults are an opinion, not a measurement. Argue about them with your team.- The validation loop throws if any score is missing or outside 1 to 5. A matrix with a blank cell silently favours whichever tool happened to be filled in.
maxPossibleconverts totals to percentages. A tool at 60 percent is not "bad"; it only tells you the relative fit to your criteria.gap <= 5encodes a practical rule: a difference that small is within the noise of subjective scoring. When that happens, decide on something the matrix cannot capture (for example the existing pipeline).
Security considerations
⚠ Learning shortcut — not for production
The scorer is a conversation aid. It is not a substitute for a security architecture review, a threat model or a proof-of-concept deployment in a sandbox account. In a bank, the tool decision also needs sign-off from security, risk and vendor management.
- Deploy identity. Whichever tool you pick, the identity that deploys production must be a pipeline role, not a human with administrator rights.
- State and templates are sensitive. A CloudFormation template can include parameter values; Terraform state can contain secrets. Treat CloudFormation stack parameters (use
NoEchoand dynamic references to Secrets Manager) and state files (encrypted bucket, narrow access) as confidential. - Do not let tool choice change your controls. The same SCPs, tagging policy, encryption and logging requirements apply to all three. A tool that makes a control hard to apply is a reason to improve the module or construct, not to skip the control.
- Supply chain. Provider plugins, CDK libraries and registry modules are third-party code. Pin, scan and review them.
- Compliance note. Using any IaC tool produces evidence of change control; it does not make you compliant with PCI DSS or UK GDPR. Your compliance team decides which evidence satisfies which requirement.
Banking use case
Harbourline's platform team writes an ADR after a six-week proof of concept. The accounts API team builds the Accounts environment in both CDK (C#) and Terraform (you do exactly this in the module exercise). The scoring shows CDK in C# ahead for the application teams, because the engineers already write C#, CloudFormation rollback suits a payments service, and xUnit tests run in the same pipeline as the application tests. The same ADR records an exception: the security tooling account uses Terraform because it also manages an external SIEM provider and a DNS provider. The ADR names an owner, lists the trigger for revisiting the decision (a second cloud workload, or a licence change) and is reviewed yearly.
Common mistakes
- Choosing by popularity. "Everyone uses Terraform" is a fact about the market, not about your team's skills or constraints.
- Choosing by the demo. A ten-line CDK example always looks shorter than a hundred-line template; compare real, complete environments.
- Mixing tools without a boundary. A stack that Terraform creates and the CDK modifies is a recipe for conflicts. Assign each resource to exactly one tool.
- Ignoring rollback behaviour. In Terraform a failed apply may leave half the environment created. Plan for it with smaller state files, saved plans and a runbook.
- Forgetting the exit cost. Moving from one tool to another later means importing or recreating resources. Keep modules and constructs small and well tested so migration is possible.
- Never writing it down. An unwritten decision is re-argued every year.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The scorer throws "missing or out-of-range score" | A criterion in weights has no entry for a tool, or a score is 0 or 6 | Add the missing score; keep scores between 1 and 5 |
dotnet run decision.cs says the file is not a project | Older SDK (before .NET 10) | Use the mcr.microsoft.com/dotnet/sdk:10.0 image, or create a console project and paste the code |
cdk diff shows replacements you did not expect | A construct change altered a logical ID or an immutable property | Read the diff carefully; set an explicit physical name or logical ID override only after understanding the impact |
validate-template passes but the stack fails to create | Validation checks syntax only | Preview with a change set in a sandbox and read the stack events |
| Terraform plan wants to replace a resource CloudFormation created | The resource was created by another tool and is unmanaged here | Import it into Terraform state, or leave it with the original tool |
Resource ... already exists creating the same bucket in two tools | Both tools target the same physical name | Use distinct names per tool in the comparison exercise (for example a -cfn, -cdk, -tf suffix) |
Cost and cleanup
This lesson costs nothing: you compare code and run a local program. If you choose to deploy the three versions of the bucket to compare previews, each uses a KMS key and an empty bucket (about 1 USD per month for a key, prorated) and takes minutes. ⚠ VERIFY current KMS pricing.
# Only if you deployed the comparison buckets:
aws cloudformation delete-stack --stack-name hl-m10-l11-cfn --profile learn-sandbox
cdk destroy --all
terraform destroy # remove "prevent_destroy" first, or the destroy is refused (that is the point of it)
# Check nothing tagged for this lesson remains
aws resourcegroupstaggingapi get-resources \
--tag-filters Key=Lab,Values=m10-l11 \
--profile learn-sandbox --region us-east-1 \
--query "ResourceTagMappingList[].ResourceARN"The CloudFormation and CDK versions use DeletionPolicy: Retain / RemovalPolicy.RETAIN, so the bucket survives a stack delete by design. Delete it yourself with aws s3 rb s3://<bucket> --force after you have confirmed it is empty and yours.
Exercises
- 🟢 Guided: run the scorer. Then change only the weight of "Manages non-AWS providers" from 1 to 5 and re-run. Record which tool wins and by how much.
- 🟡 Challenge: add two criteria that matter to your own team (for example "Local developer experience on Windows" and "Vendor support"). Re-score all three tools honestly, and write two sentences explaining each score you gave.
- 🔴 Live problem: the head of engineering messages you: "We are acquiring a fintech that runs entirely on Terraform on Azure and GCP. Do we now standardise on Terraform for everything?" Write a one-page reply that separates what changes (a second cloud, a skills pool) from what does not (your AWS landing zone and StackSets), proposes a boundary rule, and names what evidence would make you revisit it.
Assignment
Write docs/adr/0010-iac-tool-choice.md in your portfolio repository. Sections: Context, Options considered (the three tools, plus "mixed"), Criteria and weights (paste the scorer output), Decision, Consequences (positive and negative), Review date and trigger. Keep it to one page. Mark any claim you did not verify with ⚠ VERIFY.
Solutions
With the default numbers the total possible is 125. CDK scores 109 (87 percent), CloudFormation 90 (72 percent) and Terraform 65 (52 percent). Raising the weight of "Manages non-AWS providers" from 1 to 5 adds 4 points to CDK (it scores 1 there) and 20 points to Terraform (it scores 5), so the gap narrows from 44 to 28 but does not close. The lesson: one high-weight criterion can matter, but a tool that is weak on several criteria you care about every day (skills, rollback, state) is not rescued by one strength. A team that truly manages ten non-AWS providers should raise that weight and lower the C# skills weight; that is a different team and a different answer.
There is no single right answer. A strong response gives scores with reasons: for example "Windows developer experience: CDK 4 (works in Visual Studio with the same debugger; needs Node.js installed for the CLI), Terraform 3 (needs the CLI or Docker; HCL editor support is good), CloudFormation 3 (YAML plus lint tools)". The point is that every score has a reason a colleague can challenge. If you give the same score to all three, the criterion does not discriminate and should be removed.
For the live problem, a sound reply says: standardising the language for all clouds is not the same as standardising the AWS landing zone. Keep AWS baseline in CloudFormation/CDK where StackSets and Control Tower integrate natively, let the acquired teams keep Terraform for Azure and GCP, allow Terraform for AWS workload accounts owned by the acquired team under the same policy checks and tagging, and revisit in twelve months with data (incident counts, change lead time, review effort).
Knowledge check
Answer: inside the CloudFormation service, per stack. There is no state file for you to store. Terraform is the one with a state file you must protect; the CDK uses CloudFormation, so it has no state file either.
Answer: a CloudFormation template (plus assets metadata) in cdk.out. The CDK does not call AWS resource APIs itself; CloudFormation does the deployment.
Answer: they stay, and state records them. Terraform does not roll back automatically. You fix the cause and run apply again, or destroy. CloudFormation, by contrast, rolls a failed stack create or update back to the last good state by default.
Answer: CloudFormation (and therefore the CDK, which deploys through it). Terraform shows drift when you run plan or plan -refresh-only, but there is no separate drift service.
Answer: no, not on its own. The tool and language are shared, but resources are provider-specific. It becomes a strong reason when you manage non-AWS providers (SaaS, DNS, another cloud) from the same pipeline.
Interview questions
- Which IaC tool would you pick for a new AWS-only banking platform with a C# team, and why? CDK in C# is a strong default: same language and test framework, CloudFormation rollback and drift detection, no state file to protect, and native fit with StackSets and Control Tower. Say what would change your mind (a second cloud, existing Terraform investment) and that you would write it in an ADR.
- What are the downsides of the CDK? An extra abstraction layer, generated templates that are larger than the source, construct upgrades that can change logical IDs, and a Node.js dependency for the CLI.
- How does Terraform's state file affect your security design? It must be encrypted, versioned, access-controlled and locked, because it maps your estate and can hold secrets. See the state lesson.
- Can you use the CDK and Terraform in the same account? Yes, with a strict ownership rule: each resource belongs to exactly one tool, with the boundary documented, and shared values passed via SSM parameters or outputs.
Certification practice
A team of C# developers wants to define AWS infrastructure in a language they already use, unit test it, and still get automatic rollback and built-in drift detection. Which choice best fits?
A. Terraform with the AWS provider. B. AWS CDK in C#, deployed through CloudFormation. C. Hand-written shell scripts calling the AWS CLI. D. The AWS console with saved screenshots as documentation.
Answer: B. The CDK synthesises CloudFormation, so rollback and drift detection come from the service, and C# plus xUnit give typed code and tests. A has no automatic rollback. C and D are not declarative infrastructure as code.
An organisation with 60 accounts wants to deploy a baseline set of IAM roles and Config rules to every account and to new accounts automatically as they are created, using an AWS-native service. Which approach fits?
A. Run terraform apply manually from each engineer's laptop for each account.
B. Use CloudFormation StackSets with service-managed permissions targeting an organizational unit, with automatic deployment enabled.
C. Email the template to each account owner.
D. Create a Lambda function that logs in to each account's console.
Answer: B. Service-managed StackSets integrate with AWS Organizations and can auto-deploy to new accounts in the target OU. A and C do not scale or give central control; D is not a supported or secure pattern.
Completion checklist
- I can state where state lives, how a change is previewed and what happens on failure for all three tools
- I read the same bucket in CloudFormation, CDK and Terraform and listed what each hides
- I ran the scorer and changed at least one weight to see the ranking move
- I drafted an ADR with a review trigger
- I deleted anything I deployed and confirmed nothing is still billing
Key takeaways
- All three tools are credible. They differ in language, in where state lives, in failure behaviour and in ecosystem.
- Choose from explicit weighted criteria for your team, write the decision down, and name what would make you revisit it.
- For a C# AWS-only bank platform team, the CDK is a strong default; Terraform earns its place when you manage non-AWS providers.
- A mixed estate is fine if every resource has exactly one owner tool.
- "Multi-cloud" lets you reuse a workflow and skills, not code.
Further reading
- What is AWS CloudFormation?
- What is the AWS CDK?
- Terraform language documentation
- AWS Prescriptive Guidance: choosing infrastructure as code tools ⚠ VERIFY the exact page before relying on it
- Previous: Terraform modules · Next: Environment configuration and versioning
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
Lab: one environment, two tools
Define the same NAT-free Fargate and PostgreSQL environment twice, in CDK (C#) and in Terraform, run both test suites without an account, deploy for under an hour, change it through a reviewed diff, detect drift with a tested C# report, destroy everything and write the ADR that picks one tool.
Environment configuration and versioning
Promote the same infrastructure code through dev, test and prod by changing only reviewed configuration, guard production settings with an xUnit test, and tag releases so you can always answer which version is running where.