Infrastructure as Code (IaC) Lab
Modern cloud engineers do not just configure infrastructureβthey define, deploy, validate, and manage infrastructure through code.
Welcome to Lab 23 of the CompTIA Cloud+ practical lab sequence.
In the previous lab, you learned how automation and scripting can perform repetitive cloud operations:
Requirement βScript βCloud CLI / API βResource Operation βValidationThat works well for operational tasks.
But imagine building an entire environment containing:
Virtual Network
Subnets
Security Groups
Virtual Machines
Storage
Load Balancer
Database
MonitoringCreating every component manually introduces:
Manual Configuration βInconsistency βConfiguration Drift βDeployment Errors βOperational RiskInfrastructure as Code provides another approach:
Infrastructure Definition βVersion Control βValidation βDeployment βCloud InfrastructureIn this lab, you will learn how to define and manage cloud infrastructure as code.
π― Mission Information
Section titled βπ― Mission Informationβ| Item | Details |
|---|---|
| Lab | 23 β Infrastructure as Code (IaC) Lab |
| Difficulty | Intermediate |
| Estimated Time | 150β210 Minutes |
| Certification Alignment | CompTIA Cloud+ |
| Primary Focus | Infrastructure as Code |
| Previous Lab | 22 β Cloud Automation and Scripting Lab |
| Career Alignment | Cloud Administrator, Cloud Engineer, DevOps Engineer, Cloud Architect |
| Major Skills | IaC, Templates, Variables, Dependencies, Validation, Drift, Version Control |
| Deliverable | IaC Template + Deployment Plan + Validation Report |
π’ Scenario
Section titled βπ’ ScenarioβYour organization currently deploys cloud environments manually.
A typical deployment requires:
Engineer βCreate Network βCreate Subnets βConfigure Security βCreate VM βConfigure Storage βCreate Load Balancer βConfigure MonitoringDifferent engineers perform these tasks differently.
For example:
Environment A
10.10.0.0/16Encryption EnabledCorrect TagsMonitoring Enabledwhile another deployment contains:
Environment B
10.20.0.0/16Encryption EnabledMissing TagsMonitoring DisabledThe environments are intended to be identical.
But they are not.
Your organization wants:
Standard Architecture βRepeatable Deployment βConsistent Configuration βVersion Control βAuditable ChangesYour mission is to build a basic Infrastructure as Code workflow.
π― Lab Objectives
Section titled βπ― Lab ObjectivesβBy completing this lab, you should be able to:
-
explain Infrastructure as Code
-
understand declarative infrastructure
-
compare imperative and declarative approaches
-
understand IaC templates
-
understand resources
-
use variables and parameters
-
understand outputs
-
understand dependencies
-
understand desired state
-
understand deployment planning
-
understand infrastructure state
-
understand configuration drift
-
create reusable infrastructure definitions
-
understand modules
-
validate IaC configurations
-
identify insecure IaC configurations
-
understand secrets management
-
understand version control
-
understand deployment testing
-
understand rollback
-
understand immutable infrastructure
-
understand infrastructure lifecycle management
-
build an IaC deployment workflow
01 β Understand Infrastructure as Code
Section titled β01 β Understand Infrastructure as CodeβInfrastructure as Code means:
Defining and managing infrastructure using machine-readable configuration rather than relying entirely on manual configuration.
Traditional approach:
Engineer βCloud Portal βClick βConfigure βDeployIaC approach:
Engineer βInfrastructure Code βIaC Engine βCloud API βInfrastructure02 β Why Infrastructure as Code Matters
Section titled β02 β Why Infrastructure as Code MattersβIaC can provide:
Consistency
Repeatability
Automation
Version Control
Standardization
Auditability
ScalabilityInstead of asking:
How was this environment configured?
you can inspect:
Infrastructure Definition03 β Understand the IaC Workflow
Section titled β03 β Understand the IaC WorkflowβA common workflow is:
Requirement βArchitecture βIaC Definition βValidation βPlan βApproval βDeployment βVerification04 β Manual Deployment vs IaC
Section titled β04 β Manual Deployment vs IaCβManual:
Engineer βPortal βResourceIaC:
Template βIaC Engine βCloud API βResourcesCompare:
| Manual | IaC |
|---|---|
| Human-driven | Code-driven |
| Harder to reproduce | Repeatable |
| Difficult to review | Reviewable |
| Configuration differences likely | Standardized |
| Limited version history | Version controlled |
| Manual rollback | Version-based recovery possible |
05 β Understand Imperative Infrastructure
Section titled β05 β Understand Imperative InfrastructureβImperative automation describes:
How to perform the operation.
Example:
Create Network
Create Subnet
Create Security Group
Create VM
Attach StorageThe instructions define the sequence.
06 β Understand Declarative Infrastructure
Section titled β06 β Understand Declarative InfrastructureβDeclarative IaC describes:
What the desired infrastructure should look like.
Example:
Desired State
Network ExistsSubnet ExistsVM ExistsStorage AttachedThe IaC engine determines how to reach that state.
07 β Imperative vs Declarative
Section titled β07 β Imperative vs DeclarativeβIMPERATIVE
Do Step A βDo Step B βDo Step Cversus:
DECLARATIVE
Desired State βIaC Engine βRequired Changes08 β Understand IaC Tools
Section titled β08 β Understand IaC ToolsβCommon IaC technologies include:
Terraform
AWS CloudFormation
Azure ARM Templates
Azure Bicep
Google Cloud Infrastructure ManagerThe syntax differs.
The fundamental concepts remain similar:
Resources
Variables
Dependencies
Outputs
State
Deployment09 β Choose Your Lab Tool
Section titled β09 β Choose Your Lab ToolβFor this lab, you can use an IaC tool available in your environment.
Record:
IaC Tool:
Version:
Cloud Platform:
Environment:
Authentication Method:10 β Verify the IaC Tool
Section titled β10 β Verify the IaC ToolβTerraform example:
terraform versionRecord the version.
11 β Create Your Lab Directory
Section titled β11 β Create Your Lab DirectoryβCreate:
cloudplus-iac-lab/Example:
mkdir cloudplus-iac-labcd cloudplus-iac-labYour project may eventually contain:
cloudplus-iac-lab/ββββ main.tfβββ variables.tfβββ outputs.tfβββ README.md12 β Understand IaC Resources
Section titled β12 β Understand IaC ResourcesβA resource represents infrastructure that should exist.
Examples:
Virtual Network
Subnet
Virtual Machine
Security Group
Storage
Database
Load BalancerConceptually:
resource "resource_type" "resource_name" {
configuration = "value"
}13 β Create Your First Terraform Configuration
Section titled β13 β Create Your First Terraform ConfigurationβCreate:
main.tfA safe local example:
terraform { required_version = ">= 1.0.0"}This allows you to practice the IaC workflow without immediately creating cloud resources.
14 β Initialize the IaC Project
Section titled β14 β Initialize the IaC ProjectβFor Terraform:
terraform initThe initialization process prepares the working directory.
Conceptually:
Configuration βInitialize βProviders / Modules βWorking Environment15 β Validate the Configuration
Section titled β15 β Validate the ConfigurationβRun:
terraform validateExpected:
Configuration ValidIf validation fails:
Error βReview Configuration βCorrect βValidate Again16 β Understand Formatting
Section titled β16 β Understand FormattingβConsistent formatting improves readability.
Terraform:
terraform fmtIaC is code.
Therefore:
Readability and maintainability matter.
17 β Understand Providers
Section titled β17 β Understand ProvidersβIaC tools need a mechanism for interacting with infrastructure platforms.
Conceptually:
IaC Configuration βProvider βCloud API βCloud ResourcesExamples may include providers for:
AWS
Azure
Google Cloud
Kubernetes18 β Understand Authentication
Section titled β18 β Understand AuthenticationβThe provider must authenticate.
IaC Tool βIdentity βAuthentication βAuthorization βCloud API19 β Avoid Administrator Credentials
Section titled β19 β Avoid Administrator CredentialsβDo not automatically use:
Global Administrator
Root Account
Ownerfor routine IaC deployments.
Instead:
Deployment Requirements βRequired Permissions βLeast-Privilege Identity20 β Never Hardcode Cloud Credentials
Section titled β20 β Never Hardcode Cloud CredentialsβPoor:
access_key = "SECRET"secret_key = "SECRET"Avoid embedding credentials directly in infrastructure definitions.
Prefer approved authentication mechanisms.
21 β Understand Variables
Section titled β21 β Understand VariablesβWithout variables:
environment = "development"region = "region-a"repeated throughout the configuration.
Variables allow:
Input βReusable Configuration22 β Create variables.tf
Section titled β22 β Create variables.tfβExample:
variable "environment" { description = "Deployment environment" type = string default = "development"}23 β Add Another Variable
Section titled β23 β Add Another Variableβvariable "project_name" { description = "Project name" type = string default = "cloudplus"}24 β Understand Variable Types
Section titled β24 β Understand Variable TypesβCommon types include:
string
number
bool
list
map
objectExample:
variable "enable_monitoring" { type = bool default = true}25 β Understand Parameterization
Section titled β25 β Understand ParameterizationβInstead of maintaining:
development-template
testing-template
production-templateyou may use:
Reusable Template βParameters βDifferent Environment26 β Example Environment Variables
Section titled β26 β Example Environment Variablesβenvironment
region
network_cidr
instance_size
instance_count
enable_monitoring
backup_enabled27 β Understand Outputs
Section titled β27 β Understand OutputsβOutputs expose useful deployment information.
Examples:
VM IP Address
Load Balancer Address
Resource ID
Network ID28 β Create outputs.tf
Section titled β28 β Create outputs.tfβExample:
output "environment" { value = var.environment}
output "project_name" { value = var.project_name}29 β Understand Dependencies
Section titled β29 β Understand DependenciesβCloud resources frequently depend on other resources.
Example:
Network βSubnet βVMA VM cannot be placed into a subnet that does not exist.
30 β Build the Dependency Graph
Section titled β30 β Build the Dependency GraphβVirtual Network βSubnet βSecurity Controls βCompute βLoad BalancerIaC tools can often infer dependencies from resource references.
31 β Explicit vs Implicit Dependencies
Section titled β31 β Explicit vs Implicit DependenciesβImplicit:
Resource BreferencesResource ATherefore:
AβBExplicit dependencies may be defined when the relationship cannot be inferred automatically.
32 β Understand Desired State
Section titled β32 β Understand Desired StateβSuppose the code defines:
VM Count:2Current environment:
VM Count:1The IaC engine compares:
Current State βDesired State βDifferenceand determines the required action.
33 β Understand Deployment Planning
Section titled β33 β Understand Deployment PlanningβOne of the most important IaC practices is reviewing intended changes before deployment.
Terraform:
terraform planConceptually:
Configuration βCurrent State βComparison βProposed Changes34 β Never Treat the Plan as Noise
Section titled β34 β Never Treat the Plan as NoiseβA plan may indicate:
+ Create
~ Modify
- DeleteDeletion deserves particular attention.
35 β Review Before Apply
Section titled β35 β Review Before ApplyβUse:
Write βValidate βPlan βReview βApplynot:
Write βApply Immediately36 β Understand Apply
Section titled β36 β Understand ApplyβTerraform example:
terraform applyThis can modify real infrastructure.
Only apply configurations in:
Authorized Lab Environmentsand review the plan first.
37 β Build a Safe Deployment Workflow
Section titled β37 β Build a Safe Deployment WorkflowβCode βFormat βValidate βSecurity Check βPlan βReview βApproval βApply βVerify38 β Verify Deployment
Section titled β38 β Verify DeploymentβDo not assume:
IaC Apply Successful=Application WorkingValidate:
Resources Exist
Network Correct
Security Correct
Application Reachable
Monitoring Enabled39 β Understand IaC State
Section titled β39 β Understand IaC StateβSome IaC tools maintain information about deployed resources.
Terraform commonly uses:
StateConceptually:
Configuration +State +Real Infrastructure βChange Calculation40 β Understand Terraform State
Section titled β40 β Understand Terraform StateβState helps Terraform map:
Code Resourceto:
Real Cloud ResourceThis makes state operationally important.
41 β Protect State
Section titled β41 β Protect StateβState may contain:
Resource IDs
Infrastructure Details
Configuration Values
Potentially Sensitive InformationTherefore:
Treat state as sensitive operational data.
42 β Do Not Commit Sensitive State Carelessly
Section titled β42 β Do Not Commit Sensitive State CarelesslyβFor Terraform projects, review whether files such as:
terraform.tfstateshould be stored in the source repository.
Generally, infrastructure code and infrastructure state require different handling.
43 β Understand Remote State
Section titled β43 β Understand Remote StateβTeams may centrally store state to improve:
Collaboration
Consistency
Availability
Controlled AccessConceptually:
Engineer A \ β Remote State /Engineer B44 β Understand State Locking
Section titled β44 β Understand State LockingβImagine:
Engineer AChanges Network
Engineer BChanges Network
Same TimeThis can create conflicts.
State locking can help prevent concurrent modifications where supported.
45 β Understand Configuration Drift
Section titled β45 β Understand Configuration DriftβSuppose IaC defines:
Firewall Rule:Port 443An administrator manually changes the environment:
Firewall Rule:Port 443Port 22Now:
Codeβ Actual EnvironmentThis is:
Configuration drift.
46 β Common Causes of Drift
Section titled β46 β Common Causes of DriftβManual Changes
Emergency Changes
Unmanaged Resources
Incomplete Automation
Multiple Management Tools47 β Detect Drift
Section titled β47 β Detect DriftβUse:
Desired Configuration βCompare βActual Infrastructure βDifferenceA planning operation may help reveal unexpected differences.
48 β Do Not Automatically Correct Every Drift
Section titled β48 β Do Not Automatically Correct Every DriftβExample:
Emergency Security Change βIaC Reverts ChangeThat could be dangerous.
Investigate:
Why Did Drift Occur?
Was It Authorized?
Should Code Be Updated?
Should Infrastructure Be Reverted?49 β Build the Drift Workflow
Section titled β49 β Build the Drift WorkflowβDetect Drift βInvestigate βAuthorized? / \YES NO β βUpdate RestoreCode Desired State50 β Understand Reusable Infrastructure
Section titled β50 β Understand Reusable InfrastructureβPoor design:
1000 LinesRepeatedRepeatedRepeatedBetter:
Reusable Component βParameters βMultiple Deployments51 β Understand Modules
Section titled β51 β Understand ModulesβA module packages reusable infrastructure configuration.
Example:
Network Module
Compute Module
Database Module
Monitoring Module52 β Build a Module Architecture
Section titled β52 β Build a Module ArchitectureβProduction Environment | +---- Network Module | +---- Compute Module | +---- Database Module | +---- Monitoring Module53 β Why Modules Matter
Section titled β53 β Why Modules MatterβModules can improve:
Reusability
Consistency
Maintainability
Standardization54 β Avoid Giant IaC Templates
Section titled β54 β Avoid Giant IaC TemplatesβPoor:
one-file.tf5000 LinesBetter:
main.tf
variables.tf
outputs.tf
network.tf
compute.tf
security.tfor appropriately structured modules.
55 β Understand Naming Standards
Section titled β55 β Understand Naming StandardsβDefine predictable names.
Example:
cloudplus-dev-web-01
cloudplus-dev-db-01
cloudplus-prod-web-01A possible structure:
Project-Environment-Workload-Number56 β Automate Tags Through IaC
Section titled β56 β Automate Tags Through IaCβInstead of manually adding:
Environment
Owner
CostCenterdefine them through code.
Conceptually:
tags = { Environment = "development" Owner = "cloud-team" CostCenter = "IT"}57 β Why IaC Tagging Matters
Section titled β57 β Why IaC Tagging MattersβEvery deployed resource can inherit consistent:
Ownership
Environment
Cost Allocation
Governance MetadataThis connects directly to:
Lab 21 β Cloud Cost Optimization Lab
58 β Build a Standard Tag Set
Section titled β58 β Build a Standard Tag SetβEnvironment
Application
Owner
CostCenter
ManagedByExample:
ManagedBy = IaC59 β Understand IaC Security
Section titled β59 β Understand IaC SecurityβIaC can create insecure infrastructure very quickly.
Example:
Insecure Template βDeploy β100 Insecure ResourcesTherefore:
Security validation must happen before deployment whenever possible.
60 β Identify Insecure Network Definitions
Section titled β60 β Identify Insecure Network DefinitionsβLook for configurations that allow:
0.0.0.0/0 βAdministrative PortExamples might include unnecessary public exposure of:
SSH
RDP
Database Ports61 β Identify Unencrypted Storage
Section titled β61 β Identify Unencrypted StorageβCheck templates for:
Encryption Disabledwhere organizational policy requires encryption.
62 β Identify Public Storage
Section titled β62 β Identify Public StorageβLook for:
Public Access Enabledwhere it is not required.
63 β Identify Excessive IAM Permissions
Section titled β63 β Identify Excessive IAM PermissionsβPoor:
Action = "*"
Resource = "*"where the workload requires only limited permissions.
64 β Identify Hardcoded Secrets
Section titled β64 β Identify Hardcoded SecretsβSearch IaC files for:
password
secret
token
api_key
private_keyDo not assume every occurrence is a secret, but investigate them.
65 β Use Secret Management
Section titled β65 β Use Secret ManagementβPrefer:
IaC βSecret Reference βSecret Management Systeminstead of:
IaC βPlaintext Secret66 β Understand Sensitive Variables
Section titled β66 β Understand Sensitive VariablesβSome IaC tools allow values to be marked sensitive.
This can help reduce accidental display.
But remember:
Marking a variable sensitive does not automatically solve secret storage.
67 β Understand IaC Scanning
Section titled β67 β Understand IaC ScanningβIaC security tools can evaluate configurations before deployment.
Conceptually:
IaC Code βScanner βPolicy / Security Rules βFindings68 β Example IaC Findings
Section titled β68 β Example IaC FindingsβPublic Storage
Open Security Group
Encryption Disabled
Missing Logging
Missing Tags
Excessive Permissions69 β Build an IaC Security Checklist
Section titled β69 β Build an IaC Security Checklistβ[ ] No hardcoded secrets[ ] Encryption enabled[ ] Public exposure minimized[ ] Least privilege applied[ ] Logging enabled[ ] Monitoring enabled[ ] Backups configured[ ] Required tags present[ ] Network rules reviewed[ ] Production safeguards applied70 β Understand Policy as Code
Section titled β70 β Understand Policy as CodeβOrganizations may define infrastructure rules programmatically.
Example:
Infrastructure Definition βPolicy Check βCompliant? / \ YES NO β βDeploy Block71 β Example Policies
Section titled β71 β Example PoliciesβStorage Must Be Encrypted
Public Databases Prohibited
Required Tags Must Exist
Approved Regions Only
Administrative Ports Restricted72 β Understand Version Control
Section titled β72 β Understand Version ControlβIaC should generally be managed as source code.
Example:
Developer βGit βRepository βReview βDeployment73 β Initialize Git
Section titled β73 β Initialize GitβExample:
git initCheck:
git status74 β Create .gitignore
Section titled β74 β Create .gitignoreβTerraform projects commonly exclude generated or sensitive local artifacts as appropriate.
Example:
.terraform/*.tfstate*.tfstate.**.tfvarsReview exclusions according to your projectβs requirements.
75 β Do Not Blindly Ignore Every Variable File
Section titled β75 β Do Not Blindly Ignore Every Variable FileβA variable file might contain:
Region
Environment
Instance Sizeor:
Passwords
SecretsUnderstand what the file contains before deciding how it should be stored.
76 β Create Your First Commit
Section titled β76 β Create Your First CommitβExample:
git add .git commit -m "Create initial Cloud+ IaC lab"77 β Understand Change History
Section titled β77 β Understand Change HistoryβVersion control allows:
Version 1 βVersion 2 βVersion 3You can determine:
Who Changed It?
What Changed?
When?
Why?78 β Use Code Review
Section titled β78 β Use Code ReviewβProduction IaC should not rely only on:
Author βDeployA stronger workflow:
Author βPull Request βReview βValidation βApproval βDeployment79 β Review IaC Changes
Section titled β79 β Review IaC ChangesβReview:
Resource Creation
Resource Modification
Resource Deletion
Network Exposure
IAM Changes
Encryption Changes
Backup Changes80 β Treat Deletion Carefully
Section titled β80 β Treat Deletion CarefullyβA change from:
Database Existsto:
Database Removedmay result in destructive action.
Before approval:
Review Data
Review Backup
Review Dependencies
Review Retention
Confirm Approval81 β Understand Deployment Testing
Section titled β81 β Understand Deployment TestingβBefore production:
Code βValidate βTest Environment βDeploy βVerify82 β Build an IaC Test Environment
Section titled β82 β Build an IaC Test EnvironmentβWhere practical:
Development
or
SandboxUse smaller and lower-cost resources when possible.
83 β Test Repeatability
Section titled β83 β Test RepeatabilityβDeploy:
Environment Ausing the template.
Then deploy:
Environment Busing the same reusable definition with different parameters.
Compare:
Architecture
Security
Tags
Monitoring
Configuration84 β Test Idempotency
Section titled β84 β Test IdempotencyβRun the deployment again without changing the code.
Ideally:
Desired State=Current Statetherefore:
No Unnecessary Changes85 β Test Variable Changes
Section titled β85 β Test Variable ChangesβChange:
instance_count = 1to:
instance_count = 2Run the planning operation.
Observe the proposed infrastructure change before applying it.
86 β Test Resource Removal
Section titled β86 β Test Resource RemovalβRemove a test resource from the configuration.
Run:
terraform planObserve:
Resource Destruction ProposedDo not apply unless the lab resource can safely be destroyed.
87 β Understand Infrastructure Lifecycle
Section titled β87 β Understand Infrastructure LifecycleβInfrastructure commonly moves through:
Define βValidate βDeploy βOperate βModify βReplace βDestroyIaC can manage this entire lifecycle.
88 β Understand Resource Replacement
Section titled β88 β Understand Resource ReplacementβSome configuration changes cannot happen in place.
The IaC tool may need to:
Destroy Old Resource βCreate New Resourceor:
Create Replacement βTransition βRemove Old ResourceReview plans carefully.
89 β Understand Immutable Infrastructure
Section titled β89 β Understand Immutable InfrastructureβTraditional:
Server βModify βModify βPatch βModifyImmutable approach:
New Configuration βBuild New Resource βValidate βReplace Old Resource90 β Benefits of Immutable Infrastructure
Section titled β90 β Benefits of Immutable InfrastructureβPotential benefits include:
Consistency
Predictability
Reduced Drift
Repeatable Deployment91 β Understand Rollback
Section titled β91 β Understand RollbackβSuppose:
IaC Version 2 βDeployment βApplication FailureYou need a recovery strategy.
Conceptually:
Failure βRollback / Forward Fix βValidated State92 β Version Control Is Not the Entire Rollback Plan
Section titled β92 β Version Control Is Not the Entire Rollback PlanβSimply reverting code may not automatically restore:
Deleted Data
Database Contents
Stateful ResourcesTherefore consider:
Backups
Snapshots
Data Recovery
State
Dependencies93 β Build an IaC Rollback Plan
Section titled β93 β Build an IaC Rollback PlanβDocument:
Change:
Resources Affected:
Failure Condition:
Rollback Method:
Backup Required:
State Impact:
Data Impact:
Validation:
Owner:94 β Understand IaC and CI/CD
Section titled β94 β Understand IaC and CI/CDβA mature workflow may look like:
Developer βGit Commit βCI Pipeline βFormatting βValidation βSecurity Scan βPlan βReview βApproval βDeployment95 β Understand CI
Section titled β95 β Understand CIβContinuous Integration can automatically perform:
Syntax Validation
Formatting Checks
Security Scanning
Policy Validation
Testing96 β Understand CD
Section titled β96 β Understand CDβContinuous Delivery/Deployment can help automate infrastructure releases after required checks.
Conceptually:
Approved IaC βDeployment Pipeline βCloud Environment97 β Do Not Automatically Deploy Every Change to Production
Section titled β97 β Do Not Automatically Deploy Every Change to ProductionβHigh-risk infrastructure changes may require:
Review
Approval
Maintenance Window
Rollback Plan98 β Separate Environments
Section titled β98 β Separate EnvironmentsβAvoid mixing:
Development
Testing
Productionwithout appropriate boundaries.
Use:
Separate Parameters
Separate State
Separate Accounts / Projects / Subscriptionswhere architecture requires.
99 β Understand Environment Promotion
Section titled β99 β Understand Environment PromotionβA possible workflow:
Development βTesting βStaging βProductionUse the same validated infrastructure patterns where appropriate.
100 β Understand IaC Documentation
Section titled β100 β Understand IaC DocumentationβYour project should explain:
Purpose
Architecture
Prerequisites
Variables
Deployment
Validation
Rollback
Cleanup101 β Create README.md
Section titled β101 β Create README.mdβInclude:
# Cloud+ IaC Lab
## Purpose
## Architecture
## Prerequisites
## Variables
## Deployment Steps
## Validation
## Security Considerations
## Cleanup102 β Build Your Lab Architecture
Section titled β102 β Build Your Lab ArchitectureβCreate a simple architecture:
Internet | v Load Balancer | +-------+-------+ | | v v Web-01 Web-02 | | +-------+-------+ | v DatabaseInfrastructure components may include:
Network
Public Subnet
Private Subnet
Security Controls
Compute
Load Balancer
Database103 β Define the Network
Section titled β103 β Define the NetworkβConceptually:
NetworkCIDR:10.20.0.0/16104 β Define Subnets
Section titled β104 β Define SubnetsβExample:
Public:10.20.1.0/24
Private:10.20.10.0/24105 β Define Security Controls
Section titled β105 β Define Security ControlsβDesign:
Internet βHTTPS βLoad Balancer βApplication βDatabaseAvoid unnecessary:
Internet βDatabase106 β Define Compute
Section titled β106 β Define ComputeβParameters:
Instance Size
Instance Count
Image
Subnet
Security Controls
Tags107 β Define Storage
Section titled β107 β Define StorageβConsider:
Capacity
Performance
Encryption
Backup
Lifecycle108 β Define Monitoring
Section titled β108 β Define MonitoringβInclude where appropriate:
Metrics
Logs
Alerts
Resource HealthInfrastructure should not become:
Deploy βForget109 β Define Backup Requirements
Section titled β109 β Define Backup RequirementsβConsider:
Backup Enabled
Retention
Recovery RequirementsThis connects with previous Cloud+ labs.
110 β Add Cost Governance
Section titled β110 β Add Cost GovernanceβInclude:
Environment
Owner
CostCenter
Application
ManagedBytags.
111 β Build the Desired Architecture
Section titled β111 β Build the Desired Architectureβ IaC Repository | v Validation | v Plan | v Approval | v Deploy | v +------------------+ | Cloud Environment | +------------------+ | +-----------------+-----------------+ | | | v v v Network Compute Storage | | | +-----------------+-----------------+ | v Monitoring112 β Run Formatting
Section titled β112 β Run FormattingβTerraform:
terraform fmt -recursiveReview changes.
113 β Run Validation
Section titled β113 β Run Validationβterraform validateRecord:
Validation:
PASS / FAIL114 β Run Security Review
Section titled β114 β Run Security ReviewβCheck:
[ ] No plaintext credentials[ ] No unnecessary public access[ ] Encryption enabled[ ] IAM permissions reviewed[ ] Logging configured[ ] Monitoring configured[ ] Required tags present[ ] Backup requirements considered115 β Generate the Deployment Plan
Section titled β115 β Generate the Deployment Planβterraform planReview:
Resources to Add:
Resources to Change:
Resources to Destroy:116 β Review Destructive Changes
Section titled β116 β Review Destructive ChangesβIf:
Destroy > 0ask:
Why?
Expected?
Data Impact?
Backup?
Approved?117 β Deploy to the Lab Environment
Section titled β117 β Deploy to the Lab EnvironmentβOnly after validation and review:
terraform applyUse only resources authorized for the lab.
118 β Validate the Deployed Environment
Section titled β118 β Validate the Deployed EnvironmentβVerify:
[ ] Network exists[ ] Subnets correct[ ] Compute deployed[ ] Security rules correct[ ] Storage configured[ ] Encryption enabled[ ] Tags present[ ] Monitoring operational[ ] Application connectivity works119 β Perform Drift Test
Section titled β119 β Perform Drift TestβIn a disposable lab environment, make a small authorized manual change.
For example:
Change a Non-Critical TagThen run:
terraform planObserve whether the IaC tool identifies the difference.
120 β Restore Desired State
Section titled β120 β Restore Desired StateβDecide whether to:
Update Codeor:
Restore InfrastructureFor this controlled lab, restore the intended configuration.
121 β Test Repeat Execution
Section titled β121 β Test Repeat ExecutionβRun the plan again.
Expected:
No Unexpected ChangesThis demonstrates:
Desired State+Idempotency122 β Perform Cleanup
Section titled β122 β Perform CleanupβWhen the lab environment is no longer required:
terraform plan -destroyReview carefully.
Then, if authorized:
terraform destroy123 β Verify Cleanup
Section titled β123 β Verify CleanupβDo not assume everything disappeared.
Check:
Compute
Storage
Public IPs
Load Balancers
Databases
Snapshots
Network ResourcesThis is important because leftover resources may continue generating cost.
124 β Troubleshooting Scenario β Initialization Fails
Section titled β124 β Troubleshooting Scenario β Initialization FailsβCheck:
Internet Connectivity
Provider Configuration
Tool Version
Authentication
Configuration Syntax125 β Troubleshooting Scenario β Validation Fails
Section titled β125 β Troubleshooting Scenario β Validation FailsβInvestigate:
Syntax
Missing Arguments
Incorrect References
Invalid Variable Types126 β Troubleshooting Scenario β Authentication Fails
Section titled β126 β Troubleshooting Scenario β Authentication FailsβCheck:
Identity
Credential Source
Session
Account / Subscription / Project
Authentication Configuration127 β Troubleshooting Scenario β Permission Denied
Section titled β127 β Troubleshooting Scenario β Permission DeniedβAuthentication may be successful.
Authorization may not be.
Check:
Automation Identity βAssigned Permissions βRequired API Operation128 β Troubleshooting Scenario β Plan Wants to Delete Production Resource
Section titled β128 β Troubleshooting Scenario β Plan Wants to Delete Production ResourceβDo not apply.
Investigate:
Code Change
State
Resource Address
Configuration Drift
Environment Selection129 β Troubleshooting Scenario β Resource Already Exists
Section titled β129 β Troubleshooting Scenario β Resource Already ExistsβDetermine whether it is:
Managed by IaC?
Created Manually?
Part of Another Deployment?Do not blindly recreate or delete it.
130 β Troubleshooting Scenario β Deployment Partially Fails
Section titled β130 β Troubleshooting Scenario β Deployment Partially FailsβReview:
Error
Created Resources
State
Dependencies
Cloud Audit LogsDetermine whether to:
Retry
Correct Configuration
Rollback
Perform Controlled Cleanup131 β Troubleshooting Scenario β Infrastructure Changed Manually
Section titled β131 β Troubleshooting Scenario β Infrastructure Changed ManuallyβThink:
Configuration drift.
Determine whether:
Manual Change Was Authorizedand whether:
Codeor:
Infrastructureshould become the authoritative desired state.
132 β Troubleshooting Scenario β Secret Found in Repository
Section titled β132 β Troubleshooting Scenario β Secret Found in RepositoryβTreat it as potential credential exposure.
Actions may include:
Stop Further Exposure βRotate Credential βRemove Secret from Active Configuration βReview Repository Exposure βInvestigate UsageFollow organizational incident-response procedures.
133 β Troubleshooting Scenario β IaC Deployment Breaks Application
Section titled β133 β Troubleshooting Scenario β IaC Deployment Breaks ApplicationβUse:
Deployment History
Plan
Logs
Monitoring
Application HealthDetermine whether to:
Rollback
or
Forward Fix134 β Troubleshooting Scenario β State File Missing
Section titled β134 β Troubleshooting Scenario β State File MissingβDo not immediately recreate infrastructure.
Investigate:
Remote State
Backups
Repository Configuration
Existing InfrastructureState loss can create serious management problems.
135 β Troubleshooting Scenario β Two Engineers Deploy Simultaneously
Section titled β135 β Troubleshooting Scenario β Two Engineers Deploy SimultaneouslyβRisk:
Conflicting ChangesUse appropriate:
State Locking
Change Control
Deployment Pipeline136 β Troubleshooting Scenario β Destroy Leaves Resources Behind
Section titled β136 β Troubleshooting Scenario β Destroy Leaves Resources BehindβReview:
Manually Created Resources
Dependencies
Protection Settings
Failed Deletions
External Resources137 β Build the IaC Operational Framework
Section titled β137 β Build the IaC Operational FrameworkβRemember:
DESIGN βCODE βFORMAT βVALIDATE βSCAN βPLAN βREVIEW βAPPROVE βDEPLOY βVERIFY βMONITOR βDETECT DRIFT βUPDATE138 β Build the IaC Findings Register
Section titled β138 β Build the IaC Findings Registerβ| Finding | Risk | Recommendation | Priority |
|---|---|---|---|
| Manual Infrastructure Deployment | Configuration Differences | Implement IaC | High |
| Hardcoded Credential | Credential Exposure | Use Secure Authentication | Critical |
| Public Administrative Port | Unauthorized Access | Restrict Network Rule | Critical |
| Encryption Disabled | Data Exposure | Enable Encryption | High |
| Missing Tags | Governance Gap | Define Tags in IaC | Medium |
| No Version Control | Poor Change Tracking | Store IaC in Git | High |
| No Plan Review | Unintended Changes | Review Before Apply | High |
| State Stored Insecurely | Infrastructure Exposure | Secure State | High |
| Manual Changes | Configuration Drift | Implement Drift Management | Medium |
| No Rollback Plan | Recovery Risk | Document Rollback | High |
139 β Create the IaC Deployment Runbook
Section titled β139 β Create the IaC Deployment RunbookβUse:
Runbook:Infrastructure as Code Deployment
Project:
Environment:
Cloud Platform:
IaC Tool:
Repository:
Deployment Identity:
Required Permissions:
State Location:
Variables:
Pre-Deployment Checks:
Formatting:
Validation:
Security Scanning:
Plan:
Plan Review:
Approval:
Deployment:
Post-Deployment Validation:
Monitoring:
Drift Detection:
Rollback:
Cleanup:
Escalation:140 β Create the Final Lab Report
Section titled β140 β Create the Final Lab ReportβUse:
Lab:Infrastructure as Code Lab
Cloud Platform:
IaC Tool:
Tool Version:
Environment:
Architecture:
Resources Defined:
Variables:
Outputs:
Dependencies:
Authentication:
Permissions:
State:
Version Control:
Validation Result:
Security Review:
Deployment Plan:
Resources Added:
Resources Changed:
Resources Destroyed:
Deployment Result:
Post-Deployment Validation:
Drift Test:
Idempotency Test:
Rollback Strategy:
Cleanup Result:
Findings:
Recommendations:
Lessons Learned:π§ͺ Final Validation Checklist
Section titled βπ§ͺ Final Validation Checklistβ| Validation | Status |
|---|---|
| Infrastructure as Code understood | |
| Imperative vs declarative understood | |
| IaC tool verified | |
| Project directory created | |
| Configuration created | |
| Initialization completed | |
| Formatting completed | |
| Validation completed | |
| Resources understood | |
| Providers understood | |
| Authentication reviewed | |
| Least privilege reviewed | |
| Variables created | |
| Outputs created | |
| Dependencies understood | |
| Desired state understood | |
| Deployment planning completed | |
| Destructive changes reviewed | |
| State understood | |
| State protection understood | |
| Configuration drift understood | |
| Modules understood | |
| Naming standard defined | |
| Tagging defined | |
| Security configuration reviewed | |
| Hardcoded secrets checked | |
| IaC scanning understood | |
| Policy as Code understood | |
| Version control configured | |
| Code review understood | |
| Deployment testing performed | |
| Idempotency tested | |
| Infrastructure lifecycle understood | |
| Immutable infrastructure understood | |
| Rollback documented | |
| CI/CD integration understood | |
| Deployment validated | |
| Drift test performed | |
| Cleanup completed | |
| Findings documented |
π― Certification Connection
Section titled βπ― Certification ConnectionβA Cloud+ scenario may say:
Multiple engineers manually create identical environments, but configurations are different.
Think:
Infrastructure as Code and standardized templates.
Another:
The organization wants infrastructure changes reviewed before resources are modified.
Think:
IaC planning and code review.
Another:
An engineer manually changes a firewall rule that is managed by IaC.
Think:
Configuration drift.
Another:
An infrastructure template contains a plaintext administrator password.
Think:
Secret-management failure.
Another:
Infrastructure code gives a workload unrestricted permissions.
Think:
Least-privilege failure.
Another:
Two engineers attempt to modify the same Terraform-managed infrastructure simultaneously.
Think:
Remote state, locking, and controlled deployment workflows.
Another:
The organization wants identical development, testing, and production architectures.
Think:
Reusable templates/modules with environment-specific parameters.
π€ Interview Questions
Section titled βπ€ Interview QuestionsβPractice without notes.
1. What is Infrastructure as Code?
Section titled β1. What is Infrastructure as Code?β2. Why is IaC useful?
Section titled β2. Why is IaC useful?β3. Imperative vs declarative infrastructure?
Section titled β3. Imperative vs declarative infrastructure?β4. What is desired state?
Section titled β4. What is desired state?β5. What is an IaC provider?
Section titled β5. What is an IaC provider?β6. What are variables?
Section titled β6. What are variables?β7. What are outputs?
Section titled β7. What are outputs?β8. Why do dependencies matter?
Section titled β8. Why do dependencies matter?β9. What does terraform init do?
Section titled β9. What does terraform init do?β10. What does terraform validate do?
Section titled β10. What does terraform validate do?β11. What does terraform plan do?
Section titled β11. What does terraform plan do?β12. Why should you review a plan?
Section titled β12. Why should you review a plan?β13. What is Terraform state?
Section titled β13. What is Terraform state?β14. Why should state be protected?
Section titled β14. Why should state be protected?β15. What is remote state?
Section titled β15. What is remote state?β16. What is state locking?
Section titled β16. What is state locking?β17. What is configuration drift?
Section titled β17. What is configuration drift?β18. What is an IaC module?
Section titled β18. What is an IaC module?β19. Why use version control for IaC?
Section titled β19. Why use version control for IaC?β20. How should secrets be handled?
Section titled β20. How should secrets be handled?β21. What is IaC scanning?
Section titled β21. What is IaC scanning?β22. What is Policy as Code?
Section titled β22. What is Policy as Code?β23. What is immutable infrastructure?
Section titled β23. What is immutable infrastructure?β24. How would you test an IaC deployment?
Section titled β24. How would you test an IaC deployment?β25. How would you safely deploy an infrastructure change?
Section titled β25. How would you safely deploy an infrastructure change?βπ¨ Scenario Interview Question 1
Section titled βπ¨ Scenario Interview Question 1βTerraform proposes deleting a production database.
Do not immediately apply.
Review:
Configuration βState βPlan βDatabase Data βBackup βBusiness Impactπ¨ Scenario Interview Question 2
Section titled βπ¨ Scenario Interview Question 2βThe configuration says port 22 is restricted, but the cloud portal shows it open to the internet.
Think:
Configuration drift.
π¨ Scenario Interview Question 3
Section titled βπ¨ Scenario Interview Question 3βA developer commits a cloud access key to an IaC repository.
Treat it as:
credential exposure.
Rotate the credential and follow the organizationβs response process.
π¨ Scenario Interview Question 4
Section titled βπ¨ Scenario Interview Question 4βDevelopment and production need the same architecture but different VM sizes.
Use:
Reusable Infrastructure +Environment Parametersπ¨ Scenario Interview Question 5
Section titled βπ¨ Scenario Interview Question 5βEvery time the configuration is applied, unnecessary resources change.
Investigate:
Idempotency
Provider Behavior
Dynamic Values
State
Configurationπ¨ Scenario Interview Question 6
Section titled βπ¨ Scenario Interview Question 6βEngineers regularly change IaC-managed resources manually.
The organization needs stronger:
Change Management
Drift Detection
IaC Governanceπ¨ Scenario Interview Question 7
Section titled βπ¨ Scenario Interview Question 7βA network module is used by 50 environments.
A change to that module requires:
Impact Analysis
Testing
Versioning
Controlled Rolloutπ¨ Scenario Interview Question 8
Section titled βπ¨ Scenario Interview Question 8βThe IaC deployment completes successfully, but users cannot access the application.
Remember:
Deployment Successβ Application SuccessPerform post-deployment validation.
π§ IaC Interview Framework
Section titled βπ§ IaC Interview FrameworkβRemember:
REQUIREMENT βARCHITECTURE βCODE βVARIABLES βSECURITY βVALIDATE βPLAN βREVIEW βAPPROVE βDEPLOY βVERIFY βMONITOR βDRIFT βLIFECYCLEπ¬ Interview Tip
Section titled βπ¬ Interview TipβAvoid:
βIaC lets us deploy cloud resources automatically.β
A stronger answer is:
βInfrastructure as Code allows infrastructure to be defined in machine-readable configuration and managed through a repeatable software-style lifecycle. I would store the infrastructure definitions in version control, parameterize reusable components, validate and security-scan changes, generate and review the deployment plan, deploy using a least-privilege identity, verify the resulting infrastructure, protect the infrastructure state, monitor for configuration drift, and maintain rollback and recovery procedures for high-risk changes.β
That demonstrates Cloud Engineer and DevOps thinking.
π Portfolio Deliverables
Section titled βπ Portfolio DeliverablesβKeep sanitized versions of:
1. IaC Repository
Section titled β1. IaC RepositoryβInclude:
main.tf
variables.tf
outputs.tf
README.md2. Architecture Diagram
Section titled β2. Architecture DiagramβShow:
Internet βLoad Balancer βCompute βDatabase3. Deployment Plan
Section titled β3. Deployment PlanβDocument:
Add
Change
Destroyoperations.
4. IaC Security Review
Section titled β4. IaC Security ReviewβInclude:
Network Exposure
Encryption
IAM
Secrets
Logging
Tags5. Drift Assessment
Section titled β5. Drift AssessmentβDemonstrate:
Desired State βManual Change βDrift Detection βRemediation6. IaC Deployment Runbook
Section titled β6. IaC Deployment RunbookβDocument the complete deployment lifecycle.
7. IaC Findings Register
Section titled β7. IaC Findings RegisterβInclude:
Finding
Risk
Recommendation
Priorityπ Resume Examples
Section titled βπ Resume ExamplesβInstead of:
Worked with Terraform.
Use:
Built and validated Infrastructure as Code configurations to provision repeatable cloud environments using reusable variables, dependencies, standardized tagging, deployment planning, and configuration-drift management.
Or:
Implemented IaC deployment workflows incorporating version control, configuration validation, security review, change planning, least-privilege deployment identities, post-deployment verification, and rollback procedures.
Or:
Applied Infrastructure as Code practices to standardize cloud networking, compute, storage, security, monitoring, and governance configurations across repeatable cloud environments.
β Job-Readiness Check
Section titled ββ Job-Readiness CheckβYou should now be able to:
-
explain Infrastructure as Code
-
compare imperative and declarative approaches
-
understand desired state
-
understand IaC resources
-
work with variables
-
understand outputs
-
understand dependencies
-
initialize an IaC project
-
validate configurations
-
generate deployment plans
-
review destructive changes
-
understand infrastructure state
-
protect state
-
understand remote state
-
explain state locking
-
detect configuration drift
-
understand reusable modules
-
define naming standards
-
automate tagging
-
identify insecure IaC
-
identify hardcoded secrets
-
understand IaC scanning
-
understand Policy as Code
-
use version control
-
understand code review
-
test IaC deployments
-
test idempotency
-
understand infrastructure lifecycle
-
explain immutable infrastructure
-
design rollback procedures
-
understand CI/CD integration
-
validate deployments
-
safely clean up IaC resources
π Mission Complete
Section titled βπ Mission CompleteβYou have progressed from:
Manual Infrastructure βIndividual Configuration βConfiguration Differencesto:
Infrastructure Definition βVersion Control βValidation βSecurity Review βPlan βDeployment βVerification βDrift ManagementYou now understand an important cloud engineering principle:
Infrastructure should be repeatable, reviewable, testable, and recoverableβnot dependent on someone remembering which buttons they clicked in the cloud portal.
π Whatβs Next?
Section titled βπ Whatβs Next?βYou can now:
Automate Operations +Define Infrastructure as CodeThe next progression is bringing these capabilities into a controlled software delivery workflow.
Instead of:
Engineer βBuild Code βManually Test βManually Deployyou will work toward:
Code βVersion Control βBuild βTest βSecurity Validation βDeployment βMonitoringIn the next lab, you will work with:
-
CI/CD fundamentals
-
source control workflows
-
build pipelines
-
automated testing
-
deployment pipelines
-
pipeline stages
-
artifacts
-
environment promotion
-
approvals
-
secrets management
-
pipeline security
-
deployment strategies
-
rollback
-
pipeline monitoring
-
cloud infrastructure integration
β‘οΈ Next: Lab 24 β Cloud CI/CD Pipeline Lab