Effettuare il
provisioning su Azure
utilizzando Terraform e
Azure DevOps
GIORGIO LASALA
Thanks to
www.linkedin.com/in/giorgiolasala
github.com/salem84
Solution Architect
@ Engineering Ingegneria Informatica
giorgio.lasala@eng.it
AGENDA
• Infrastructure as Code
• Terraform Architecture and Workflow
• IaaS provisioning
• PaaS provisioning
• Terraform with Azure DevOps using YAML
• Terraform with Azure DevOps using Plugins
• Provisioning SharePoint Farm with Terraform
• Provisioning Azure ETL with Terraform
Once upon a time… (Windows) Azure
Today… Microsoft Azure
Azure and Command Line
Infrastructure as Code (IaC)
“Infrastructure as Code is the process of managing and
provisioning computing infrastructure and its configuration
through machine-processable definition files. It treats the
infrastructure as a software system, applying software
engineering practices to manage changes to the system in a
structured, safe way”
Infrastructure as Code characteristics
• Consistency
• Treat infrastructure like application code
• Single source of truth
• Increase repeatability and testability
• Idempotent provisioning and configuration
• Speed
• Decrease provisioning time
Infrastructure as Code characteristics
• Accountability
• Rely less on availability of persons to perform tasks
• Always know what is changed
• Validate infrastructure before deployment
• Increased Efficiency
• Use proven software development practices for
deploying infrastructure
• Lowering the costs of infrastructure management
Terraform
www.terraform.io
Core ideas in Terraform
• IaC Tool
• Open Source
• Multiplatform (Windows, Linux, Mac, …)
• Multiprovider (+200) cloud and on-premise, but …
• Plan validation
• HashiCorp Configuration Language (HCL) ~ JSON
• Simple model of resource entities with attributes
• Stateful lifecycle with CRUD operations
• Declarative configuration
• Dependencies by inference
• Parallel execution
Terraform Architecture
Terraform flow
terraform init
Init ApplyPlan
Terraform
Scripts
Terraform
State
terraform plan –out plan.dat
terraform apply plan.dat
Terminology in Terraform
Providers
Offer technology integrations and functionality, largely by wrapping third-
party APIs (e.g. azurerm)
Resources and Data Sources
Made available via a Provider, are the building blocks used to codify and
manage infrastructure; have a set of configurable attributes and a lifecycle
such as create, read, update, delete (e.g. Azure App Service)
Made reusable with Modules
Provisioner
Initiliaze a resource from a local or remote script
Terraform flow with Azure
Init ApplyPlan
State file contiene
informazioni
sensibiliState condiviso Locking dello stato 
Deployment con Azure Pipelines
Demo
Joy and pain of Terraform
• Declarative language
• Not imperative
• It’s not ARM
• Slower
• Not integrated in Azure Management Portal
• Provider coverage largely depends on community
• State file is critical
• Creation, storing and maintenance
• Integration with existing infrastructure
• Import command is for single resource
• Not aware of API rate and resources limits (plan / apply)
✓ Use a VCS
✓ Use remote state and access policy
❑ e. g. use a single build server
✓ Avoid user credentials in Terraform code
✓ Naming convention
❑ e. g. "${var.shortname}-{var.env}"
✓ Use VSCode with following extensions:
❑ Terraform [mauve.terraform] by Mikael Olenfalk
❑ Terraform doc snippet [run-at-scale.terraform-doc-
snippets] by Brandon O'Connor
Terraform tips and tricks
✓ https://github.com/shuaibiyy/awesome-terraform
✓ https://28mm.github.io/notes/d3-terraform-graphs
Hashicorp Docs and modules
✓ https://www.terraform.io/docs/
✓ https://registry.terraform.io/
Framework testing
✓ https://github.com/gruntwork-io/terratest
Terraform tips and links
Thank You!!!
Thanks to

Provisioning with Terraform - AzureDay Reloaded

  • 1.
    Effettuare il provisioning suAzure utilizzando Terraform e Azure DevOps GIORGIO LASALA
  • 2.
  • 3.
  • 4.
    AGENDA • Infrastructure asCode • Terraform Architecture and Workflow • IaaS provisioning • PaaS provisioning • Terraform with Azure DevOps using YAML • Terraform with Azure DevOps using Plugins • Provisioning SharePoint Farm with Terraform • Provisioning Azure ETL with Terraform
  • 5.
    Once upon atime… (Windows) Azure
  • 6.
  • 7.
  • 8.
    Infrastructure as Code(IaC) “Infrastructure as Code is the process of managing and provisioning computing infrastructure and its configuration through machine-processable definition files. It treats the infrastructure as a software system, applying software engineering practices to manage changes to the system in a structured, safe way”
  • 9.
    Infrastructure as Codecharacteristics • Consistency • Treat infrastructure like application code • Single source of truth • Increase repeatability and testability • Idempotent provisioning and configuration • Speed • Decrease provisioning time
  • 10.
    Infrastructure as Codecharacteristics • Accountability • Rely less on availability of persons to perform tasks • Always know what is changed • Validate infrastructure before deployment • Increased Efficiency • Use proven software development practices for deploying infrastructure • Lowering the costs of infrastructure management
  • 11.
  • 12.
    Core ideas inTerraform • IaC Tool • Open Source • Multiplatform (Windows, Linux, Mac, …) • Multiprovider (+200) cloud and on-premise, but … • Plan validation • HashiCorp Configuration Language (HCL) ~ JSON • Simple model of resource entities with attributes • Stateful lifecycle with CRUD operations • Declarative configuration • Dependencies by inference • Parallel execution
  • 13.
  • 14.
    Terraform flow terraform init InitApplyPlan Terraform Scripts Terraform State terraform plan –out plan.dat terraform apply plan.dat
  • 15.
    Terminology in Terraform Providers Offertechnology integrations and functionality, largely by wrapping third- party APIs (e.g. azurerm) Resources and Data Sources Made available via a Provider, are the building blocks used to codify and manage infrastructure; have a set of configurable attributes and a lifecycle such as create, read, update, delete (e.g. Azure App Service) Made reusable with Modules Provisioner Initiliaze a resource from a local or remote script
  • 18.
    Terraform flow withAzure Init ApplyPlan State file contiene informazioni sensibiliState condiviso Locking dello stato 
  • 19.
  • 23.
  • 24.
    Joy and painof Terraform • Declarative language • Not imperative • It’s not ARM • Slower • Not integrated in Azure Management Portal • Provider coverage largely depends on community • State file is critical • Creation, storing and maintenance • Integration with existing infrastructure • Import command is for single resource • Not aware of API rate and resources limits (plan / apply)
  • 25.
    ✓ Use aVCS ✓ Use remote state and access policy ❑ e. g. use a single build server ✓ Avoid user credentials in Terraform code ✓ Naming convention ❑ e. g. "${var.shortname}-{var.env}" ✓ Use VSCode with following extensions: ❑ Terraform [mauve.terraform] by Mikael Olenfalk ❑ Terraform doc snippet [run-at-scale.terraform-doc- snippets] by Brandon O'Connor Terraform tips and tricks
  • 26.
    ✓ https://github.com/shuaibiyy/awesome-terraform ✓ https://28mm.github.io/notes/d3-terraform-graphs HashicorpDocs and modules ✓ https://www.terraform.io/docs/ ✓ https://registry.terraform.io/ Framework testing ✓ https://github.com/gruntwork-io/terratest Terraform tips and links
  • 28.
  • 29.