Terraform ConceptCloudFormation EquivalentExplanation
Configuration (HCL files)Template (JSON or YAML)Both define infrastructure as code, but Terraform uses HCL (HashiCorp Configuration Language) which is more readable, while CloudFormation uses JSON or YAML templates familiar to many AWS users.
ResourceResourceBoth define infrastructure components like EC2 instances, S3 buckets, etc., as resources in their respective configs.
State file (terraform.tfstate)Managed state internally by CloudFormationTerraform requires explicit state management via a state file that tracks resource states; CloudFormation manages state automatically within AWS.
Workspace (previously called Environment)StackCloudFormation has the concept of a stack which is an instantiation of a template and can be created multiple times; Terraform has no direct stack concept but uses workspaces to separate state for different environments, though it requires manual switching.
ModuleNested Stack / MacrosTerraform modules are reusable, composable units of infrastructure code; CloudFormation supports nested stacks and macros for modularity, but Terraform’s modules are generally considered more flexible and easier to reuse.
ProviderAWS Service IntegrationTerraform uses providers to interact with different cloud platforms (AWS, Azure, GCP, etc.); CloudFormation is AWS-specific and integrates natively with AWS services.
Plan (terraform plan)Change SetTerraform’s plan command shows all changes before applying; CloudFormation’s Change Sets provide a preview of changes before deployment, but Terraform’s plan is often regarded as more detailed and transparent.
Apply (terraform apply)Stack Update / CreateBoth apply the defined changes to provision or update infrastructure.
Destroy (terraform destroy)Stack DeleteBoth can delete all resources managed by the configuration/stack.
Interpolation / ExpressionsIntrinsic Functions (e.g., Fn::JoinRef)Both support expressions to reference resources and outputs dynamically, though Terraform’s HCL syntax is more expressive and user-friendly.
OutputsOutputsBoth allow defining outputs from the infrastructure for use elsewhere.
ProvisionersCustom Resources / Lambda-backed Custom ResourcesTerraform provisioners run scripts or commands on resources; CloudFormation uses custom resources backed by Lambda functions for similar extensibility.
State LockingStack Locking (via AWS mechanisms)Terraform supports state locking to prevent concurrent changes; CloudFormation inherently prevents concurrent stack updates.
Multi-cloud supportAWS-onlyTerraform supports multiple cloud providers via providers; CloudFormation is AWS-specific.