%3CLINGO-SUB%20id%3D%22lingo-sub-2069350%22%20slang%3D%22en-US%22%3EThe%20benefits%20of%20Infrastructure%20as%20Code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2069350%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20are%20lots%20of%20different%20ways%20you%20can%20deploy%20and%20configure%20your%20Azure%20resources.%20When%20customers%20are%20first%20starting%20their%20cloud%20journey%20it's%20common%20to%20provision%20resources%20manually%2C%20deploying%20and%20configuring%20them%20in%20the%20Azure%20portal.%20However%2C%20this%20quickly%20becomes%20difficult%20to%20manage%20and%20scale.%20Infrastructure%20as%20Code%20(IaC)%20techniques%20and%20tools%20are%20designed%20to%20help%20you%20make%20use%20of%20your%20skills%20with%20coding%20and%20DevOps%20practices%20when%20working%20with%20your%20cloud%20infrastructure.%20However%2C%20I%20frequently%20work%20with%20customers%20who%20aren't%20completely%20convinced%20that%20IaC%20is%20going%20to%20help%20them%2C%20or%20be%20worth%20the%20investment.%20It%20can%20be%20helpful%20to%20have%20some%20insight%20into%20the%20benefits%20that%20many%20other%20customers%20have%20seen%20when%20using%20IaC%20approaches.%20This%20post%20outlines%20the%20main%20reason%20I%20think%20IaC%20is%20an%20essential%20part%20of%20a%20modern%20solution%20for%20Azure.%20We%20won't%20get%20much%20into%20the%20technical%20details%20of%20how%20you%20use%20IaC%20-%20this%20is%20just%20a%20high-level%20overview%20of%20why%20you%20should%20use%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EWhat%20is%20Infrastructure%20as%20Code%3F%3CP%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Flearn%2Fmodules%2Fazure-well-architected-operational-excellence%2F4-use-automation-to-reduce-effort-and-error%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EAzure%20Well-Architected%20Framework%3C%2FA%3E%20has%20a%20great%20definition%20of%20IaC%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3EInfrastructure%20as%20code%20(IaC)%20is%20the%20management%20of%20infrastructure%20-%20such%20as%20networks%2C%20virtual%20machines%2C%20load%20balancers%2C%20and%20connection%20topology%20-%20in%20a%20descriptive%20model%2C%20using%20a%20versioning%20system%20that%20is%20similar%20to%20what%20is%20used%20for%20source%20code.%20When%20you%20are%20creating%20an%20application%2C%20the%20same%20source%20code%20will%20generate%20the%20same%20binary%20every%20time%20it%20is%20compiled.%20In%20a%20similar%20manner%2C%20an%20IaC%20model%20generates%20the%20same%20environment%20every%20time%20it%20is%20applied.%20IaC%20is%20a%20key%20DevOps%20practice%2C%20and%20it%20is%20often%20used%20in%20conjunction%20with%20continuous%20delivery.%3C%2FP%3E%3CP%3EUltimately%2C%20IaC%20allows%20you%20and%20your%20team%20to%20develop%20and%20release%20changes%20faster%2C%20but%20with%20much%20higher%20confidence%20in%20your%20deployments.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EGain%20higher%20confidence%3CP%3EOne%20of%20the%20biggest%20benefits%20of%20IaC%20is%20the%20level%20of%20confidence%20you%20can%20have%20in%20your%20deployments%2C%20and%20in%20your%20understanding%20of%20the%20infrastructure%20and%20its%20configuration.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIntegrate%20with%20your%20process.%20If%20you%20have%20a%20process%20by%20which%20code%20changes%20gets%20peer%20reviewed%2C%20you%20can%20use%20the%20exact%20same%20process%20for%20your%20infrastructure.%20This%20can%20be%20very%20helpful%20when%20a%20team%20member%20might%20be%20proposing%20a%20change%20to%20a%20resource%2C%20but%20they%20don't%20realise%20that%20the%20change%20might%20not%20work%2C%20could%20cause%20issues%20elsewhere%20in%20the%20solution%2C%20or%20may%20not%20meet%20the%20requirements.%20If%20these%20changes%20are%20made%20directly%20in%20the%20portal%20then%20you%20may%20not%20have%20the%20opportunity%20for%20your%20team%20to%20review%20the%20changes%20before%20they%20are%20made.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConsistency.%20Following%20an%20IaC%20process%20ensures%20that%20the%20whole%20team%20is%20following%20a%20standard%2C%20well-established%20process%20-%20regardless%20of%20who%20on%20the%20team%20has%20initiated%20it.%20I%20often%20work%20with%20customers%20who%20have%20a%20single%20designated%20person%20who%20is%20permitted%20to%20deploy%20to%20production%3B%20if%20this%20person%20is%20unavailable%20then%20deployments%20can%20be%20very%20difficult%20to%20complete%2C%20since%20that%20person%20will%20maintain%20all%20the%20knowledge%20in%20their%20head.%20By%20following%20a%20fully%20automated%20process%20you%20can%20move%20the%20knowledge%20of%20the%20deployment%20process%20into%20the%20automation%20tooling%2C%20and%20then%20you%20can%20broaden%20the%20number%20of%20people%20on%20your%20team%20who%20can%20initiate%20deployments%20while%20still%20maintaining%20the%20same%20quality%20level%20-%20and%20without%20giving%20broad%20administrative%20access%20to%20your%20environment.%20Not%20only%20does%20this%20help%20with%20your%20operational%20efficiency%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Farchitecture%2Fframework%2Fsecurity%2Fsecurity-principles%23%3A~%3Atext%3DEmbrace%2520Automation%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Eit%20also%20has%20security%20benefits%20too%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAutomated%20scanning.%20Many%20types%20of%20IaC%20assets%20can%20be%20scanned%20by%20automated%20tooling.%20One%20such%20type%20of%20tooling%20is%20linting%2C%20to%20check%20for%20errors%20in%20the%20code.%20Another%20type%20will%20scan%20the%20proposed%20changes%20to%20your%20Azure%20infrastructure%20to%20make%20sure%20they%20follow%20security%20and%20performance%20best%20practices%20-%20for%20example%2C%20ensuring%20that%20storage%20accounts%20are%20configured%20to%20block%20unsecured%20connections.%20This%20can%20be%20an%20important%20part%20of%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Flearn%2Fmodules%2Fexplore-devops-continuous-security-operations%2F2-explore-continuous-security%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EContinuous%20Security%3C%2FA%3E%20approach.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESecret%20management.%20Every%20solution%20requires%20some%20secrets%20to%20be%20maintained%20and%20managed.%20These%20include%20connection%20strings%2C%20API%20keys%2C%20client%20secrets%2C%20and%20certificates.%20Following%20an%20IaC%20approach%20means%20that%20you%20need%20to%20also%20adopt%20some%20best-practice%20approaches%20to%20managing%20these%20secrets.%20For%20example%2C%20Azure%20has%20the%20Key%20Vault%20service%20to%20maintain%20these%20types%20of%20data.%20Key%20Vault%20can%20be%20easily%20integrated%20with%20many%20IaC%20tools%20and%20assets%20to%20ensure%20that%20the%20person%20conducting%20the%20deployment%20doesn't%20need%20access%20to%20your%20production%20secrets%2C%20which%20means%20you're%20adhering%20to%20the%20security%20principle%20of%20%3CA%20href%3D%22https%3A%2F%2Fus-cert.cisa.gov%2Fbsi%2Farticles%2Fknowledge%2Fprinciples%2Fleast-privilege%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eleast%20privilege%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAccess%20control.%20A%20fully%20automated%20IaC%20deployment%20pipeline%20means%20that%20all%20changes%20to%20your%20Azure%20resources%20should%20be%20done%20by%20an%20automated%20procedure.%20By%20doing%20this%2C%20you%20can%20be%20confident%20that%20all%20changes%20that%20are%20deployed%20to%20your%20Azure%20environment%20have%20followed%20the%20correct%20procedure%2C%20and%20it's%20much%20harder%20for%20bad%20configuration%20to%20make%20its%20way%20through%20to%20production%20accidentally.%20Ideally%2C%20you%20would%20remove%20the%20ability%20for%20humans%20to%20modify%20your%20resources%20at%20all%20-%20although%20you%20may%20allow%20for%20this%20to%20be%20overridden%20in%20an%20emergency%2C%20by%20using%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Factive-directory%2Froles%2Fsecurity-emergency-access%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3E'break%20glass'%20account%3C%2FA%3E%20or%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Factive-directory%2Fprivileged-identity-management%2F%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EPrivileged%20Identity%20Management%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAvoid%20configuration%20drift.%20When%20I%20work%20with%20customers%20to%20adopt%20IaC%20approaches%2C%20I%20recommend%20redeploying%20all%20of%20the%20assets%20on%20every%20release.%20IaC%20tooling%20is%20generally%20built%20to%20be%20idempotent%20(i.e.%20to%20be%20able%20to%20be%20run%20over%20and%20over%20again%20without%20any%20bad%20effects).%20Usually%2C%20the%20first%20deployment%20of%20an%20asset%20will%20actually%20deploy%20the%20asset%2C%20while%20subsequent%20redeployments%20will%20essentially%20act%20as%20'no-ops'%20and%20have%20no%20effect.%20This%20practice%20helps%20in%20a%20few%20ways%3A%3C%2FP%3EIt%20ensures%20that%20your%20IaC%20assets%20are%20regularly%20exercised.%20If%20they%20are%20only%20deployed%20occasionally%2C%20it's%20much%20more%20likely%20they%20will%20become%20stale%20and%20you%20won't%20notice%20until%20it's%20too%20late.%20This%20is%20particularly%20important%20if%20you%20need%20to%20rely%20on%20your%20IaC%20assets%20as%20part%20of%20a%20disaster%20recovery%20plan.%20It%20ensures%20that%20your%20application%20code%20and%20infrastructure%20won't%20get%20out%20of%20sync.%20For%20example%2C%20if%20you%20have%20an%20application%20update%20that%20needs%20an%20IaC%20asset%20to%20be%20deployed%20first%20(such%20as%20to%20deploy%20a%20new%20database)%2C%20you%20want%20to%20make%20sure%20you%20won't%20accidentally%20forget%20to%20do%20this%20in%20the%20right%20order.%20Deploying%20the%20two%20together%20in%20one%20pipeline%20means%20you%20are%20less%20likely%20to%20encounter%20these%20kinds%20of%20'race%20conditions'.%20It%20helps%20to%20avoid%20configuration%20drift.%20If%20someone%20does%20accidentally%20make%20a%20change%20to%20a%20resource%20without%20following%20your%20IaC%20pipeline%2C%20then%20you%20want%20to%20correct%20this%20as%20quickly%20as%20possible%20and%20get%20the%20resource%20back%20to%20the%20correct%20state.%20By%20following%20an%20IaC%20approach%2C%20the%20source%20of%20truth%20for%20your%20environment's%20configuration%20is%20in%20code.%3CP%3E%26nbsp%3B%3C%2FP%3EManage%20multiple%20environments%3CP%3EIaC%20can%20help%20with%20managing%20your%20environments.%20Pretty%20much%20every%20customer%20has%20to%20maintain%20some%20non-production%20environments%20as%20well%20as%20production.%20Some%20customers%20also%20maintain%20multiple%20production%20environments%2C%20such%20as%20for%20multitenanted%20solutions%20or%20for%20geographically%20distributed%20applications.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EManage%20non-production%20environments.%20A%20common%20pain%20point%20for%20customers%20is%20when%20their%20non-production%20environments%20are%20not%20the%20same%20as%20their%20production.%20This%20slows%20down%20testing%20of%20changes%20and%20reduces%20the%20team's%20confidence%20that%20they%20fully%20understand%20and%20what's%20happening%20in%20production.%20This%20configuration%20drift%20will%20often%20happen%20when%20the%20environments%20are%20all%20created%20manually%2C%20and%20someone%20forgets%20to%20apply%20a%20change%20somewhere.%20If%20you%20follow%20an%20IaC%20approach%20then%20this%20problem%20goes%20away%2C%20because%20the%20same%20UaC%20definition%20is%20used%20to%20create%20and%20deploy%20all%20of%20your%20environments%20-%20both%20non-production%20and%20production.%20You%20can%20specify%20different%20configuration%20for%20each%20environment%2C%20of%20course%2C%20but%20the%20core%20definition%20will%20be%20the%20same.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDynamically%20provision%20environments.%20Once%20you%20have%20your%20IaC%20assets%2C%20you%20can%20then%20use%20them%20to%20provision%20new%20environments%20very%20easily.%20This%20can%20be%20enormously%20helpful%20when%20you're%20testing%20your%20solution.%20For%20example%2C%20you%20could%20quickly%20provision%20a%20duplicate%20of%20your%20production%20environment%20that%20can%20then%20be%20used%20for%20security%20penetration%20tests%2C%20for%20load%20testing%2C%20or%20to%20help%20a%20developer%20track%20down%20a%20bug.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EScale%20production%20environments.%20Some%20customers%20have%20the%20requirement%20to%20provision%20multiple%20production%20environments.%20For%20example%2C%20you%20might%20be%20following%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Farchitecture%2Fpatterns%2Fdeployment-stamp%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Edeployment%20stamps%20pattern%3C%2FA%3E%2C%20or%20you%20might%20need%20to%20create%20a%20new%20instance%20of%20your%20solution%20in%20another%20geographical%20region.%20IaC%20assets%20can%20be%20used%20to%20quickly%20provision%20all%20of%20the%20components%20of%20your%20solution%20again%2C%20and%20keep%20them%20consistent%20with%20the%20existing%20environment.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDisaster%20recovery.%20In%20some%20situations%2C%20IaC%20assets%20can%20be%20used%20as%20part%20of%20a%20disaster%20recovery%20plan.%20If%20you%20don't%20need%20to%20keep%20copies%20of%20all%20of%20your%20infrastructure%20ready%20for%20a%20potential%20disaster%2C%20and%20can%20cope%20with%20a%20bit%20of%20downtime%20while%20you%20wait%20for%20your%20IaC%20assets%20to%20provision%20resources%20in%20another%20Azure%20region%2C%20then%20this%20can%20be%20worth%20considering.%20You'll%20need%20to%20be%20careful%20to%20plan%20out%20how%20you%20handle%20disaster%20recovery%20for%20your%20databases%2C%20storage%20accounts%2C%20and%20other%20resources%20that%20store%20state%2C%20though.%20You%20also%20need%20to%20make%20sure%20that%20you%20fully%20test%20your%20disaster%20recovery%20plans%20and%20that%20they%20meet%20your%20requirements%20for%20how%20much%20downtime%20you%20can%20experience%20in%20a%20disaster%20scenario%20(which%20is%20often%20called%20your%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Farchitecture%2Fframework%2Fresiliency%2Fbusiness-metrics%23recovery-metrics%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3ERecovery%20Time%20Objective%3C%2FA%3E).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EBetter%20understand%20your%20cloud%20resources%3CP%3EIaC%20can%20also%20help%20you%20better%20understand%20the%20state%20of%20your%20resources.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAudit%20changes.%20Changes%20to%20your%20IaC%20assets%20will%20be%20version-controlled.%20This%20means%20you%20can%20review%20each%20change%20that%20has%20happened%2C%20as%20well%20as%20who%20made%20it%2C%20and%20when.%20This%20can%20be%20very%20helpful%20if%20you're%20trying%20to%20understand%20why%20a%20resource%20is%20configured%20a%20specific%20way.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMetadata.%20Many%20types%20of%20IaC%20assets%20let%20you%20add%20metadata%2C%20like%20code%20comments%2C%20to%20help%20explain%20why%20something%20is%20done%20a%20particular%20way.%20If%20your%20organisation%20has%20a%20culture%20of%20documenting%20your%20code%2C%20you%20can%20apply%20the%20same%20principles%20to%20your%20infrastructure.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKeep%20everything%20together.%20It's%20pretty%20common%20for%20a%20developer%20to%20work%20on%20a%20feature%20that%20will%20require%20both%20code%20changes%20and%20infrastructure%20changes.%20By%20keeping%20your%20infrastructure%20defined%20as%20code%2C%20you'll%20be%20able%20to%20group%20these%20together%20and%20see%20the%20relationship.%20For%20example%2C%20if%20you%20see%20a%20change%20to%20an%20IaC%20asset%20on%20a%20feature%20branch%20or%20in%20a%20pull%20request%2C%20you'll%20have%20a%20clearer%20understanding%20of%20what%20that%20change%20relates%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBetter%20understand%20Azure%20itself.%20The%20Azure%20portal%20is%20a%20great%20way%20to%20easily%20provision%20and%20configure%20resources%2C%20but%20it%20often%20simplifies%20the%20underlying%20resource%20model%20used.%20Using%20IaC%20will%20mean%20that%20you%20gain%20a%20much%20deeper%20understanding%20of%20what%20is%20happening%20in%20Azure%20and%20how%20to%20troubleshoot%20it%20if%20something%20isn't%20working%20correctly.%20For%20example%2C%20if%20you%20provision%20a%20set%20of%20virtual%20machines%20manually%20in%20the%20Azure%20portal%2C%20you%20may%20not%20realise%20that%20there%20are%20actually%20lots%20of%20separate%20Azure%20resources%20provisioned%20-%20and%20that%20some%20of%20these%20can%20potentially%20be%20shared%2C%20which%20can%20help%20to%20simplify%20your%20ongoing%20operations.%20Another%20example%20is%20that%20when%20you%20provision%20a%20Key%20Vault%20instance%20through%20the%20portal%2C%20the%20person%20creating%20it%20will%20be%20given%20access%20to%20the%20vault%20automatically%20-%20which%20may%20not%20necessarily%20be%20what%20you%20want.%20Using%20IaC%20means%20you%20have%20explicit%20control.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EDeclarative%20and%20imperative%20IaC%3CP%3EBroadly%20speaking%2C%20there%20are%20two%20different%20models%20for%20IaC.%20Imperative%20IaC%20involves%20writing%20scripts%2C%20in%20a%20language%20like%20Bash%2C%20PowerShell%2C%20C%23%20script%20files%2C%20or%20Python.%20These%20programmatically%20execute%20a%20series%20of%20steps%20to%20create%20or%20modify%20your%20resources.%20Declarative%20IaC%20instead%20involves%20writing%20a%20definition%20of%20how%20you%20want%20your%20environment%20to%20look%3B%20the%20tooling%20then%20figures%20out%20how%20to%20make%20this%20happen%20by%20inspecting%20your%20current%20state%2C%20comparing%20it%20to%20the%20target%20state%20you've%20requested%2C%20and%20applying%20the%20differences.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Flearn%2Fmodules%2Fazure-well-architected-operational-excellence%2F4-use-automation-to-reduce-effort-and-error%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EThere's%20a%20good%20discussion%20of%20imperative%20and%20declarative%20IaC%20here.%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20great%20Azure%20tooling%20options%20for%20both%20models.%20For%20imperative%20IaC%20you%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fcli%2Fazure%2F%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EAzure%20CLI%3C%2FA%3E%20or%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fazure%2F%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EPowerShell%20cmdlets%3C%2FA%3E.%20For%20declarative%20IaC%20you%20can%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Ftemplates%2F%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EAzure%20Resource%20Manager%20(ARM)%20templates%3C%2FA%3E%20-%20or%2C%20in%20the%20near%20future%2C%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fbicep%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Ethe%20new%20ARM%20template%20language%20called%20Bicep%3C%2FA%3E%2C%20which%20is%20my%20personal%20favourite%20option.%20Another%20popular%20choice%20is%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2F%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ETerraform%3C%2FA%3E%20-%20there's%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Farchitecture%2Fframework%2Fdevops%2Fautomation-infrastructure%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Egood%20comparison%20of%20ARM%20templates%20and%20Terraform%20in%20the%20Azure%20Well-Architected%20Framework%3C%2FA%3E.%20There%20are%20plenty%20of%20other%20community%20and%20commercial%20tools%20around%20too%2C%20including%20%3CA%20href%3D%22https%3A%2F%2Fwww.pulumi.com%2F%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EPulumi%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20prefer%20using%20declarative%20IaC%20approaches%20-%20it%20can%20sometimes%20be%20a%20little%20tricky%20to%20write%20imperative%20scripts%20that%20will%20work%20consistently%20and%20will%20do%20exactly%20what%20you%20expect%20every%20time.%20I%20also%20feel%20like%20you%20get%20the%20most%20benefit%20out%20of%20IaC%20when%20you%20use%20declarative%20tooling.%20My%20personal%20choice%20is%20to%20use%20ARM%20templates%20(or%20soon%2C%20Bicep)%20for%20my%20IaC.%20However%2C%20the%20choice%20is%20yours.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EHow%20to%20get%20started%20with%20IaC%3CP%3EHopefully%20these%20reasons%20are%20enough%20to%20convince%20you%20that%20IaC%20is%20worth%20the%20initial%20upfront%20investment%20in%20time%20-%20you'll%20need%20to%20be%20prepared%20to%20create%20your%20IaC%20assets%2C%20and%20to%20create%20a%20good%20process%20for%20your%20release%20and%20the%20necessary%20pipelines%20to%20support%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%2C%20explore%20and%20try%20out%20a%20few%20tools%20to%20see%20which%20will%20work%20best%20for%20your%20team.%20If%20you%20don't%20have%20any%20experience%20with%20IaC%20already%20then%20I%20recommend%20you%20start%20using%20Bicep%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fbicep%2Ftree%2Fmain%2Fdocs%2Ftutorial%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Ethere's%20a%20great%20tutorial%20on%20how%20to%20get%20started%3C%2FA%3E.%20Try%20creating%20a%20simple%20dummy%20solution%20to%20see%20how%20the%20end-to-end%20process%20works.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENext%2C%20try%20creating%20some%20IaC%20assets%20for%20your%20actual%20solution.%20How%20do%20this%20will%20depend%20a%20little%20on%20your%20situation%3A%3C%2FP%3EIf%20you're%20working%20on%20a%20brand%20new%20solution%20then%20try%20to%20adopt%20the%20discipline%20of%20only%20deploying%20through%20IaC%20assets%2C%20and%20consider%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-resource-manager%2Ftemplates%2Fdeployment-modes%23complete-mode%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EARM%20template%20'complete'%20deployment%20mode%3C%2FA%3E%20to%20help%20to%20maintain%20this%20discipline.%20If%20you've%20got%20existing%20Azure%20resources%20then%20I%20recommend%20following%20a%20hybrid%20approach%20and%20slowly%20migrating%20to%20IaC%20assets.%20Start%20by%20creating%20IaC%20assets%20for%20a%20few%20small%20pieces%20of%20your%20solution%2C%20get%20those%20working%2C%20and%20then%20add%20more%20and%20more%20until%20you%20have%20are%20deploying%20everything%20in%20code.%20At%20first%2C%20make%20sure%20you%20are%20doing%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-resource-manager%2Ftemplates%2Fdeployment-modes%23incremental-mode%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Eincremental%20deployments%3C%2FA%3E%20so%20that%20you%20don't%20accidentally%20destroy%20any%20existing%20production%20resources%20that%20you%20haven't%20yet%20added%20to%20your%20IaC%20assets.%3CP%3EYou'll%20also%20need%20to%20build%20a%20pipeline%20to%20deploy%20the%20IaC%20assets.%20If%20you%20use%20ARM%20templates%20or%20Bicep%2C%20you%20can%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-resource-manager%2Ftemplates%2Fadd-template-to-azure-pipelines%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Eintegrate%20these%20with%20Azure%20Pipelines%3C%2FA%3E.%20Make%20sure%20that%20any%20new%20resources%20are%20created%20and%20managed%20completely%20within%20your%20IaC%20assets%20and%20deployed%20using%20your%20pipelines.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20should%20also%20remember%20to%20use%20good%20coding%20practices%20in%20your%20IaC%20assets.%20Use%20elements%20like%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fbicep%2Fblob%2Fmain%2Fdocs%2Ftutorial%2F05-creating-modules.md%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3EBicep%20modules%3C%2FA%3E%20to%20help%20you%20organise%20your%20assets%20into%20separate%2C%20composable%20files.%20Make%20sure%20you%20follow%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fazure-resource-manager%2Ftemplates%2Ftemplate-best-practices%22%20rel%3D%22noopener%20noreferrer%22%20target%3D%22_blank%22%3Ebest%20practices%20for%20ARM%20templates%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKeep%20iterating%20and%20improving%20your%20IaC%20workflow%2C%20adding%20more%20and%20more%20of%20your%20solution%20to%20your%20IaC%20assets%20and%20deployment%20pipeline.%20Pretty%20soon%20you%20will%20start%20to%20see%20all%20of%20the%20benefits%20of%20IaC%20in%20your%20own%20team.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2069350%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20about%20why%20Infrastructure%20as%20Code%20is%20a%20key%20piece%20of%20a%20modern%20DevOps%20strategy%2C%20and%20the%20many%20benefits%20it%20brings.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2069350%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EApp%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EData%20%26amp%3B%20AI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EInfra%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2082269%22%20slang%3D%22en-US%22%3ERe%3A%20The%20benefits%20of%20Infrastructure%20as%20Code%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2082269%22%20slang%3D%22en-US%22%3E%3CP%3Egreat%20post!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

There are lots of different ways you can deploy and configure your Azure resources. When customers are first starting their cloud journey it's common to provision resources manually, deploying and configuring them in the Azure portal. However, this quickly becomes difficult to manage and scale. Infrastructure as Code (IaC) techniques and tools are designed to help you make use of your skills with coding and DevOps practices when working with your cloud infrastructure. However, I frequently work with customers who aren't completely convinced that IaC is going to help them, or be worth the investment. It can be helpful to have some insight into the benefits that many other customers have seen when using IaC approaches. This post outlines the main reason I think IaC is an essential part of a modern solution for Azure. We won't get much into the technical details of how you use IaC - this is just a high-level overview of why you should use it.

 

What is Infrastructure as Code?

The Azure Well-Architected Framework has a great definition of IaC:

 

Infrastructure as code (IaC) is the management of infrastructure - such as networks, virtual machines, load balancers, and connection topology - in a descriptive model, using a versioning system that is similar to what is used for source code. When you are creating an application, the same source code will generate the same binary every time it is compiled. In a similar manner, an IaC model generates the same environment every time it is applied. IaC is a key DevOps practice, and it is often used in conjunction with continuous delivery.

Ultimately, IaC allows you and your team to develop and release changes faster, but with much higher confidence in your deployments.

 

Gain higher confidence

One of the biggest benefits of IaC is the level of confidence you can have in your deployments, and in your understanding of the infrastructure and its configuration.

 

Integrate with your process. If you have a process by which code changes gets peer reviewed, you can use the exact same process for your infrastructure. This can be very helpful when a team member might be proposing a change to a resource, but they don't realise that the change might not work, could cause issues elsewhere in the solution, or may not meet the requirements. If these changes are made directly in the portal then you may not have the opportunity for your team to review the changes before they are made.

 

Consistency. Following an IaC process ensures that the whole team is following a standard, well-established process - regardless of who on the team has initiated it. I often work with customers who have a single designated person who is permitted to deploy to production; if this person is unavailable then deployments can be very difficult to complete, since that person will maintain all the knowledge in their head. By following a fully automated process you can move the knowledge of the deployment process into the automation tooling, and then you can broaden the number of people on your team who can initiate deployments while still maintaining the same quality level - and without giving broad administrative access to your environment. Not only does this help with your operational efficiency, it also has security benefits too.

 

Automated scanning. Many types of IaC assets can be scanned by automated tooling. One such type of tooling is linting, to check for errors in the code. Another type will scan the proposed changes to your Azure infrastructure to make sure they follow security and performance best practices - for example, ensuring that storage accounts are configured to block unsecured connections. This can be an important part of a Continuous Security approach.

 

Secret management. Every solution requires some secrets to be maintained and managed. These include connection strings, API keys, client secrets, and certificates. Following an IaC approach means that you need to also adopt some best-practice approaches to managing these secrets. For example, Azure has the Key Vault service to maintain these types of data. Key Vault can be easily integrated with many IaC tools and assets to ensure that the person conducting the deployment doesn't need access to your production secrets, which means you're adhering to the security principle of least privilege.

 

Access control. A fully automated IaC deployment pipeline means that all changes to your Azure resources should be done by an automated procedure. By doing this, you can be confident that all changes that are deployed to your Azure environment have followed the correct procedure, and it's much harder for bad configuration to make its way through to production accidentally. Ideally, you would remove the ability for humans to modify your resources at all - although you may allow for this to be overridden in an emergency, by using a 'break glass' account or Privileged Identity Management.

 

Avoid configuration drift. When I work with customers to adopt IaC approaches, I recommend redeploying all of the assets on every release. IaC tooling is generally built to be idempotent (i.e. to be able to be run over and over again without any bad effects). Usually, the first deployment of an asset will actually deploy the asset, while subsequent redeployments will essentially act as 'no-ops' and have no effect. This practice helps in a few ways:

  • It ensures that your IaC assets are regularly exercised. If they are only deployed occasionally, it's much more likely they will become stale and you won't notice until it's too late. This is particularly important if you need to rely on your IaC assets as part of a disaster recovery plan.
  • It ensures that your application code and infrastructure won't get out of sync. For example, if you have an application update that needs an IaC asset to be deployed first (such as to deploy a new database), you want to make sure you won't accidentally forget to do this in the right order. Deploying the two together in one pipeline means you are less likely to encounter these kinds of 'race conditions'.
  • It helps to avoid configuration drift. If someone does accidentally make a change to a resource without following your IaC pipeline, then you want to correct this as quickly as possible and get the resource back to the correct state. By following an IaC approach, the source of truth for your environment's configuration is in code.

 

Manage multiple environments

IaC can help with managing your environments. Pretty much every customer has to maintain some non-production environments as well as production. Some customers also maintain multiple production environments, such as for multitenanted solutions or for geographically distributed applications.

 

Manage non-production environments. A common pain point for customers is when their non-production environments are not the same as their production. This slows down testing of changes and reduces the team's confidence that they fully understand and what's happening in production. This configuration drift will often happen when the environments are all created manually, and someone forgets to apply a change somewhere. If you follow an IaC approach then this problem goes away, because the same UaC definition is used to create and deploy all of your environments - both non-production and production. You can specify different configuration for each environment, of course, but the core definition will be the same.

 

Dynamically provision environments. Once you have your IaC assets, you can then use them to provision new environments very easily. This can be enormously helpful when you're testing your solution. For example, you could quickly provision a duplicate of your production environment that can then be used for security penetration tests, for load testing, or to help a developer track down a bug.

 

Scale production environments. Some customers have the requirement to provision multiple production environments. For example, you might be following the deployment stamps pattern, or you might need to create a new instance of your solution in another geographical region. IaC assets can be used to quickly provision all of the components of your solution again, and keep them consistent with the existing environment.

 

Disaster recovery. In some situations, IaC assets can be used as part of a disaster recovery plan. If you don't need to keep copies of all of your infrastructure ready for a potential disaster, and can cope with a bit of downtime while you wait for your IaC assets to provision resources in another Azure region, then this can be worth considering. You'll need to be careful to plan out how you handle disaster recovery for your databases, storage accounts, and other resources that store state, though. You also need to make sure that you fully test your disaster recovery plans and that they meet your requirements for how much downtime you can experience in a disaster scenario (which is often called your Recovery Time Objective).

 

Better understand your cloud resources

IaC can also help you better understand the state of your resources.

 

Audit changes. Changes to your IaC assets will be version-controlled. This means you can review each change that has happened, as well as who made it, and when. This can be very helpful if you're trying to understand why a resource is configured a specific way.

 

Metadata. Many types of IaC assets let you add metadata, like code comments, to help explain why something is done a particular way. If your organisation has a culture of documenting your code, you can apply the same principles to your infrastructure.

 

Keep everything together. It's pretty common for a developer to work on a feature that will require both code changes and infrastructure changes. By keeping your infrastructure defined as code, you'll be able to group these together and see the relationship. For example, if you see a change to an IaC asset on a feature branch or in a pull request, you'll have a clearer understanding of what that change relates to.

 

Better understand Azure itself. The Azure portal is a great way to easily provision and configure resources, but it often simplifies the underlying resource model used. Using IaC will mean that you gain a much deeper understanding of what is happening in Azure and how to troubleshoot it if something isn't working correctly. For example, if you provision a set of virtual machines manually in the Azure portal, you may not realise that there are actually lots of separate Azure resources provisioned - and that some of these can potentially be shared, which can help to simplify your ongoing operations. Another example is that when you provision a Key Vault instance through the portal, the person creating it will be given access to the vault automatically - which may not necessarily be what you want. Using IaC means you have explicit control.

 

Declarative and imperative IaC

Broadly speaking, there are two different models for IaC. Imperative IaC involves writing scripts, in a language like Bash, PowerShell, C# script files, or Python. These programmatically execute a series of steps to create or modify your resources. Declarative IaC instead involves writing a definition of how you want your environment to look; the tooling then figures out how to make this happen by inspecting your current state, comparing it to the target state you've requested, and applying the differences. There's a good discussion of imperative and declarative IaC here.

 

There are great Azure tooling options for both models. For imperative IaC you can use the Azure CLI or PowerShell cmdlets. For declarative IaC you can use Azure Resource Manager (ARM) templates - or, in the near future, the new ARM template language called Bicep, which is my personal favourite option. Another popular choice is Terraform - there's a good comparison of ARM templates and Terraform in the Azure Well-Architected Framework. There are plenty of other community and commercial tools around too, including Pulumi.

 

I prefer using declarative IaC approaches - it can sometimes be a little tricky to write imperative scripts that will work consistently and will do exactly what you expect every time. I also feel like you get the most benefit out of IaC when you use declarative tooling. My personal choice is to use ARM templates (or soon, Bicep) for my IaC. However, the choice is yours.

 

How to get started with IaC

Hopefully these reasons are enough to convince you that IaC is worth the initial upfront investment in time - you'll need to be prepared to create your IaC assets, and to create a good process for your release and the necessary pipelines to support it.

 

First, explore and try out a few tools to see which will work best for your team. If you don't have any experience with IaC already then I recommend you start using Bicep - there's a great tutorial on how to get started. Try creating a simple dummy solution to see how the end-to-end process works.

 

Next, try creating some IaC assets for your actual solution. How do this will depend a little on your situation:

  • If you're working on a brand new solution then try to adopt the discipline of only deploying through IaC assets, and consider using the ARM template 'complete' deployment mode to help to maintain this discipline.
  • If you've got existing Azure resources then I recommend following a hybrid approach and slowly migrating to IaC assets. Start by creating IaC assets for a few small pieces of your solution, get those working, and then add more and more until you have are deploying everything in code. At first, make sure you are doing incremental deployments so that you don't accidentally destroy any existing production resources that you haven't yet added to your IaC assets.

You'll also need to build a pipeline to deploy the IaC assets. If you use ARM templates or Bicep, you can integrate these with Azure Pipelines. Make sure that any new resources are created and managed completely within your IaC assets and deployed using your pipelines.

 

You should also remember to use good coding practices in your IaC assets. Use elements like Bicep modules to help you organise your assets into separate, composable files. Make sure you follow the best practices for ARM templates.

 

Keep iterating and improving your IaC workflow, adding more and more of your solution to your IaC assets and deployment pipeline. Pretty soon you will start to see all of the benefits of IaC in your own team.

1 Comment
New Contributor

great post!