# 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.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/infrastructure-as-code-(iac)

> 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.

Practice exams covering Infrastructure as code (IaC): [ANS-C01 AWS Certified Advanced Networking - Specialty](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty), [CLF-C02 AWS Certified Cloud Practitioner](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner), [SOA-C03 AWS Certified CloudOps Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate), [DEA-C01 AWS Certified Data Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate), [DVA-C02 AWS Certified Developer - Associate](https://blowstack.com/practice-exams/aws-certified-developer-associate), [DOP-C02 AWS Certified DevOps Engineer - Professional](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional), [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [MLA-C02 (beta) AWS Certified Machine Learning Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate), [SCS-C03 AWS Certified Security - Specialty](https://blowstack.com/practice-exams/aws-certified-security-specialty), [SAA-C03 AWS Certified Solutions Architect - Associate](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate).

## 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.

1. **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.
2. **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.
3. **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.
4. **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.
5. **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.
6. **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 CloudFormation](https://blowstack.com/tools/cloud-services-hub/aws-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 Tower](https://blowstack.com/tools/cloud-services-hub/aws-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 Catalog](https://blowstack.com/tools/cloud-services-hub/aws-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 CodePipeline](https://blowstack.com/tools/cloud-services-hub/aws-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.

### Question 1 (CLF-C02)

**Question:**

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?

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

**Explanation:** 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.

### Question 2 (MLA-C02 (beta))

**Question:**

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?

**Correct 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.

**Explanation:** 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.

### Question 3 (AIP-C01)

**Question:**

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?

**Correct 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.

**Explanation:** 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.

### Question 4 (SOA-C03)

**Question:**

A company uses AWS CodeBuild to run Terraform from a GitHub repository. Pull request builds must run terraform init and terraform validate, including for contributions from outside the company. Production resources must be deployed automatically after reviewed changes are merged into the protected main branch.

Contributors can modify Terraform files, scripts, and buildspec.yml in their pull requests. They cannot change CodeBuild project settings, IAM policies, or branch protection rules, and they have no direct permission to start builds. The company requires that code executed during pull request validation cannot obtain production provisioning permissions, even if a contributor submits malicious build commands.

Which solution meets these requirements?

**Correct answer:** Use separate CodeBuild projects and service roles. Give the pull request validation role no production provisioning permissions and no ability to assume a production deployment role. Configure the production project to deploy only on push events for the protected main branch, and give only its service role the required provisioning permissions.

**Explanation:** Separate projects with separate IAM roles establish a permissions boundary that pull request code cannot change. Malicious validation commands cannot obtain production permissions from their role. Filtering the production project's webhook to push events on the protected main branch ensures that automatic deployments run only after the required review and merge process.

### Question 5 (SCS-C03)

**Question:**

A company deploys application stacks across multiple AWS accounts by using AWS CloudFormation. Each account has a centrally managed CloudFormation service role that can create and manage workload IAM roles under the /applications/ path. Application teams can submit arbitrary templates through an approved deployment process, including templates that create IAM roles with inline policies.

The security team maintains an ApplicationBoundary managed policy in each account. The identity-based permissions of every workload role created by the deployment process must remain limited by this policy, including during subsequent stack updates. Enforcement must not depend on template validation. Application teams and workload roles cannot modify the service role or the ApplicationBoundary policy, and application teams have no direct IAM permissions.

Which change to the CloudFormation service role's permissions meets these requirements?

**Correct answer:** Allow iam:CreateRole only when iam:PermissionsBoundary equals the local ApplicationBoundary policy ARN. Allow iam:PutRolePermissionsBoundary only for that same boundary, and explicitly deny iam:DeleteRolePermissionsBoundary for workload roles.

**Explanation:** The CreateRole condition requires the approved boundary at creation. Restricting PutRolePermissionsBoundary prevents replacement with a different boundary, and denying DeleteRolePermissionsBoundary prevents its removal during updates. Because the boundary policy itself is protected, inline and attached identity policies cannot grant effective permissions beyond its limits.

### Question 6 (DEA-C01)

**Question:**

A company deploys a data validation application and its Amazon CloudWatch Logs log group into new environments by using a version-controlled AWS CloudFormation template. Application log messages contain email addresses in formats supported by CloudWatch Logs sensitive data detection.

The company requires email addresses in newly ingested events to be masked when operations engineers view or query the log group. The remaining message content must remain readable. Authorized security investigators must be able to retrieve the original values. The configuration must be deployed automatically in every new environment before the application starts writing logs, without changing application code or creating a separate sanitized log group.

Which change should the data engineer make to the deployment?

**Correct answer:** Add a DataProtectionPolicy to the AWS::Logs::LogGroup resource with Audit and Deidentify operations for the managed EmailAddress data identifier. Ensure application startup depends on creation of the configured log group.

**Explanation:** A CloudWatch Logs data protection policy can detect and mask supported email addresses while preserving the original data for investigators with logs:Unmask permission. Declaring the policy on the log group makes the configuration repeatable through CloudFormation. Creating the configured group before logging begins is important because masking applies to events ingested after the policy is established.

### Question 7 (DOP-C02)

**Question:**

A company uses AWS CloudFormation to manage an incident-analysis environment. A standalone encrypted Amazon EBS volume contains diagnostic data from a compromised host. The host has been terminated, and the volume is detached.

An incident-response event starts a workflow that updates the stack to provision a clean analysis environment in another Availability Zone. The approved template changes the volume's AvailabilityZone property, which requires replacement. The replacement volume does not need the old data.

The original volume must remain available with its existing volume ID and data for forensic investigation after the update completes. When the analysis stack is eventually deleted, CloudFormation must take a snapshot of the replacement volume and then delete that replacement volume. The workflow must implement these lifecycle requirements through the template, without separate volume-management API calls.

Which configuration should the DevOps engineer include on the EBS volume resource in the template used for the update?

**Correct answer:** Set UpdateReplacePolicy to Retain and DeletionPolicy to Snapshot.

**Explanation:** UpdateReplacePolicy controls the old physical resource when a stack update replaces it. Retain preserves the original volume and its data, while removing that volume from CloudFormation management. DeletionPolicy controls the currently managed replacement volume when the stack is deleted. Snapshot causes CloudFormation to snapshot that EBS volume before deleting it.

### Question 8 (DVA-C02)

**Question:**

A developer maintains an AWS CloudFormation template that defines a Lambda function and its execution role. A CI/CD pipeline deploys the template to separate development and production stacks. A new feature requires the function to send messages to a new SQS queue. Each stack must own its own queue, and the function must receive that queue's URL through an environment variable. The team requires the infrastructure configuration to remain reproducible from the version-controlled template without post-deployment configuration steps. Which change should the developer make?

**Correct answer:** Add an AWS::SQS::Queue resource to the template. Set the function's queue URL environment variable using Ref on the queue, and add sqs:SendMessage permission to the execution role using the queue's Arn attribute from Fn::GetAtt.

**Explanation:** This keeps the queue, function configuration, and permissions in the version-controlled infrastructure definition. For an AWS::SQS::Queue resource, Ref returns the queue URL, and Fn::GetAtt with Arn returns its ARN. Each stack resolves these references to its own queue, and CloudFormation manages the dependencies.

### Question 9 (ANS-C01)

**Question:**

A company uses an AWS CloudFormation template to deploy data-processing VPCs. Each stack manages a public NAT gateway, its dedicated Elastic IP address, and IPv4 default routes from private subnet route tables to the NAT gateway. Each stack also manages an S3 gateway endpoint associated with all private subnet route tables.

Traffic analysis shows that some deployments require access only to Amazon S3 in the same Region. The company wants to eliminate NAT gateway and public IPv4 address charges for those deployments. Other deployments must retain internet access. An engineer adds an InternetEgressEnabled parameter to the shared template. Setting this parameter to false during an existing stack update must remove the NAT gateway, its Elastic IP address, and the private default routes while preserving S3 connectivity. No resources currently have retention policies.

Which template change meets these requirements?

**Correct answer:** Define a condition that evaluates whether InternetEgressEnabled is true. Apply it to the NAT gateway, its Elastic IP address, and every private default route that targets the gateway. Leave the S3 gateway endpoint and its route table associations unconditional.

**Explanation:** CloudFormation deletes existing resources when their resource conditions change from true to false, unless a retention policy prevents deletion. Applying the same condition to the gateway, its address, and its dependent default routes removes the unnecessary resources consistently. The independently managed S3 gateway endpoint retains the endpoint routes needed for same-Region S3 access. Deployments with the parameter set to true retain internet egress.

### Question 10 (SAA-C03)

**Question:**

A company runs a customer-facing application across two Availability Zones. A recent infrastructure update unexpectedly replaced a production resource and caused an outage. Infrastructure changes are currently applied by scripts that issue individual AWS API calls.

The company wants to maintain a version-controlled definition of the complete application infrastructure. Before each production deployment, an engineer must review the proposed resource additions, modifications, and deletions, including whether an update might replace a resource. No production changes may occur until the engineer approves the proposal. The company wants to minimize custom deployment logic.

Which solution meets these requirements?

**Correct answer:** Define the infrastructure in version-controlled AWS CloudFormation templates. Create a change set for each proposed production revision, require an engineer to review and approve it, and execute the change set only after approval.

**Explanation:** CloudFormation manages infrastructure from reusable, version-controlled definitions. Change sets preview proposed additions, modifications, deletions, and potential resource replacements without applying them. Separating change set creation from execution provides the required approval gate with little custom deployment logic.

## 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:

- [SOA-C03](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate): 38 questions
- [DOP-C02](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional): 18 questions
- [DEA-C01](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate): 11 questions
- [CLF-C02](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner): 10 questions
- [ANS-C01](https://blowstack.com/practice-exams/aws-certified-advanced-networking-specialty): 10 questions
- [DVA-C02](https://blowstack.com/practice-exams/aws-certified-developer-associate): 9 questions
- [SCS-C03](https://blowstack.com/practice-exams/aws-certified-security-specialty): 7 questions
- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 6 questions
- [MLA-C02 (beta)](https://blowstack.com/practice-exams/aws-certified-machine-learning-engineer-associate): 4 questions
- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 3 questions

## What is Infrastructure as code (IaC)

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.

- CLF-C02: Infrastructure as code (IaC): repeatable infrastructure deployments (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-repeatable-infrastructure-deployments-clf-c02
- MLA-C02 (beta): Infrastructure as code (IaC): composing connected infrastructure (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-composing-connected-infrastructure-mla-c02
- AIP-C01: Infrastructure as code (IaC): reusable infrastructure components (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-reusable-infrastructure-components-aip-c01
- SOA-C03: Infrastructure as code (IaC): Terraform deployment workflow (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-terraform-deployment-workflow-soa-c03
- SCS-C03: Infrastructure as code (IaC): secure multi-account rollouts (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-secure-multi-account-rollouts-scs-c03
- DEA-C01: Infrastructure as code (IaC): repeatable infrastructure deployments (Premium), https://app.blowstack.com/lessons/infrastructure-as-code-iac-repeatable-infrastructure-deployments-dea-c01
