Cloud concept · Updated

Infrastructure as code (IaC) - Infrastructure as code (IaC) is the practice of defining and managing infrastructure through machine-readable, version-controlled configuration or code rather than manual setup.

In short

IaC turns infrastructure definitions into repeatable deployment processes that can be reviewed, tested, and automated. It helps engineers create consistent environments, reduce manual errors, and apply security standards across accounts while maintaining a traceable history of changes.

Cloud Concepts Hub →

6 key aspects of Infrastructure as code (IaC)

IaC combines versioned definitions, repeatable lifecycle operations, automated validation, and controlled deployment to manage infrastructure consistently at scale.

01
Version-controlled infrastructure definitions

Store templates, modules, and configuration alongside a reviewable change history. Pull requests make infrastructure changes visible before deployment and help connect deployed configurations to approved revisions.

02
Repeatable provisioning and lifecycle management

Use reusable definitions to create, update, and remove environments through a consistent process. Parameterize legitimate differences rather than maintaining unrelated copies of each environment.

03
Automated validation and security checks

Validate syntax and resource properties, test deployment behavior, and evaluate security policies before provisioning. For CloudFormation, cfn-lint and CloudFormation Guard address different validation needs and can run together in a deployment pipeline.

04
Controlled multi-account deployment

Distribute approved baselines across accounts and Regions using scoped permissions and staged rollouts. Separate account governance from workload deployment so teams understand which controls are centrally enforced and which configurations their templates manage.

05
State and drift awareness

Understand how the chosen tool tracks managed resources and identifies differences between declared and deployed configurations. Investigate manual changes before reconciling them, and protect state storage where the tool uses it.

06
Operational efficiency with deployment safeguards

Automate repetitive provisioning and cleanup to reduce manual work and improve consistency. Combine automation with cost checks, change previews, backups, and approval gates because errors can propagate faster at scale.

Cloud services for Infrastructure as code (IaC)

CloudFormation provides template-driven resource lifecycle management, and StackSets extends that model across accounts and Regions. Control Tower establishes account governance and landing-zone controls, while workload templates and customization workflows supply additional infrastructure. Service Catalog exposes approved configurations through controlled self-service provisioning. CodePipeline connects source changes to testing, approval, and deployment stages; those stages can run cfn-lint and CloudFormation Guard before changes reach production. Together, these services support repeatable delivery, but teams must still define permissions, protect sensitive data, manage drift, and plan for destructive changes.

AWS CloudFormationAWS CloudFormation

CloudFormation provisions and updates AWS resources from templates, grouping managed resources into stacks. Change sets preview proposed stack changes, while StackSets extend template deployment across accounts and Regions; drift detection identifies supported configuration differences.

AWS Control TowerAWS Control Tower

Control Tower establishes a governed multi-account landing zone and supports account provisioning and enrollment of eligible existing accounts. It complements IaC with centrally enabled controls, while account customization workflows can deploy additional organization-specific infrastructure and configurations.

AWS Service CatalogAWS Service Catalog

Service Catalog lets administrators publish approved infrastructure products and control who can provision them. CloudFormation-based products turn reviewed templates into repeatable self-service deployments with defined parameters and constraints.

AWS CodePipelineAWS CodePipeline

CodePipeline orchestrates infrastructure delivery workflows that can include validation, security checks, approvals, and deployment. It coordinates execution stages rather than replacing the IaC engine that provisions resources.

Infrastructure as code (IaC) exam questions

Real practice exam questions on Infrastructure as code (IaC), with the correct answer and its explanation. Answer them with every option in the exam simulator.

CLF-C02

A company maintains separate resource configuration files for its development and production environments. Both environments require the same network and security design, but production needs larger compute and database resources. Engineers spend time applying each design change to both files, and the files sometimes become inconsistent. Which approach would reduce this maintenance effort while preserving the required capacity differences?

Show answerCORRECT ANSWER

Maintain one AWS CloudFormation template and supply environment-specific parameters for compute and database sizes during deployment.

A parameterized template provides one reusable infrastructure design while allowing each environment to use appropriate resource sizes. This reduces duplicate maintenance and the risk of inconsistent changes.

MLA-C02 (beta)

A company deploys fine-tuned foundation models to an Amazon SageMaker AI real-time endpoint through an automated release pipeline. An AWS CloudFormation stack manages the SageMaker model, endpoint configuration, and endpoint. Each release creates a new model resource and changes the model referenced in the endpoint configuration's ProductionVariants property.

The template explicitly sets EndpointConfigName to support-fm-config. During the next release, CloudFormation reports that it cannot replace the endpoint configuration because the resource has a custom name. The application must continue using the existing endpoint name, and subsequent releases must work without manually deleting resources or editing resource names.

Which template change should the ML engineer make?

Show answerCORRECT ANSWER

Remove the explicit EndpointConfigName property and let CloudFormation generate the physical name. Set the endpoint's EndpointConfigName property to Ref the endpoint configuration resource, while preserving the existing endpoint name.

Changes to ProductionVariants require replacement of the endpoint configuration. A CloudFormation-generated name allows a replacement configuration to be created without a naming collision. Ref supplies the new configuration's name to the existing endpoint, allowing CloudFormation to update what the stable endpoint serves without requiring manual naming changes.

AIP-C01

An enterprise runs Amazon Bedrock applications in AWS accounts that belong to a dedicated AWS Organizations organizational unit (OU). A platform team has created a parameterized baseline for application execution roles, encrypted storage, and operational alarms. The baseline must be deployed into two approved AWS Regions in every account in the OU, including accounts added later.

The enterprise requires centrally reviewed infrastructure updates and automatic provisioning when an account joins the OU. The platform team must not maintain deployment execution roles separately in each member account. Development and production accounts must use the same infrastructure definition with approved parameter differences. AWS Organizations has all features enabled.

Which implementation meets these requirements?

Show answerCORRECT ANSWER

Activate trusted access between CloudFormation StackSets and AWS Organizations. Create a service-managed StackSet targeting the OU and both approved Regions, enable automatic deployment, and manage the template and approved parameter overrides through a reviewed deployment pipeline.

Service-managed StackSets use AWS Organizations integration to manage deployment permissions without separately maintained execution roles in each account. OU targeting with automatic deployment provisions stack instances when new accounts join the OU. A shared template, approved parameter overrides, and reviewed updates provide repeatable infrastructure with controlled environment differences.

Practice Infrastructure as code (IaC) in a full exam

Questions on Infrastructure as code (IaC) in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Infrastructure as code (IaC)

3 min read

Infrastructure as code treats infrastructure definitions as engineering artifacts. Instead of manually creating networks, compute resources, databases, and access policies for each environment, engineers describe them in files and use a deployment engine to provision and update them. These definitions can be stored in version control, reviewed through pull requests, and tested before deployment. The approach applies across cloud providers and can also manage on-premises infrastructure.

Many IaC tools are declarative: engineers specify the desired configuration, and the tool determines the necessary operations. Other approaches use imperative code to describe provisioning steps. For example, a reusable definition might create a private network, application servers, a database, and security rules. Parameters allow development and production to use the same design with different capacities and environment-specific values. Repeatability means applying a controlled design consistently, not requiring every environment to have identical settings.

The choice between a management console, programmatic access, and IaC depends on the task. A console is convenient for exploration, troubleshooting, or an isolated operation. APIs, SDKs, and command-line tools support scripts, application integration, and operational automation. IaC is particularly useful when resources must be recreated, updated together, or deployed repeatedly across environments. These options overlap: an engineer can invoke an IaC deployment through a CLI or API. A script that issues resource-creation commands is not automatically a complete infrastructure lifecycle solution; it must still handle dependencies, retries, existing resources, updates, and deletion.

Automation can reduce provisioning time, repetitive labor, and the cost of correcting inconsistent configurations. Disposable test environments can be created when needed and removed afterward. However, IaC does not automatically reduce the cloud bill: automated deployments can also create excessive capacity or duplicate environments rapidly. Cost controls, ownership tags, quotas, and reliable cleanup remain necessary. Building modules, tests, deployment pipelines, and operational expertise also requires an initial investment.

Secure deployment starts with reviewed defaults, such as encryption, restricted network access, and least-privilege roles. In AWS, cfn-lint checks CloudFormation templates against resource specifications and validation rules, while CloudFormation Guard evaluates configurations against policy-as-code rules. These checks complement rather than replace runtime security controls. Keep secret values out of source files, use appropriate secret references, and protect deployment credentials and any IaC state files that may contain sensitive information.

For multi-account deployment, AWS CloudFormation StackSets can distribute a common template across selected accounts and Regions. AWS Control Tower establishes and governs a landing zone, supports account provisioning, and can enroll eligible existing accounts after prerequisites and conflicts are addressed. Optional controls can be enabled for relevant organizational units, with applicability depending on the control. Preventive controls restrict actions, detective controls identify noncompliance, and proactive controls check supported resources before provisioning through CloudFormation. Organization-specific requirements may also need custom policies, configuration rules, or provisioning checks; these are not automatically equivalent to Control Tower's managed controls.

IaC improves consistency but does not guarantee security, idempotency, or safe rollback in every situation. A flawed template can reproduce the same vulnerability across many accounts. Manual changes can cause configuration drift, and drift detection has resource and property coverage limits. Review proposed changes, test in nonproduction accounts, limit deployment permissions, and stage large rollouts. Resource replacement or deletion can destroy data, so retention policies, backups, and recovery procedures remain essential. Third-party tools such as Terraform offer additional workflows and provider coverage, but their state management, locking, and access controls require deliberate design.

Learn Infrastructure as code (IaC) in lessons

10 short lessons on Infrastructure as code (IaC) in 8 certification courses.

and 4 more lessons

Open the lessons