Skip to content

Commit bd38157

Browse files
committed
First cut of Azure VM Demo.
1 parent 5dbd0c9 commit bd38157

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

azure/main.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This azure main.tf file configures
2+
# - The baseline terraform registery for Azure
3+
# - The backend terraform uses to store STATE
4+
# - Authenication with Azure via Service Principle
5+
# - Basic Azure structures such as resource groups
6+
7+
8+
# Configure terraform resource providers and remote backend state management
9+
10+
terraform {
11+
required_providers {
12+
azurerm = {
13+
source = "hashicorp/azurerm"
14+
version = "3.65.0"
15+
}
16+
}
17+
}
18+
19+
# Configure the Azure provider to use specific subscription + other parameters
20+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest
21+
22+
provider "azurerm" {
23+
features {
24+
25+
resource_group {
26+
prevent_deletion_if_contains_resources = false
27+
}
28+
29+
}
30+
31+
skip_provider_registration = true
32+
33+
tenant_id = var.TENANT_ID
34+
subscription_id = var.SUBSCRIPTION_ID
35+
client_id = var.CLIENT_ID
36+
client_secret = var.CLIENT_SECRET
37+
}
38+
39+
# Create azure resource group
40+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
41+
42+
resource "azurerm_resource_group" "rg" {
43+
name = "rg-tim-demo-uksouth"
44+
location = "UK South"
45+
}

azure/terraform.tfvars.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# tfvars files are used by terraform to pass secret values to terraform at runtime
2+
3+
# this file is typically dynamaically created at runtime in a CI/CD pipeline using a key vault
4+
5+
# Baseline variables needed to use this terraform
6+
7+
TENANT_ID = "????????-????-????-????-????????????"
8+
SUBSCRIPTION_ID = "????????-????-????-????-?????????????"
9+
CLIENT_ID = "?????????????"
10+
CLIENT_SECRET = "?????????????"

azure/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file defines baseline variables used across this TF deployment
2+
3+
# These will typically be provided at Runtime in a CI/CD pipeline from a key vault
4+
5+
variable "TENANT_ID" {
6+
type = string
7+
}
8+
9+
variable "SUBSCRIPTION_ID" {
10+
type = string
11+
}
12+
13+
variable "CLIENT_ID" {
14+
type = string
15+
}
16+
17+
variable "CLIENT_SECRET" {
18+
type = string
19+
}

azure/vm.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# References:
2+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network
3+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet
4+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip
5+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface
6+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine
7+
8+
resource "azurerm_virtual_network" "vn" {
9+
name = "tim-demo-network"
10+
address_space = ["10.0.0.0/16"]
11+
location = azurerm_resource_group.rg.location
12+
resource_group_name = azurerm_resource_group.rg.name
13+
}
14+
15+
resource "azurerm_subnet" "sn" {
16+
name = "internal"
17+
resource_group_name = azurerm_resource_group.rg.name
18+
virtual_network_name = azurerm_virtual_network.vn.name
19+
address_prefixes = ["10.0.2.0/24"]
20+
}
21+
22+
resource "azurerm_public_ip" "pip" {
23+
name = "tim-demo-pip"
24+
resource_group_name = azurerm_resource_group.rg.name
25+
location = azurerm_resource_group.rg.location
26+
allocation_method = "Dynamic"
27+
}
28+
29+
resource "azurerm_network_interface" "ni" {
30+
name = "tim-demo-nic"
31+
location = azurerm_resource_group.rg.location
32+
resource_group_name = azurerm_resource_group.rg.name
33+
34+
ip_configuration {
35+
name = "internal"
36+
subnet_id = azurerm_subnet.sn.id
37+
private_ip_address_allocation = "Dynamic"
38+
39+
public_ip_address_id = azurerm_public_ip.pip.id
40+
}
41+
}
42+
43+
resource "azurerm_linux_virtual_machine" "vm" {
44+
name = "tim-demo-vm"
45+
resource_group_name = azurerm_resource_group.rg.name
46+
location = azurerm_resource_group.rg.location
47+
size = "Standard_F2"
48+
admin_username = "adminuser"
49+
network_interface_ids = [
50+
azurerm_network_interface.ni.id,
51+
]
52+
53+
admin_ssh_key {
54+
username = "adminuser"
55+
public_key = file("C:/Users/tim_hall/Dropbox/cloud/Azure/id_rsa.pub")
56+
}
57+
58+
os_disk {
59+
caching = "ReadWrite"
60+
storage_account_type = "Standard_LRS"
61+
}
62+
63+
source_image_reference {
64+
publisher = "Canonical"
65+
offer = "0001-com-ubuntu-server-focal"
66+
sku = "20_04-lts"
67+
version = "latest"
68+
}
69+
}

0 commit comments

Comments
 (0)