Updated code for two VMSS articles
This commit is contained in:
parent
1bb60e6a06
commit
a7b8413823
@ -15,9 +15,7 @@ resource "azurerm_resource_group" "vmss" {
|
|||||||
name = var.resource_group_name
|
name = var.resource_group_name
|
||||||
location = var.location
|
location = var.location
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_virtual_network" "vmss" {
|
resource "azurerm_virtual_network" "vmss" {
|
||||||
@ -26,16 +24,14 @@ resource "azurerm_virtual_network" "vmss" {
|
|||||||
location = var.location
|
location = var.location
|
||||||
resource_group_name = azurerm_resource_group.vmss.name
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_subnet" "vmss" {
|
resource "azurerm_subnet" "vmss" {
|
||||||
name = "vmss-subnet"
|
name = "vmss-subnet"
|
||||||
resource_group_name = azurerm_resource_group.vmss.name
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
virtual_network_name = azurerm_virtual_network.vmss.name
|
virtual_network_name = azurerm_virtual_network.vmss.name
|
||||||
address_prefix = "10.0.2.0/24"
|
address_prefixes = ["10.0.2.0/24"]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_public_ip" "vmss" {
|
resource "azurerm_public_ip" "vmss" {
|
||||||
@ -43,11 +39,8 @@ resource "azurerm_public_ip" "vmss" {
|
|||||||
location = var.location
|
location = var.location
|
||||||
resource_group_name = azurerm_resource_group.vmss.name
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
allocation_method = "Static"
|
allocation_method = "Static"
|
||||||
domain_name_label = azurerm_resource_group.vmss.name
|
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_lb" "vmss" {
|
resource "azurerm_lb" "vmss" {
|
||||||
@ -60,13 +53,10 @@ resource "azurerm_lb" "vmss" {
|
|||||||
public_ip_address_id = azurerm_public_ip.vmss.id
|
public_ip_address_id = azurerm_public_ip.vmss.id
|
||||||
}
|
}
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_lb_backend_address_pool" "bpepool" {
|
resource "azurerm_lb_backend_address_pool" "bpepool" {
|
||||||
resource_group_name = azurerm_resource_group.vmss.name
|
|
||||||
loadbalancer_id = azurerm_lb.vmss.id
|
loadbalancer_id = azurerm_lb.vmss.id
|
||||||
name = "BackEndAddressPool"
|
name = "BackEndAddressPool"
|
||||||
}
|
}
|
||||||
@ -91,11 +81,11 @@ resource "azurerm_lb_rule" "lbnatrule" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data "azurerm_resource_group" "image" {
|
data "azurerm_resource_group" "image" {
|
||||||
name = "myResourceGroup"
|
name = var.packer_resource_group_name
|
||||||
}
|
}
|
||||||
|
|
||||||
data "azurerm_image" "image" {
|
data "azurerm_image" "image" {
|
||||||
name = "myPackerImage"
|
name = var.packer_image_name
|
||||||
resource_group_name = data.azurerm_resource_group.image.name
|
resource_group_name = data.azurerm_resource_group.image.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,9 +146,7 @@ resource "azurerm_virtual_machine_scale_set" "vmss" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_public_ip" "jumpbox" {
|
resource "azurerm_public_ip" "jumpbox" {
|
||||||
@ -166,11 +154,8 @@ resource "azurerm_public_ip" "jumpbox" {
|
|||||||
location = var.location
|
location = var.location
|
||||||
resource_group_name = azurerm_resource_group.vmss.name
|
resource_group_name = azurerm_resource_group.vmss.name
|
||||||
allocation_method = "Static"
|
allocation_method = "Static"
|
||||||
domain_name_label = "${azurerm_resource_group.vmss.name}-ssh"
|
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_network_interface" "jumpbox" {
|
resource "azurerm_network_interface" "jumpbox" {
|
||||||
@ -185,9 +170,7 @@ resource "azurerm_network_interface" "jumpbox" {
|
|||||||
public_ip_address_id = azurerm_public_ip.jumpbox.id
|
public_ip_address_id = azurerm_public_ip.jumpbox.id
|
||||||
}
|
}
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_virtual_machine" "jumpbox" {
|
resource "azurerm_virtual_machine" "jumpbox" {
|
||||||
@ -226,8 +209,6 @@ resource "azurerm_virtual_machine" "jumpbox" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tags = {
|
tags = var.tags
|
||||||
environment = "codelab"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,27 @@
|
|||||||
|
|
||||||
This template deploys an Azure virtual machine scale set with a jumpbox from a Packer custom image.
|
This template deploys an Azure virtual machine scale set with a jumpbox from a Packer custom image.
|
||||||
|
|
||||||
## Resources
|
|
||||||
|
|
||||||
| Terraform Resource Type | Description |
|
| Terraform Resource Type | Description |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `azurerm_resource_group` | The resource group all resources are deployed into |
|
[azurerm_image](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image) | Manages a Shared Image within a Shared Image Gallery.|
|
||||||
|
[azurerm_lb](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb) | Manages a Load Balancer Resource. |
|
||||||
|
[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. |
|
||||||
|
[azurerm_lb_probe](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_probe) | Manages a LoadBalancer Probe Resource. |
|
||||||
|
[azurerm_lb_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_rule) | Manages a Load Balancer Rule. |
|
||||||
|
[azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | Manages a Network Interface. |
|
||||||
|
[azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | Manages a Public IP Address. |
|
||||||
|
[azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | Manages a Resource Group. |
|
||||||
|
[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. |
|
||||||
|
[azurerm_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine) | Manages a Virtual Machine. |
|
||||||
|
[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. |
|
||||||
|
[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. |
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|-|-|
|
|-|-|
|
||||||
|
| `packer_resource_group_name` | Name of the resource group in which the Packer image will be created |
|
||||||
|
| `packer_image_name` | Name of the Packer image |
|
||||||
| `resource_group_name` | Name of the resource group in which the resources will be created |
|
| `resource_group_name` | Name of the resource group in which the resources will be created |
|
||||||
| `location` | Location where resources will be create |
|
| `location` | Location where resources will be create |
|
||||||
| `tags` | Map of the tags to use for the resources that are deployed |
|
| `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
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
To see how to run this example, see [Create an Azure virtual machine scale set from a Packer custom image by using Terraform
|
To see how to run this example, see [Create an Azure virtual machine scale set from a Packer custom image by using Terraform
|
||||||
](https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-using-packer-hcl#create-an-azure-image-by-using-packer).
|
](https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-using-packer-hcl#create-an-azure-image-by-using-packer).
|
||||||
|
38
quickstart/201-vmss-packer-jumpbox/ubuntu.json
Normal file
38
quickstart/201-vmss-packer-jumpbox/ubuntu.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"builders": [{
|
||||||
|
"type": "azure-arm",
|
||||||
|
|
||||||
|
"client_id": "0bfc2293-4d69-49b5-83f7-bf0d60d20c45",
|
||||||
|
"client_secret": "G3.6ytCh44Kcla~_JRPBDLkzsXLOa3edDL",
|
||||||
|
"tenant_id": "c3fd441d-b8ad-487e-aa27-453079018fca",
|
||||||
|
"subscription_id": "b162117f-53fa-4f42-8c77-6a65ca966c40",
|
||||||
|
|
||||||
|
"managed_image_resource_group_name": "myPackerImages",
|
||||||
|
"managed_image_name": "myPackerImage",
|
||||||
|
|
||||||
|
"os_type": "Linux",
|
||||||
|
"image_publisher": "Canonical",
|
||||||
|
"image_offer": "UbuntuServer",
|
||||||
|
"image_sku": "16.04-LTS",
|
||||||
|
|
||||||
|
"azure_tags": {
|
||||||
|
"dept": "Engineering",
|
||||||
|
"task": "Image deployment"
|
||||||
|
},
|
||||||
|
|
||||||
|
"location": "East US",
|
||||||
|
"vm_size": "Standard_DS2_v2"
|
||||||
|
}],
|
||||||
|
"provisioners": [{
|
||||||
|
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
|
||||||
|
"inline": [
|
||||||
|
"apt-get update",
|
||||||
|
"apt-get upgrade -y",
|
||||||
|
"apt-get -y install nginx",
|
||||||
|
|
||||||
|
"/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
|
||||||
|
],
|
||||||
|
"inline_shebang": "/bin/sh -x",
|
||||||
|
"type": "shell"
|
||||||
|
}]
|
||||||
|
}
|
@ -1,3 +1,18 @@
|
|||||||
|
variable "packer_resource_group_name" {
|
||||||
|
description = "Name of the resource group in which the Packer image will be created"
|
||||||
|
default = "myPackerImages"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "packer_image_name" {
|
||||||
|
description = "Name of the Packer image"
|
||||||
|
default = "myPackerImage"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_group_name" {
|
||||||
|
description = "Name of the resource group in which the Packer image will be created"
|
||||||
|
default = "myPackerImages"
|
||||||
|
}
|
||||||
|
|
||||||
variable "resource_group_name" {
|
variable "resource_group_name" {
|
||||||
description = "Name of the resource group in which the resources will be created"
|
description = "Name of the resource group in which the resources will be created"
|
||||||
default = "myResourceGroup"
|
default = "myResourceGroup"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user