Skip to content

Commit b452851

Browse files
committed
Added code for create-vm-scaleset-network-disks-hcl
1 parent ef2d32c commit b452851

File tree

7 files changed

+271
-26
lines changed

7 files changed

+271
-26
lines changed
Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Create Azure resource group
1+
# Azure resource group
22

33
This template deploys an Azure resource group.
44

@@ -18,27 +18,4 @@ This template deploys an Azure resource group.
1818

1919
## Example
2020

21-
```bash
22-
terraform plan -out main.tfplan
23-
24-
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
25-
+ create
26-
27-
Terraform will perform the following actions:
28-
29-
# azurerm_resource_group.rg will be created
30-
+ resource "azurerm_resource_group" "rg" {
31-
+ id = (known after apply)
32-
+ location = "eastus"
33-
+ name = "sample-dev-rg"
34-
}
35-
36-
Plan: 1 to add, 0 to change, 0 to destroy.
37-
38-
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
39-
40-
Saved the plan to: main.tfplan
41-
42-
To perform exactly these actions, run the following command to apply:
43-
terraform apply "main.tfplan"
44-
```
21+
To see how to run this example, see [https://docs.microsoft.com/azure/developer/terraform/create-resource-group]

quickstart/201-vmss-appgw-waf/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This template deploys a Virtual Machine Scale Set fronted by an Azure Applicatio
1515
| Name | Description |
1616
|-|-|
1717
| `name` | Name of the deployment |
18-
| `environment` | The depolyment environment name (used for postfixing resource names) |
18+
| `environment` | The deployment environment name (used for postfixing resource names) |
1919
| `prefix` | A prefix for globally-unique dns-based resources |
2020
| `location` | The Azure Region to deploy these resources in |
2121

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "~>2.0"
6+
}
7+
}
8+
}
9+
10+
provider "azurerm" {
11+
features {}
12+
}
13+
14+
resource "azurerm_resource_group" "vmss" {
15+
name = var.resource_group_name
16+
location = var.location
17+
tags = var.tags
18+
}
19+
20+
resource "random_string" "fqdn" {
21+
length = 6
22+
special = false
23+
upper = false
24+
number = false
25+
}
26+
27+
resource "azurerm_virtual_network" "vmss" {
28+
name = "vmss-vnet"
29+
address_space = ["10.0.0.0/16"]
30+
location = var.location
31+
resource_group_name = azurerm_resource_group.vmss.name
32+
tags = var.tags
33+
}
34+
35+
resource "azurerm_subnet" "vmss" {
36+
name = "vmss-subnet"
37+
resource_group_name = azurerm_resource_group.vmss.name
38+
virtual_network_name = azurerm_virtual_network.vmss.name
39+
address_prefixes = ["10.0.2.0/24"]
40+
}
41+
42+
resource "azurerm_public_ip" "vmss" {
43+
name = "vmss-public-ip"
44+
location = var.location
45+
resource_group_name = azurerm_resource_group.vmss.name
46+
allocation_method = "Static"
47+
domain_name_label = random_string.fqdn.result
48+
tags = var.tags
49+
}
50+
51+
resource "azurerm_lb" "vmss" {
52+
name = "vmss-lb"
53+
location = var.location
54+
resource_group_name = azurerm_resource_group.vmss.name
55+
56+
frontend_ip_configuration {
57+
name = "PublicIPAddress"
58+
public_ip_address_id = azurerm_public_ip.vmss.id
59+
}
60+
61+
tags = var.tags
62+
}
63+
64+
resource "azurerm_lb_backend_address_pool" "bpepool" {
65+
loadbalancer_id = azurerm_lb.vmss.id
66+
name = "BackEndAddressPool"
67+
}
68+
69+
resource "azurerm_lb_probe" "vmss" {
70+
resource_group_name = azurerm_resource_group.vmss.name
71+
loadbalancer_id = azurerm_lb.vmss.id
72+
name = "ssh-running-probe"
73+
port = var.application_port
74+
}
75+
76+
resource "azurerm_lb_rule" "lbnatrule" {
77+
resource_group_name = azurerm_resource_group.vmss.name
78+
loadbalancer_id = azurerm_lb.vmss.id
79+
name = "http"
80+
protocol = "Tcp"
81+
frontend_port = var.application_port
82+
backend_port = var.application_port
83+
backend_address_pool_id = azurerm_lb_backend_address_pool.bpepool.id
84+
frontend_ip_configuration_name = "PublicIPAddress"
85+
probe_id = azurerm_lb_probe.vmss.id
86+
}
87+
88+
resource "azurerm_virtual_machine_scale_set" "vmss" {
89+
name = "vmscaleset"
90+
location = var.location
91+
resource_group_name = azurerm_resource_group.vmss.name
92+
upgrade_policy_mode = "Manual"
93+
94+
sku {
95+
name = "Standard_DS1_v2"
96+
tier = "Standard"
97+
capacity = 2
98+
}
99+
100+
storage_profile_image_reference {
101+
publisher = "Canonical"
102+
offer = "UbuntuServer"
103+
sku = "16.04-LTS"
104+
version = "latest"
105+
}
106+
107+
storage_profile_os_disk {
108+
name = ""
109+
caching = "ReadWrite"
110+
create_option = "FromImage"
111+
managed_disk_type = "Standard_LRS"
112+
}
113+
114+
storage_profile_data_disk {
115+
lun = 0
116+
caching = "ReadWrite"
117+
create_option = "Empty"
118+
disk_size_gb = 10
119+
}
120+
121+
os_profile {
122+
computer_name_prefix = "vmlab"
123+
admin_username = var.admin_user
124+
admin_password = var.admin_password
125+
custom_data = file("web.conf")
126+
}
127+
128+
os_profile_linux_config {
129+
disable_password_authentication = false
130+
}
131+
132+
network_profile {
133+
name = "terraformnetworkprofile"
134+
primary = true
135+
136+
ip_configuration {
137+
name = "IPConfiguration"
138+
subnet_id = azurerm_subnet.vmss.id
139+
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
140+
primary = true
141+
}
142+
}
143+
144+
tags = var.tags
145+
}
146+
147+
resource "azurerm_public_ip" "jumpbox" {
148+
name = "jumpbox-public-ip"
149+
location = var.location
150+
resource_group_name = azurerm_resource_group.vmss.name
151+
allocation_method = "Static"
152+
domain_name_label = "${random_string.fqdn.result}-ssh"
153+
tags = var.tags
154+
}
155+
156+
resource "azurerm_network_interface" "jumpbox" {
157+
name = "jumpbox-nic"
158+
location = var.location
159+
resource_group_name = azurerm_resource_group.vmss.name
160+
161+
ip_configuration {
162+
name = "IPConfiguration"
163+
subnet_id = azurerm_subnet.vmss.id
164+
private_ip_address_allocation = "dynamic"
165+
public_ip_address_id = azurerm_public_ip.jumpbox.id
166+
}
167+
168+
tags = var.tags
169+
}
170+
171+
resource "azurerm_virtual_machine" "jumpbox" {
172+
name = "jumpbox"
173+
location = var.location
174+
resource_group_name = azurerm_resource_group.vmss.name
175+
network_interface_ids = [azurerm_network_interface.jumpbox.id]
176+
vm_size = "Standard_DS1_v2"
177+
178+
storage_image_reference {
179+
publisher = "Canonical"
180+
offer = "UbuntuServer"
181+
sku = "16.04-LTS"
182+
version = "latest"
183+
}
184+
185+
storage_os_disk {
186+
name = "jumpbox-osdisk"
187+
caching = "ReadWrite"
188+
create_option = "FromImage"
189+
managed_disk_type = "Standard_LRS"
190+
}
191+
192+
os_profile {
193+
computer_name = "jumpbox"
194+
admin_username = var.admin_user
195+
admin_password = var.admin_password
196+
}
197+
198+
os_profile_linux_config {
199+
disable_password_authentication = false
200+
}
201+
202+
tags = var.tags
203+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "vmss_public_ip" {
2+
value = azurerm_public_ip.vmss.fqdn
3+
}
4+
5+
output "jumpbox_public_ip" {
6+
value = azurerm_public_ip.jumpbox.fqdn
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Azure virtual machine scale set with jumpbox
2+
3+
This template deploys an Azure virtual machine scale set with a jumpbox.
4+
5+
## Resources
6+
7+
| Terraform Resource Type | Description |
8+
| - | - |
9+
| `azurerm_resource_group` | The resource group all resources are deployed into |
10+
11+
## Variables
12+
13+
| Name | Description |
14+
|-|-|
15+
| `resource_group_name` | Name of the resource group in which the resources will be created |
16+
| `location` | Location where resources will be create |
17+
| `tags` | Map of the tags to use for the resources that are deployed |
18+
| `application_port` | Port that you want to expose to the external load balancer |
19+
| `admin_user` | User name to use as the admin account on the VMs that will be part of the VM scale set |
20+
| `admin_password` | Default password for admin account (NOTE: For security reasons, this value is not set in the plaintext variables.tf file.) |
21+
22+
## Example
23+
24+
To see how to run this example, see [https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-hcl]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "resource_group_name" {
2+
description = "Name of the resource group in which the resources will be created"
3+
default = "myResourceGroup"
4+
}
5+
6+
variable "location" {
7+
default = "eastus"
8+
description = "Location where resources will be created"
9+
}
10+
11+
variable "tags" {
12+
description = "Map of the tags to use for the resources that are deployed"
13+
type = map(string)
14+
default = {
15+
environment = "codelab"
16+
}
17+
}
18+
19+
variable "application_port" {
20+
description = "Port that you want to expose to the external load balancer"
21+
default = 80
22+
}
23+
24+
variable "admin_user" {
25+
description = "User name to use as the admin account on the VMs that will be part of the VM scale set"
26+
default = "azureuser"
27+
}
28+
29+
variable "admin_password" {
30+
description = "Default password for admin account"
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#cloud-config
2+
packages:
3+
- nginx

0 commit comments

Comments
 (0)