Terraform On Azure Cloud v9
Terraform On Azure Cloud v9
SRE |
Real-World 25 Demos
Kalyan Reddy Daida
StackSimplify
DevOps on
AWS EKS STACKSIMPLI AWS &
Jenkins Azure AKS
Kubernetes FY Azure Ansible Part-2
HashiCorp Azure Certs
Azure AKS DevOps & Certified AZ-900, 104,
Kubernetes SRE Vault & Consul 204, 400
Kubernetes Google Cloud
AWS ECS Roadmap Certifications
Associate &
Docker on AWS CKAD, CKA, CKS
Professional
Certs
AWS AWS Google GKE
Python
CloudFormation Lambda Kubernetes
HashiCorp Certified Terraform Associate on AWS with 50 Practical Demos
Terraform on AWS with SRE and IaC DevOps with 20 Real-World Demos
HashiCorp Certified Terraform Associate on Azure with 60+ Practical
Demos
Terraform on Azure with IaC DevOps SRE with 20+ Real-World Demos
Terraform on AWS EKS Elastic Kubernetes Service with 15+ Real-World Demos
© Kalyan Reddy Daida StackSimplify
Terraform on Azure with IaC
DevOps SRE | Real-World 25
Demos
Kalyan Reddy Daida
StackSimplify
Terraform Fundamentals (Commands, Language, Settings, Providers, Resources)
Azure Virtual Network, Subnets and Terraform Azure Traffic Manager
Network Security Groups On
Azure Virtual Machines, Network Interface Azure Cloud Azure Application Gateway Basics
and Public IP
Azure Application Gateway Context Path
Azure Bastion Host and Bastion Service Real-World based Routing and Multisite Hosting
Azure Standard Load Balancer with Approach Azure Application Gateway SSL, HTTP to
Inbound NAT Rules HTTPS Redirect, SSL with Key Vault
Azure Virtual Machine Scale Sets with Step by Step Terraform Local Modules – Leverage Public
Manual Scaling Documentation Registry
Azure VMSS with Autoscaling Default, On GitHub Terraform Local Modules – Build from
Recurrence and Fixed Profiles scratch and Publish to Public TF Registry
Azure Standard Load Balancer (External Terraform Remote State Storage & Remote
Incremental
and Internal) State Datasource
way to Build
Complex Infra Azure MySQL Single Server with Azure
Azure Private and Public DNS Zones
Application Gateway
IaC DevOps with Azure DevOps for Terraform Project with Build and Release Pipelines
TF Configs
well kept
on GitHub
Resource Group Traffic Manager NAT Gateway Virtual Network Subnet Network Security
Group
Network Interface Virtual Machine Azure Disk VM Scale Set Public IP DNS Zone
MySQL Server Load Balancer LB Inbound NAT Application Storage Azure DevOps
Gateway Account Pipelines
30+ 20+
Terraform & Azure
Concepts Resources
terraform init terraform validate terraform plan terraform apply terraform destroy
We are going to
learn Terraform
Fundamentals for 3
hours
Virtual Network
Bastion Bastion
Host Subnet NSG
Virtual Network
DB Tier DB
Subnet NSG
Terraform file() Function VM NSG (Optional)
AZ AD Webapp
Connect
App Service app
Azure DevOps
Access key project Build job
off code
Developer
Storage account
IP address
Establish
pipeline Deploy
Webapp
Database
NIC VM Disk
Admin
User
App Tier App
Bastion Service Subnet NSG
Subnet
SSL Port 443
DB Tier DB
Subnet NSG
Bastion Service
Browser Azure Bastion Service
Public IP
Port 22
VMSS
Bastion Host NIC VM Disk
Linux VM Public IP Manual Scaling
Port 22
P3 P2 P1
Scale Out
Scale In
Default
Profile
© Kalyan Reddy Daida StackSimplify
Autoscaling
Recurrence Profile Week Days
Recurrence
Week Days
Recurrence
Weekends
Fixed Date
Profile
Virtual Network
NAT Gateway
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
Virtual Network
applb.terraformguru.com NAT Gateway
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
Terraform Terraform
State Storage State Locking
Azure Traffic
terraform_remote_state
Manager
data source
Project-2: westus2
project-3-terraform.tfstate
Azure VNET + LB
The terraform_remote_state data source retrieves
+ VMSS
the root module output values from some other
Terraform configuration, using the latest state
project-2-terraform.tfstate snapshot from the remote backend.
Web VMSS
Web
LB Azure Standard VMSS NSG
Resource Group Public IP Load Balancer
mytfdemo-wquift.trafficmanager.net
Resource
Group Virtual Network
Users Azure Traffic Manager
Web Tier
Region: westus2 Subnet
Web
Region: eastus2 NSG
Web VMSS
Web
LB Azure Standard VMSS NSG
Public IP Load Balancer
AG – Listeners
DB Tier DB
Create AG using Subnet NSG
AG – HTTP Settings
Azure Portal
AG – Rules
AG – Listeners
DB Tier DB
Subnet NSG
AG – HTTP Settings
AG – Rules
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
http://ag-public-ip/app1/
+
http://ag-public-ip/app2/ AG
NSG
http://ag-public-ip/ AG Subnet /app1/*
/app2/*
Azure
LB Public IP Application /*
Users App2 VMSS
Gateway LB
+
External Site
stacksimplify.com
Root Context
External
Redirect
Context Path
based Routing
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
http://app1.terraformguru.com/index.html
http://app1.terraformguru.com/app1/index.html +
AG Subnet app1.terraformguru.com
Azure app2.terraformguru.com
LB Public IP Application
Users AG
NSG Gateway LB App2 VMSS
http://app2.terraformguru.com/index.html
http://app2.terraformguru.com/app2/index.html +
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
+
Azure
AG Subnet
http://terraformguru.com Application
https://terraformguru.com Gateway LB
Azure
HTTP AG Storage
To SSL
LB Public IP Error Account
Users HTTPs Certs
Pages
Redirect
AG
NSG 502.html 403.html
Virtual Network
Web Tier Web
Subnet NSG
Azure
AG Subnet
http://terraformguru.com Application App1 VMSS
https://terraformguru.com Gateway LB
+
HTTP AG
To SSL
Users
LB Public IP Error
HTTPs Certs
Pages
Redirect Azure
AG Storage
NSG Account
502.html 403.html
Azure Key User Assigned
Vault Managed Identity
Developer
4 6 10
8
Resource Group Resource Group Resource Group Resource Group
Real-World
Demo 23
© Kalyan Reddy Daida StackSimplify
Azure MySQL Single Server
Azure Cloud
Resource
Group
Virtual Network
Web Tier
Subnet
App1 VMSS
VNET Service
+ Endpoint
Web
NSG
MySQL Virtual
Azure Network Rule
AG Subnet
Application
http://terraformguru.com Gateway LB
https://terraformguru.com
Azure
HTTP AG Storage
SSL Azure MySQL
LB Public IP
To Error Account Single Server
Users HTTPs Certs
Pages
Redirect
AG
NSG 502.html 403.html
UMS Web App with Create User, List User, UMS Web App DB information can be passed via
Login and Logout Features Environment Variables (DB Name, Port User, Pass)
UMS Web App needs MySQL DB to store its We can login with new users created to UMS
users. If connection to DB fails, it cannot start Web App
Demo-1 Demo-3
Terraform
Modules
Demo-2 Demo-4
Demo 4
Terraform Real-World
Implementations on AWS & Azure
Documentation
Disaster
Dev QA Staging Production
Recovery
Documentation
(Steps Missing)
Disaster
Dev QA Staging Production
Recovery
Not-in-
No CI Delays Issues Outages
Sync
Documentation
Disaster
Dev QA Staging Production
Recovery
Disaster
Dev QA Staging Production
Recovery
Scale Down
Prod-1 Prod-2
Creates Infra
Disaster
Dev QA Staging Production
Recovery
Re-Use
One-Time Quick & Tracked
Template Reliable
Work Fast for Audit
s
Total Time: 25 Days reduced to 5 days, Provisioning environments will be in minutes or seconds
If you accidentally change the wrong setting or delete the wrong resource in the web console you
Stability can break things. IaC helps solve this, especially when it is combined with version control, such as
Git.
With IaC we can write it once and then reuse it many times. This means that one well written
Scalability template can be used as the basis for multiple services, in multiple regions around the world,
making it much easier to horizontally scale.
Once again IaC gives you a unified template for how to deploy our architecture. If we create one
Security well secured architecture we can reuse it multiple times, and know that each deployed version is
following the same settings.
Terraform not only creates resources it also maintains the record of what is created in real world
Audit cloud environments using its State files.
Mac OS
Windows OS
Linux OS
terraform init terraform validate terraform plan terraform apply terraform destroy
Blocks
Arguments
HCL – HashiCorp Language Terraform
Identifiers
Comments
Block Labels
Block Type
Based on Block
Top Level & Type block labels
Block inside will be 1 or 2
Blocks Example:
Resource – 2
Top Level Blocks: resource, provider Arguments labels
Block Inside Block: provisioners, Variables – 1 label
resource specific blocks like tags
© Kalyan Reddy Daida StackSimplify
Terraform Language Basics – Configuration
Syntax
Argument
Name Argument
[or] Value
Identifier [or]
Expression
Multi-line
comment
Provider Requirements
Experimental Language
Features
Passing Metadata to
Providers
1
terraform init
Terraform CLI Azure Cloud
rov ider
n lo ad P Terraform Registry
Dow
3 terraform plan 4 terraform apply Azure
Terraform Azure
Provider 5 terraform destroy APIs
Resource Group
2 terraform validate
Version Constraints within the configuration itself determine which versions of dependencies are potentially compatible
Dependency Lock File: After selecting a specific version of each dependency using Version Constraints Terraform
remembers the decisions it made in a dependency lock file so that it can (by default) make the same decisions again in
future.
Very Important: Lock File currently tracks only Provider Dependencies. For modules continue to use exact version
constraint to ensure that Terraform will always select the same module version.
Checksum Verification: Terraform will also verify that each package it installs matches at least one of the checksums it
previously recorded in the lock file, if any, returning an error if none of the checksums match
© Kalyan Reddy Daida StackSimplify
Dependency Lock File
If we have lock file, the lock file causes Terraform to always install the same provider version, ensuring that runs across
your team or remote sessions will be consistent.
Resource
Terraform
Meta-Argument
Resource Syntax
depends_on
Terraform
Resources Resource
Terraform
Meta-Argument
Resource Behavior
for_each
Resource
Terraform
Meta-Argument
State
lifecycle
Block Labels
Block Type
Based on Block
Top Level & Type block labels
Block inside will be 1 or 2
Blocks Example:
Resource – 2
Top Level Blocks: resource, provider Arguments labels
Block Inside Block: provisioners, Variables – 1 label
resource specific blocks like tags
© Kalyan Reddy Daida StackSimplify
Terraform Language Basics – Configuration
Syntax
Argument
Name Argument
[or] Value
Identifier [or]
Expression
Terraform State
State Terraform
This state is used by Terraform to map real world resources to your configuration
(.tf files), keep track of metadata, and to improve performance for large
Admin
infrastructures.
Local Desktop This state is stored by default in a local file named "terraform.tfstate", but it can
also be stored remotely, which works better in a team environment.
1
terraform init Azure Cloud
Terraform CLI
ov id er
n lo ad Pr Terraform Registry Virtual Network Subnet Public IP
Dow
4 terraform apply Azure
Terraform Azure
Provider 5 terraform destroy APIs
Resource Group Network Interface
2 terraform validate
The primary purpose of Terraform state is to store bindings between objects in a
3 terraform plan
remote system and resource instances declared in your configuration.
Terraform State
When Terraform creates a remote object in response to a change of configuration, it will record the
File identity of that remote object against a particular resource instance, and then potentially update or delete
terraform.tfstate that object in response to future configuration changes.
terraform.tfstate
Azure
Virtual Network
Subnets
Network Security Group
© Kalyan Reddy Daida StackSimplify
Azure Virtual Network – 4
Tier Design
Resource Group
Virtual Network
Bastion Bastion
Host Subnet NSG
azurerm_resource_group azurerm_network_security_group
azurerm_virtual_network azurerm_network_security_rule
azurerm_subnet azurerm_subnet_network_security_group_association
Real-World
Demo 1
© Kalyan Reddy Daida StackSimplify
Input variables serve as parameters for a Terraform module, allowing aspects of the module to be customized without
altering the module's own source code, and allowing modules to be shared between different configurations.
1 2
A root module can use A child module can use
outputs to print certain
Terraform outputs to expose a
values in the CLI output Variables subset of its resource
after running terraform Outputs attributes to a parent
apply. module.
Count and
for_each and
Basics Splat
for loops
Expression
Over the process master the for loops in Terraform with Lists and
Maps
© Kalyan Reddy Daida StackSimplify
Terraform Variables – Local
Values
A local value assigns a name to an expression, so you can use that
name multiple times within a module without repeating it.
In blocks where for_each is set, an additional each object is available in for_each with Maps
expressions, so you can modify the configuration of each instance.
each.key — The map key (or set member) corresponding to this instance. for_each with Set of Strings
each.value — The map value corresponding to this instance. (If a set was for_each Chaining
provided, this is the same as each.key.)
Virtual Network
DB Tier DB
VM NSG (Optional) Subnet NSG
Bastion Bastion
Host Subnet NSG
azurerm_network_interface
azurerm_linux_virtual_machine
Real-World
Demo 2
© Kalyan Reddy Daida StackSimplify
Real-World
Demo 3
Azure
Bastion Host Service
and
Bastion Host Linux VM
© Kalyan Reddy Daida StackSimplify
Azure Bastion Host Linux VM &
Bastion Service
Resource
Group Virtual Network
NIC VM Disk
Admin
User
App Tier App
Bastion Service Subnet NSG
Subnet
SSL Port 443
DB Tier DB
Subnet NSG
Bastion Service
Browser Azure Bastion Service
Public IP
azurerm_network_interface
azurerm_public_ip
Azure Disk (automatically
gets created)
azurerm_subnet Dedicated Subnet for
Azure Bastion Service
azurerm_network_security_group Optional
azurerm_network_security_rule azurerm_bastion_host
azurerm_network_interface_security_group_association
Real-World
Demo 3
© Kalyan Reddy Daida StackSimplify
Terraform Provisioners
Provisioners can be used to model specific actions on the local machine or on a remote
machine in order to prepare servers
Failure Behaviour: Continue: Ignore Failure Behaviour: Fail: Raise an error and
the error and continue with creation stop applying (the default behavior). If
or destruction. creation provisioner, taint resource
local-exec Provisioner
Terraform
Connect to Azure Bastion Host VM from Terraform CLI
Connection
Terminal
Block
Terraform File
Push terraform-azure.pem to Bastion Host VM
Provisioner
Terraform
Provide permissions chmod 400 to terraform-azure.pem
remote-exec
after copied to Bastion Host VM
Provisioner
Instances of null_resource are treated like normal resources, but they don't do
anything.
Same as other resource, you can configure provisioners and connection details on
a null_resource.
Creation Time Provisioner (by default) Destroy Time Provisioner (when = destroy)
Web Tier
Subnet
Web VM-1
Admin Port 22
Web VM-2
Port 22
Inbound NAT
SSH Port 2022 Rules
NIC VM Disk
Users
Demo 5
Azure
Standard
Load Balancer
Port 22
azurerm_lb_backend_address_pool
azurerm_lb_rule
azurerm_network_interface_backen
d_address_pool_association
Real-World
Demo 5
© Kalyan Reddy Daida StackSimplify
Load Balancer
Real-World Virtual Machines
Demo 6
Azure
Standard
Load Balancer
Inbound NAT Rules
© Kalyan Reddy Daida StackSimplify
Azure Standard Load Balancer – Inbound NAT
Rules
SSH Client – Putty / Resource
Terminal Group Virtual Network
azurerm_lb_backend_address_pool
azurerm_lb_rule
azurerm_network_interface_backen
d_address_pool_association
azurerm_network_interface_nat_rul
azurerm_lb_nat_rule
e_association
© Kalyan Reddy Daida StackSimplify
Azure Load Balancer – Inbound NAT Rules Topology
Real-World
Demo 6
© Kalyan Reddy Daida StackSimplify
Virtual Machines
Load Balancer
Real-World
Demo 7
Azure
Multiple VMs
Meta-Argument Count
© Kalyan Reddy Daida StackSimplify
Resource Meta-Arguments
depends_on
count
provider
Meta-Arguments can be
used with any resource
type to change the lifecycle
behavior of resources.
Provisioners &
Connections
© Kalyan Reddy Daida StackSimplify
Practical Example with Step-by-Step
Documentation on Github
9 Demos for 2 Hour 30 Minutes
Meta-Arguments
Standard Resource behavior can be altered using special nested lifecycle block within a
lifecycle resource block body
Provisioners & For taking extra actions after resource creation (Example: install some app on server or do
Connections something on local desktop after resource is created at remote destination)
Real-World
Demo 7
© Kalyan Reddy Daida StackSimplify
Virtual Machines
Load Balancer
Real-World
Demo 8
Azure
Multiple VMs
Meta-Argument for_each
© Kalyan Reddy Daida StackSimplify
Azure Standard Load Balancer – Meta-
Argument for_each
Resource
Group Virtual Network
Real-World
Demo 8
© Kalyan Reddy Daida StackSimplify
Load Balancer
Real-World VM
Demo 9 Scale Sets
Azure
Virtual Machine
Scale Sets
Manual Scaling
External LB
© Kalyan Reddy Daida StackSimplify
Azure Standard Load Balancer – VMSS
Manual Scaling
Resource
SSH Client – Putty / Group
Terminal
Virtual Network
VMSS
Bastion Host NIC VM Disk
Linux VM Public IP Manual Scaling
Port 22
Not needed
when using
VMSS
Real-World
Demo 9
© Kalyan Reddy Daida StackSimplify
Load Balancer VM
Real-World Scale Sets
Demo 10
Azure
Virtual Machine
Scale Sets Autoscaling
External LB
© Kalyan Reddy Daida StackSimplify
Azure Standard Load Balancer + VMSS
Auto Scaling
Resource
SSH Client – Putty / Group
Terminal
Virtual Network
VMSS
NIC VM Disk
Bastion Host
Linux VM Public IP Autoscaling
Port 22
P3 P2 P1
Scale Out
Scale In
Default
Profile
© Kalyan Reddy Daida StackSimplify
Autoscaling – What happens to default profile when other profiles
present ?
Recurrence
Week Days
Recurrence
Weekends
Fixed Date
Profile
Real-World
Demo 10
© Kalyan Reddy Daida StackSimplify
Real-World
Demo 11
Azure
Standard
Load Balancer
External and Internal LB
© Kalyan Reddy Daida StackSimplify
Azure - External LB + Web VMSS + Internet
Internal LB + App VMSS
Resource NAT Gateway
Group Public IP
Virtual Network
NAT Gateway
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
Port 22
App VMSS NSG
Web Tier Web
Subnet NSG
Internal
Web VMSS LB
Port 80
DB Tier DB
LB Azure Standard Web Subnet NSG
Users VMSS NSG
Public IP Load Balancer
Download app1.conf from Storage Container to Apache
azurerm_lb
azurerm_lb_backend_address_pool
azurerm_lb_rule
Internal LB is
No Public IP
for Internal LB
created in azurerm_network_interface_backen
App Subnet d_address_pool_association
azurerm_nat_gateway
azurerm_nat_gateway_public_ip_association In addition to
NAT App VM and App Load
Gateway azurerm_subnet_nat_gateway_association Balancer these
Resources are also
required
azurerm_storage_account
azurerm_storage_container
Storage
Account azurerm_storage_blob
External LB
Internal LB
Real-World
Demo 11
© Kalyan Reddy Daida StackSimplify
Real-World
Azure
Load Balancer Demo 12 VM
Scale Sets
Azure
Private DNS Zones
Virtual Network
applb.terraformguru.com NAT Gateway
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
azurerm_private_dns_zone
azurerm_private_dns_zone_virtual_network_link
Real-World
Demo 12
© Kalyan Reddy Daida StackSimplify
Real-World
Demo 13
Azure
Delegate DNS Domain
To
Azure Public DNS Zone
© Kalyan Reddy Daida StackSimplify
Azure
Real-World
VM
Load Balancer
Demo 14 Scale Sets
Azure
Public DNS Zones
DB Tier DB
Subnet NSG
Storage
Account Download app1.conf from Storage Container to Web VMSS Apache
DB Tier DB
app1.kubeoncloud.com LB Web Subnet NSG
Azure Standard
Public IP Load Balancer VMSS NSG
Users Download app1.conf from Storage Container to Apache
Datasource: azurerm_dns_zone
Azure
Public DNS azurerm_dns_a_record – app1 Record: app1.kubeoncloud.com
Zone
Real-World
Demo 14
© Kalyan Reddy Daida StackSimplify
Real-World
Demo 15
Terraform
Azure VM
Load Balancer Scale Sets
Backend
Remote State Storage
with
Azure Storage Account
© Kalyan Reddy Daida StackSimplify
What is Terraform Backend ?
Backends are responsible for storing state and providing an API for state locking.
Terraform Terraform
State Storage State Locking
You can disable state locking for most commands with the -
lock flag but it is not recommended.
If acquiring the lock is taking longer than expected, Terraform
Azure Storage Account terraform.tfstate
will output a status message.
If Terraform doesn't output a message, state locking is still
occurring if your backend supports it.
Terraform has a force-unlock command to manually unlock
Azure VM
the state if unlocking failed.
Instance
Azure Cloud
© Kalyan Reddy Daida StackSimplify
Terraform Remote
State File with
State Locking
Real-World
Demo 15
© Kalyan Reddy Daida StackSimplify
Terraform
Backends
Where Backends are Used Backend configuration is only used by Terraform CLI.
Azure
Traffic Manager
Terraform
Remote State Datasource
© Kalyan Reddy Daida StackSimplify
Terraform Remote State
Project-1: eastus2
Datasource
Azure VNET + LB
+ VMSS
Project-3: eastus2
project-1-terraform.tfstate
Azure Traffic
terraform_remote_state
Manager
data source
Project-2: westus2
project-3-terraform.tfstate
Azure VNET + LB
The terraform_remote_state data source retrieves
+ VMSS
the root module output values from some other
Terraform configuration, using the latest state
project-2-terraform.tfstate snapshot from the remote backend.
Web VMSS
Web
LB Azure Standard VMSS NSG
Resource Group Public IP Load Balancer
mytfdemo-wquift.trafficmanager.net
Resource
Group Virtual Network
Users Azure Traffic Manager
Web Tier
Region: westus2 Subnet
Web
Region: eastus2 NSG
Web VMSS
Web
LB Azure Standard VMSS NSG
Public IP Load Balancer
Real-World
Demo 16
© Kalyan Reddy Daida StackSimplify
Real-World
Application VM
Gateway Demo 17 & 18 Scale Sets
Azure
Application Gateway
using
Azure Portal & Terraform
© Kalyan Reddy Daida StackSimplify
Azure Application Gateway
AG – Listeners
DB Tier DB
Create AG using Subnet NSG
AG – HTTP Settings
Azure Portal
AG – Rules
AG – Listeners
DB Tier DB
Subnet NSG
AG – HTTP Settings
AG – Rules
DB Tier DB
Subnet NSG
Bastion Host NIC VM Disk
Linux VM Public IP
Port 22
Azure
LB Public IP Application
Users
Gateway LB
Real-World
Demo 17 & 18
© Kalyan Reddy Daida StackSimplify
Real-World
Application VM
Gateway Demo 19 Scale Sets
Azure
Application Gateway
Context Path Routing
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
http://ag-public-ip/app1/
+
http://ag-public-ip/app2/ AG
NSG
http://ag-public-ip/ AG Subnet /app1/*
/app2/*
Azure
LB Public IP Application /*
Users App2 VMSS
Gateway LB
+
External Site
stacksimplify.com
Root Context
External
Redirect
Context Path
based Routing
Real-World
Demo 19
© Kalyan Reddy Daida StackSimplify
Real-World
Application VM
Gateway Demo 20 Scale Sets
Azure
Application Gateway
Multisite Hosting
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
http://app1.terraformguru.com/index.html
http://app1.terraformguru.com/app1/index.html +
AG Subnet app1.terraformguru.com
Azure app2.terraformguru.com
LB Public IP Application
Users AG
NSG Gateway LB App2 VMSS
http://app2.terraformguru.com/index.html
http://app2.terraformguru.com/app2/index.html +
Real-World
Demo 20
© Kalyan Reddy Daida StackSimplify
Real-World VM
Application
Gateway Demo 21 Scale Sets
Azure
Application Gateway
Self Signed SSL
Http to Https Redirect
Error Pages 502 and 403
© Kalyan Reddy Daida StackSimplify
Azure Application Gateway – SSL Self-
signed
Resource
Group
Virtual Network
Web Tier Web
Subnet NSG
App1 VMSS
+
Azure
AG Subnet
http://terraformguru.com Application
https://terraformguru.com Gateway LB
Azure
HTTP AG Storage
To SSL
LB Public IP Error Account
Users HTTPs Certs
Pages
Redirect
AG
NSG 502.html 403.html
Real-World
Demo 21
© Kalyan Reddy Daida StackSimplify
Real-World
Azure Key Vault
Application
Gateway
VM
Scale Sets
Demo 22
Azure
Application Gateway
Self Signed SSL
User Managed Azure Key Vault
Identity
Virtual Network
Web Tier Web
Subnet NSG
Azure
AG Subnet
http://terraformguru.com Application App1 VMSS
https://terraformguru.com Gateway LB
+
HTTP AG
To SSL
Users
LB Public IP Error
HTTPs Certs
Pages
Redirect Azure
AG Storage
NSG Account
502.html 403.html
Azure Key User Assigned
Vault Managed Identity
Real-World
Demo 22
© Kalyan Reddy Daida StackSimplify
Github Azure Azure
DevOps Starter
Real-World
Pipelines
Pipelines
Demo 23
Azure
IaC DevOps
Continuous Integration & Delivery
Pipelines
Azure Build & Release Pipelines
© Kalyan Reddy Daida StackSimplify
Azure Pipelines – Key Concepts
Developer
4 6 10
8
Resource Group Resource Group Resource Group Resource Group
Dev QA
Prod
Stage
Real-World
Demo 23
© Kalyan Reddy Daida StackSimplify
Github Azure Azure
DevOps Pipelines Starter
Pipelines
Real-World
Demo 23
Azure
IaC DevOps
Continuous Integration Pipelines
Build Pipelines
© Kalyan Reddy Daida StackSimplify
Azure Pipelines – Key Concepts
Developer
Agent: 1800
Minutes Free
Usually, it takes 2 to 3
business days for
approval.
It got approved for me
in 24 hours.
Real-World
Demo 23
Azure
IaC DevOps
Continuous Delivery Pipelines
Release Pipelines
© Kalyan Reddy Daida StackSimplify
Azure DevOps – Release Pipelines
To achieve Continuous Delivery we use Release Pipelines
4 6 10
8
Resource Group Resource Group Resource Group Resource Group
Dev QA
Prod
Stage
Demo 24
Gateway Scale Sets
Azure
MySQL Single Server
Resource
Group
Virtual Network
Web Tier
Subnet
App1 VMSS
VNET Service
+ Endpoint
Web
NSG
MySQL Virtual
Azure Network Rule
AG Subnet
Application
http://terraformguru.com Gateway LB
https://terraformguru.com
Azure
HTTP AG Storage
SSL Azure MySQL
LB Public IP
To Error Account Single Server
Users HTTPs Certs
Pages
Redirect
AG
NSG 502.html 403.html
azurerm_mysql_database
Input Variables Sensitive Flag = True
azurerm_mysql_firewall_rule
azurerm_mysql_virtual_network_rule
UMS Web App with Create User, List User, UMS Web App DB information can be passed via
Login and Logout Features Environment Variables (DB Name, Port User, Pass)
UMS Web App needs MySQL DB to store its We can login with new users created to UMS
users. If connection to DB fails, it cannot start Web App
Real-World
Demo 24
© Kalyan Reddy Daida StackSimplify
Terraform
Modules
A Terraform module (usually the root module of a In addition to modules from the local filesystem,
configuration) can call other modules to include Terraform can load modules from a public or private
their resources into the configuration. registry.
Demo 1
Demo 3
Demo 4
Demo 5
Demo 6
© Kalyan Reddy Daida StackSimplify
Practical Examples & Step-by-Step
Documentation on Github
2 Hour 10 Minutes