Terraform: Data Sources > template_file

template_file renders a template from a file.

Use it with a fileor inline. E.g.

file

file refers to a file path in the current directory.

and ip_address is set to a value which can be read in the template using ${ip_address}.

 

Note: see also Terraform: Data Sources

and https://www.terraform.io/docs/providers/template/d/file.html#

Install and configure Terraform to provision VMs and other infra to Azure

Note: if you don’t want to install terraform locally then use Azure Cloud Shell

use the >_ icon in the Azure portal

Set up Terraform access to Azure

1. get your subscription ID and tenant ID

az login

az account show --query "{subscriptionId:id, tenantId:tenantId}"

and set via an environment variable:

export SUBSCRIPTION_ID=abcd-abcd-etc
az account set --subscription="${SUBSCRIPTION_ID}"

2. create an Azure AD service principal

(an Azure AD service principal is a credential for your application – https://docs.microsoft.com/en-us/azure/azure-stack/azure-stack-create-service-principals )

az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"

and note your appId, tenantID and password.

Slot them into this Terraform script (tf_env_vars.sh) to set up env vars:

#!/bin/sh
echo “Setting environment variables for Terraform”
export ARM_SUBSCRIPTION_ID=your_subscription_id
export ARM_CLIENT_ID=your_appId
export ARM_CLIENT_SECRET=your_password
export ARM_TENANT_ID=your_tenant_id

# Not needed for public, required for usgovernment, german, china
export ARM_ENVIRONMENT=public

Note: remember to apply these environment variables to your current shell. i.e. use:

. ./tf_env_vars.sh

(notice the leading dot?)

Create a test.tf file with:

and run with terraform initterraform plan and terraform apply

This should create a Resource Group.

https://docs.microsoft.com/en-us/azure/virtual-machines/linux/terraform-install-configure

Azure VM Tiers

Basic tier: Introductory level

Standard tiers:

A-series: Standard level

D-series: Faster processors, high memory-to-core ratio, SSD temp disk

Dv2-series: 35% faster than D series. Same memory/disk

DS-series: Premium storage (SSDs)

G-series: Biggest VM size. Intel Xeon E5 V3 processors

GS-series: Premium storage (SSDs)

 

Key VM IaaS Questions

  • CPU
  • RAM
  • NIC
  • Temp disk performance
  • Data disk
  • Cache size
  • Max data disk IOPS/bandwidth

 

  • Fault Domains => single point of failure (e.g. all servers in same rack fail ‘cos power fails). Place resources in separate fault domains
  • Update Domains => software updates (e.g. when server OS is updated then VMs are shifted off and then shifted back)

Azure Availability Sets => fault or update won’t take workload down. So distribute workloads across availability sets. Each workload in its own availability set (e.g. SQL server and web server in same availability set).

Note: VMs in same availability set should be of same sort.