INFRASTRUCTURE AS-A/FROM CODE
AN INTRODUCTION
Alex Tjahjana
Founding Consultant, IT Account 4 U
26th June 2024
30+ years of experiences in:
Software Development: C#, .net, JS Frameworks
Infrastructure: Azure, aws, on-prem
DevOps
Cyber Security
Certifications:
ITIL Certified
Certified Scrum Master
Azure Architect Expert
Azure DevOps Engineer Expert
Cybersecurity Architect Expert
AWS Solutions Architect Professional
DEFINITIONS
• is the process of managing and provisioning computer data center
resources through machine-readable definition files, rather than
physical hardware configuration or interactive configuration tools
(Wittig, Andreas; Wittig, Michael (2016). Amazon Web Services in Action. Manning Press. p. 93)
Infrastructure as code (IaC)
• is an approach that creates, configures, and manages cloud
resources understanding a software application's source code,
without explicit description.
(https://www.infoq.com/news/2023/02/infrastructure-code-cloud-manage/)
Infrastructure from Code (IfC)
APPROACHES FOR IAC
• Defines the target/desired configuration/state
• Terraform, CloudFormation, Crossplane, Bicep, Puppet, ARM Template
Declarative model
• Describe how to achieve the target/desired configuration/state
• Pulumi, CDKs, Ansible, Helm, Chef
Imperative model
How declarative do we need it to be?
APPROACHES FOR IFC
• Analyse and infer infrastructure from code
• Ampt, Nitric
SDK-based
• Specify the infrastructure as in-code annotation
• Klotho
Code annotation
• Annotates the code, and the tools incorporate it into the framework
• Encore, Shuttle, AWS Chalice
Hybrid: Annotation +
Framework
• Cloud-centric programming languages
• Wing, DarkLang
New programming
language
ADVANTAGES
GitOps
• Collaboration
• Security
• Compliance and Auditing
• Standardisation
Can be automated
• Integration with DevOps and Continuous Deployment
• Modification through configuration
Repeatable and consistent
Traceable
Transparent
• Higher visibility
RISKS
Takes time to setup
Templates configuration vulnerabilities
Configuration drifts
Secret management
Cost Especially IfC
Shifts infrastructure and security responsibilities to developers
DEMO TERRAFORM
BEST
PRACTICES
FOR
TERRAFORM
Modularise the TerraForm code
Refactor
Risk of rebuilding the resource
Tags
Costing
Metadata
Implement TerraForm test version 1.6.0+
Implement compliance and security scans
Use input validation
Nice to have: Resource cost
estimation
Infracost, Scalr
MODULE IN PRIVATE GIT
• Use non-personal account
• Use git config command in your yaml
git config --global url."https://${PERSONAL_ACCESS_TOKEN}@dev.azure.com".insteadOf "https://dev.azure.com"
MAKES TERRAFORM IN AZUREDEVOPS
EASIER
• TerraForm yaml commands
• Terraform Service Connection
TerraForm extension
Snyk extension
• file transforms
Use Pipeline library
Use Pipeline Environment
DEMO TERRAFORM
MODULES
REPOSITORIES
• https://dev.azure.com/itaccount4u/demo-
terraform/_git/local-modules
Single repository (folders as module)
• https://dev.azure.com/itaccount4u/demo-
terraform/_git/remote-modules
Remote Modules:
• https://dev.azure.com/itaccount4u/demo-
terraform-module/_git/resource-group
• https://dev.azure.com/itaccount4u/demo-
terraform-module/_git/storage-account
Modularised Code
RESOURCES
• Infrastructure as a Code:
https://en.wikipedia.org/wiki/Infrastructure_as_code
• Infrastructure from Code:
https://www.infoq.com/news/2023/02/infrastructure-code-cloud-
manage/
• State of Infrastructure-from-Code 2023:
https://klo.dev/state-of-infrastructure-from-code-2023/
• 14 lines of IfC code creates 8 aws resources:
https://infrastructurefromcode.com/#:~:text=automatically%20provis
ion%20and%20configure%20the%20following%20resources
• Infrastructure as Code: Do the Drawbacks Outweigh the Benefits?:
https://www.itprotoday.com/software-development/infrastructure-as-
code-do-the-drawbacks-outweigh-the-benefits-
RESOURCES
• Create Azure Service Principal:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/doc
s/guides/service_principal_client_secret
• TerraForm test:
https://developer.hashicorp.com/terraform/language/tests
• TerraForm dynamic block: https://spacelift.io/blog/terraform-
dynamic-blocks
• Module in private repository:
https://medium.com/@dipandergoyal/terraform-using-private-git-
repo-as-module-source-d20d8cec7c5
• Infracost: https://github.com/infracost/infracost
• Azure DevSecOps snippets:
https://github.com/AErmie/DevSecOps/tree/main/azure-pipelines
THANK YOU
Alex Tjahjana
alex@itaccount4u.com
linkedin.com/in/alextjahjana/

Infrastructure-As-A/From-Code - An Introduction

  • 1.
    INFRASTRUCTURE AS-A/FROM CODE ANINTRODUCTION Alex Tjahjana Founding Consultant, IT Account 4 U 26th June 2024
  • 2.
    30+ years ofexperiences in: Software Development: C#, .net, JS Frameworks Infrastructure: Azure, aws, on-prem DevOps Cyber Security Certifications: ITIL Certified Certified Scrum Master Azure Architect Expert Azure DevOps Engineer Expert Cybersecurity Architect Expert AWS Solutions Architect Professional
  • 3.
    DEFINITIONS • is theprocess of managing and provisioning computer data center resources through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools (Wittig, Andreas; Wittig, Michael (2016). Amazon Web Services in Action. Manning Press. p. 93) Infrastructure as code (IaC) • is an approach that creates, configures, and manages cloud resources understanding a software application's source code, without explicit description. (https://www.infoq.com/news/2023/02/infrastructure-code-cloud-manage/) Infrastructure from Code (IfC)
  • 4.
    APPROACHES FOR IAC •Defines the target/desired configuration/state • Terraform, CloudFormation, Crossplane, Bicep, Puppet, ARM Template Declarative model • Describe how to achieve the target/desired configuration/state • Pulumi, CDKs, Ansible, Helm, Chef Imperative model How declarative do we need it to be?
  • 5.
    APPROACHES FOR IFC •Analyse and infer infrastructure from code • Ampt, Nitric SDK-based • Specify the infrastructure as in-code annotation • Klotho Code annotation • Annotates the code, and the tools incorporate it into the framework • Encore, Shuttle, AWS Chalice Hybrid: Annotation + Framework • Cloud-centric programming languages • Wing, DarkLang New programming language
  • 6.
    ADVANTAGES GitOps • Collaboration • Security •Compliance and Auditing • Standardisation Can be automated • Integration with DevOps and Continuous Deployment • Modification through configuration Repeatable and consistent Traceable Transparent • Higher visibility
  • 7.
    RISKS Takes time tosetup Templates configuration vulnerabilities Configuration drifts Secret management Cost Especially IfC Shifts infrastructure and security responsibilities to developers
  • 8.
  • 9.
    BEST PRACTICES FOR TERRAFORM Modularise the TerraFormcode Refactor Risk of rebuilding the resource Tags Costing Metadata Implement TerraForm test version 1.6.0+ Implement compliance and security scans Use input validation Nice to have: Resource cost estimation Infracost, Scalr
  • 10.
    MODULE IN PRIVATEGIT • Use non-personal account • Use git config command in your yaml git config --global url."https://${PERSONAL_ACCESS_TOKEN}@dev.azure.com".insteadOf "https://dev.azure.com"
  • 11.
    MAKES TERRAFORM INAZUREDEVOPS EASIER • TerraForm yaml commands • Terraform Service Connection TerraForm extension Snyk extension • file transforms Use Pipeline library Use Pipeline Environment
  • 12.
  • 13.
    REPOSITORIES • https://dev.azure.com/itaccount4u/demo- terraform/_git/local-modules Single repository(folders as module) • https://dev.azure.com/itaccount4u/demo- terraform/_git/remote-modules Remote Modules: • https://dev.azure.com/itaccount4u/demo- terraform-module/_git/resource-group • https://dev.azure.com/itaccount4u/demo- terraform-module/_git/storage-account Modularised Code
  • 14.
    RESOURCES • Infrastructure asa Code: https://en.wikipedia.org/wiki/Infrastructure_as_code • Infrastructure from Code: https://www.infoq.com/news/2023/02/infrastructure-code-cloud- manage/ • State of Infrastructure-from-Code 2023: https://klo.dev/state-of-infrastructure-from-code-2023/ • 14 lines of IfC code creates 8 aws resources: https://infrastructurefromcode.com/#:~:text=automatically%20provis ion%20and%20configure%20the%20following%20resources • Infrastructure as Code: Do the Drawbacks Outweigh the Benefits?: https://www.itprotoday.com/software-development/infrastructure-as- code-do-the-drawbacks-outweigh-the-benefits-
  • 15.
    RESOURCES • Create AzureService Principal: https://registry.terraform.io/providers/hashicorp/azurerm/latest/doc s/guides/service_principal_client_secret • TerraForm test: https://developer.hashicorp.com/terraform/language/tests • TerraForm dynamic block: https://spacelift.io/blog/terraform- dynamic-blocks • Module in private repository: https://medium.com/@dipandergoyal/terraform-using-private-git- repo-as-module-source-d20d8cec7c5 • Infracost: https://github.com/infracost/infracost • Azure DevSecOps snippets: https://github.com/AErmie/DevSecOps/tree/main/azure-pipelines
  • 16.