Skip to content

Commit a7b8413

Browse files
committed
Updated code for two VMSS articles
1 parent 1bb60e6 commit a7b8413

File tree

4 files changed

+79
-34
lines changed

4 files changed

+79
-34
lines changed

quickstart/201-vmss-packer-jumpbox/main.tf

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ resource "azurerm_resource_group" "vmss" {
1515
name = var.resource_group_name
1616
location = var.location
1717

18-
tags = {
19-
environment = "codelab"
20-
}
18+
tags = var.tags
2119
}
2220

2321
resource "azurerm_virtual_network" "vmss" {
@@ -26,28 +24,23 @@ resource "azurerm_virtual_network" "vmss" {
2624
location = var.location
2725
resource_group_name = azurerm_resource_group.vmss.name
2826

29-
tags = {
30-
environment = "codelab"
31-
}
27+
tags = var.tags
3228
}
3329

3430
resource "azurerm_subnet" "vmss" {
3531
name = "vmss-subnet"
3632
resource_group_name = azurerm_resource_group.vmss.name
3733
virtual_network_name = azurerm_virtual_network.vmss.name
38-
address_prefix = "10.0.2.0/24"
34+
address_prefixes = ["10.0.2.0/24"]
3935
}
4036

4137
resource "azurerm_public_ip" "vmss" {
4238
name = "vmss-public-ip"
4339
location = var.location
4440
resource_group_name = azurerm_resource_group.vmss.name
4541
allocation_method = "Static"
46-
domain_name_label = azurerm_resource_group.vmss.name
4742

48-
tags = {
49-
environment = "codelab"
50-
}
43+
tags = var.tags
5144
}
5245

5346
resource "azurerm_lb" "vmss" {
@@ -60,13 +53,10 @@ resource "azurerm_lb" "vmss" {
6053
public_ip_address_id = azurerm_public_ip.vmss.id
6154
}
6255

63-
tags = {
64-
environment = "codelab"
65-
}
56+
tags = var.tags
6657
}
6758

6859
resource "azurerm_lb_backend_address_pool" "bpepool" {
69-
resource_group_name = azurerm_resource_group.vmss.name
7060
loadbalancer_id = azurerm_lb.vmss.id
7161
name = "BackEndAddressPool"
7262
}
@@ -91,11 +81,11 @@ resource "azurerm_lb_rule" "lbnatrule" {
9181
}
9282

9383
data "azurerm_resource_group" "image" {
94-
name = "myResourceGroup"
84+
name = var.packer_resource_group_name
9585
}
9686

9787
data "azurerm_image" "image" {
98-
name = "myPackerImage"
88+
name = var.packer_image_name
9989
resource_group_name = data.azurerm_resource_group.image.name
10090
}
10191

@@ -156,21 +146,16 @@ resource "azurerm_virtual_machine_scale_set" "vmss" {
156146
}
157147
}
158148

159-
tags = {
160-
environment = "codelab"
161-
}
149+
tags = var.tags
162150
}
163151

164152
resource "azurerm_public_ip" "jumpbox" {
165153
name = "jumpbox-public-ip"
166154
location = var.location
167155
resource_group_name = azurerm_resource_group.vmss.name
168156
allocation_method = "Static"
169-
domain_name_label = "${azurerm_resource_group.vmss.name}-ssh"
170157

171-
tags = {
172-
environment = "codelab"
173-
}
158+
tags = var.tags
174159
}
175160

176161
resource "azurerm_network_interface" "jumpbox" {
@@ -185,9 +170,7 @@ resource "azurerm_network_interface" "jumpbox" {
185170
public_ip_address_id = azurerm_public_ip.jumpbox.id
186171
}
187172

188-
tags = {
189-
environment = "codelab"
190-
}
173+
tags = var.tags
191174
}
192175

193176
resource "azurerm_virtual_machine" "jumpbox" {
@@ -226,8 +209,6 @@ resource "azurerm_virtual_machine" "jumpbox" {
226209
}
227210
}
228211

229-
tags = {
230-
environment = "codelab"
231-
}
212+
tags = var.tags
232213
}
233214

quickstart/201-vmss-packer-jumpbox/readme.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22

33
This template deploys an Azure virtual machine scale set with a jumpbox from a Packer custom image.
44

5-
## Resources
6-
75
| Terraform Resource Type | Description |
86
| - | - |
9-
| `azurerm_resource_group` | The resource group all resources are deployed into |
7+
[azurerm_image](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image) | Manages a Shared Image within a Shared Image Gallery.|
8+
[azurerm_lb](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb) | Manages a Load Balancer Resource. |
9+
[azurerm_lb_backend_address_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_backend_address_pool) | Manages a Load Balancer Backend Address Pool. |
10+
[azurerm_lb_probe](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_probe) | Manages a LoadBalancer Probe Resource. |
11+
[azurerm_lb_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_rule) | Manages a Load Balancer Rule. |
12+
[azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | Manages a Network Interface. |
13+
[azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | Manages a Public IP Address. |
14+
[azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | Manages a Resource Group. |
15+
[azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) | Manages a subnet. Subnets represent network segments within the IP space defined by the virtual network. |
16+
[azurerm_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine) | Manages a Virtual Machine. |
17+
[azurerm_virtual_machine_scale_set](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_scale_set) | Manages a virtual machine scale set. |
18+
[azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) | Manages a virtual network including any configured subnets. Each subnet can optionally be configured with a security group to be associated with the subnet. |
1019

1120
## Variables
1221

1322
| Name | Description |
1423
|-|-|
24+
| `packer_resource_group_name` | Name of the resource group in which the Packer image will be created |
25+
| `packer_image_name` | Name of the Packer image |
1526
| `resource_group_name` | Name of the resource group in which the resources will be created |
1627
| `location` | Location where resources will be create |
1728
| `tags` | Map of the tags to use for the resources that are deployed |
@@ -22,4 +33,4 @@ This template deploys an Azure virtual machine scale set with a jumpbox from a P
2233
## Example
2334

2435
To see how to run this example, see [Create an Azure virtual machine scale set from a Packer custom image by using Terraform
25-
](https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-using-packer-hcl#create-an-azure-image-by-using-packer).
36+
](https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-using-packer-hcl#create-an-azure-image-by-using-packer).
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"builders": [{
3+
"type": "azure-arm",
4+
5+
"client_id": "0bfc2293-4d69-49b5-83f7-bf0d60d20c45",
6+
"client_secret": "G3.6ytCh44Kcla~_JRPBDLkzsXLOa3edDL",
7+
"tenant_id": "c3fd441d-b8ad-487e-aa27-453079018fca",
8+
"subscription_id": "b162117f-53fa-4f42-8c77-6a65ca966c40",
9+
10+
"managed_image_resource_group_name": "myPackerImages",
11+
"managed_image_name": "myPackerImage",
12+
13+
"os_type": "Linux",
14+
"image_publisher": "Canonical",
15+
"image_offer": "UbuntuServer",
16+
"image_sku": "16.04-LTS",
17+
18+
"azure_tags": {
19+
"dept": "Engineering",
20+
"task": "Image deployment"
21+
},
22+
23+
"location": "East US",
24+
"vm_size": "Standard_DS2_v2"
25+
}],
26+
"provisioners": [{
27+
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
28+
"inline": [
29+
"apt-get update",
30+
"apt-get upgrade -y",
31+
"apt-get -y install nginx",
32+
33+
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
34+
],
35+
"inline_shebang": "/bin/sh -x",
36+
"type": "shell"
37+
}]
38+
}

quickstart/201-vmss-packer-jumpbox/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
variable "packer_resource_group_name" {
2+
description = "Name of the resource group in which the Packer image will be created"
3+
default = "myPackerImages"
4+
}
5+
6+
variable "packer_image_name" {
7+
description = "Name of the Packer image"
8+
default = "myPackerImage"
9+
}
10+
11+
variable "resource_group_name" {
12+
description = "Name of the resource group in which the Packer image will be created"
13+
default = "myPackerImages"
14+
}
15+
116
variable "resource_group_name" {
217
description = "Name of the resource group in which the resources will be created"
318
default = "myResourceGroup"

0 commit comments

Comments
 (0)