Added code for create-vm-scaleset-network-disks-hcl
This commit is contained in:
parent
ef2d32ca99
commit
b4528513d2
@ -1,4 +1,4 @@
|
||||
# Create Azure resource group
|
||||
# Azure resource group
|
||||
|
||||
This template deploys an Azure resource group.
|
||||
|
||||
@ -18,27 +18,4 @@ This template deploys an Azure resource group.
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
terraform plan -out main.tfplan
|
||||
|
||||
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
|
||||
+ create
|
||||
|
||||
Terraform will perform the following actions:
|
||||
|
||||
# azurerm_resource_group.rg will be created
|
||||
+ resource "azurerm_resource_group" "rg" {
|
||||
+ id = (known after apply)
|
||||
+ location = "eastus"
|
||||
+ name = "sample-dev-rg"
|
||||
}
|
||||
|
||||
Plan: 1 to add, 0 to change, 0 to destroy.
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Saved the plan to: main.tfplan
|
||||
|
||||
To perform exactly these actions, run the following command to apply:
|
||||
terraform apply "main.tfplan"
|
||||
```
|
||||
To see how to run this example, see [https://docs.microsoft.com/azure/developer/terraform/create-resource-group]
|
@ -15,7 +15,7 @@ This template deploys a Virtual Machine Scale Set fronted by an Azure Applicatio
|
||||
| Name | Description |
|
||||
|-|-|
|
||||
| `name` | Name of the deployment |
|
||||
| `environment` | The depolyment environment name (used for postfixing resource names) |
|
||||
| `environment` | The deployment environment name (used for postfixing resource names) |
|
||||
| `prefix` | A prefix for globally-unique dns-based resources |
|
||||
| `location` | The Azure Region to deploy these resources in |
|
||||
|
||||
|
203
quickstart/201-vmss-jumpbox/main.tf
Normal file
203
quickstart/201-vmss-jumpbox/main.tf
Normal file
@ -0,0 +1,203 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~>2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
|
||||
resource "azurerm_resource_group" "vmss" {
|
||||
name = var.resource_group_name
|
||||
location = var.location
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "random_string" "fqdn" {
|
||||
length = 6
|
||||
special = false
|
||||
upper = false
|
||||
number = false
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_network" "vmss" {
|
||||
name = "vmss-vnet"
|
||||
address_space = ["10.0.0.0/16"]
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_subnet" "vmss" {
|
||||
name = "vmss-subnet"
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
virtual_network_name = azurerm_virtual_network.vmss.name
|
||||
address_prefixes = ["10.0.2.0/24"]
|
||||
}
|
||||
|
||||
resource "azurerm_public_ip" "vmss" {
|
||||
name = "vmss-public-ip"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
allocation_method = "Static"
|
||||
domain_name_label = random_string.fqdn.result
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_lb" "vmss" {
|
||||
name = "vmss-lb"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
|
||||
frontend_ip_configuration {
|
||||
name = "PublicIPAddress"
|
||||
public_ip_address_id = azurerm_public_ip.vmss.id
|
||||
}
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_lb_backend_address_pool" "bpepool" {
|
||||
loadbalancer_id = azurerm_lb.vmss.id
|
||||
name = "BackEndAddressPool"
|
||||
}
|
||||
|
||||
resource "azurerm_lb_probe" "vmss" {
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
loadbalancer_id = azurerm_lb.vmss.id
|
||||
name = "ssh-running-probe"
|
||||
port = var.application_port
|
||||
}
|
||||
|
||||
resource "azurerm_lb_rule" "lbnatrule" {
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
loadbalancer_id = azurerm_lb.vmss.id
|
||||
name = "http"
|
||||
protocol = "Tcp"
|
||||
frontend_port = var.application_port
|
||||
backend_port = var.application_port
|
||||
backend_address_pool_id = azurerm_lb_backend_address_pool.bpepool.id
|
||||
frontend_ip_configuration_name = "PublicIPAddress"
|
||||
probe_id = azurerm_lb_probe.vmss.id
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine_scale_set" "vmss" {
|
||||
name = "vmscaleset"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
upgrade_policy_mode = "Manual"
|
||||
|
||||
sku {
|
||||
name = "Standard_DS1_v2"
|
||||
tier = "Standard"
|
||||
capacity = 2
|
||||
}
|
||||
|
||||
storage_profile_image_reference {
|
||||
publisher = "Canonical"
|
||||
offer = "UbuntuServer"
|
||||
sku = "16.04-LTS"
|
||||
version = "latest"
|
||||
}
|
||||
|
||||
storage_profile_os_disk {
|
||||
name = ""
|
||||
caching = "ReadWrite"
|
||||
create_option = "FromImage"
|
||||
managed_disk_type = "Standard_LRS"
|
||||
}
|
||||
|
||||
storage_profile_data_disk {
|
||||
lun = 0
|
||||
caching = "ReadWrite"
|
||||
create_option = "Empty"
|
||||
disk_size_gb = 10
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name_prefix = "vmlab"
|
||||
admin_username = var.admin_user
|
||||
admin_password = var.admin_password
|
||||
custom_data = file("web.conf")
|
||||
}
|
||||
|
||||
os_profile_linux_config {
|
||||
disable_password_authentication = false
|
||||
}
|
||||
|
||||
network_profile {
|
||||
name = "terraformnetworkprofile"
|
||||
primary = true
|
||||
|
||||
ip_configuration {
|
||||
name = "IPConfiguration"
|
||||
subnet_id = azurerm_subnet.vmss.id
|
||||
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
|
||||
primary = true
|
||||
}
|
||||
}
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_public_ip" "jumpbox" {
|
||||
name = "jumpbox-public-ip"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
allocation_method = "Static"
|
||||
domain_name_label = "${random_string.fqdn.result}-ssh"
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_network_interface" "jumpbox" {
|
||||
name = "jumpbox-nic"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
|
||||
ip_configuration {
|
||||
name = "IPConfiguration"
|
||||
subnet_id = azurerm_subnet.vmss.id
|
||||
private_ip_address_allocation = "dynamic"
|
||||
public_ip_address_id = azurerm_public_ip.jumpbox.id
|
||||
}
|
||||
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "jumpbox" {
|
||||
name = "jumpbox"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vmss.name
|
||||
network_interface_ids = [azurerm_network_interface.jumpbox.id]
|
||||
vm_size = "Standard_DS1_v2"
|
||||
|
||||
storage_image_reference {
|
||||
publisher = "Canonical"
|
||||
offer = "UbuntuServer"
|
||||
sku = "16.04-LTS"
|
||||
version = "latest"
|
||||
}
|
||||
|
||||
storage_os_disk {
|
||||
name = "jumpbox-osdisk"
|
||||
caching = "ReadWrite"
|
||||
create_option = "FromImage"
|
||||
managed_disk_type = "Standard_LRS"
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name = "jumpbox"
|
||||
admin_username = var.admin_user
|
||||
admin_password = var.admin_password
|
||||
}
|
||||
|
||||
os_profile_linux_config {
|
||||
disable_password_authentication = false
|
||||
}
|
||||
|
||||
tags = var.tags
|
||||
}
|
7
quickstart/201-vmss-jumpbox/output.tf
Normal file
7
quickstart/201-vmss-jumpbox/output.tf
Normal file
@ -0,0 +1,7 @@
|
||||
output "vmss_public_ip" {
|
||||
value = azurerm_public_ip.vmss.fqdn
|
||||
}
|
||||
|
||||
output "jumpbox_public_ip" {
|
||||
value = azurerm_public_ip.jumpbox.fqdn
|
||||
}
|
24
quickstart/201-vmss-jumpbox/readme.md
Normal file
24
quickstart/201-vmss-jumpbox/readme.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Azure virtual machine scale set with jumpbox
|
||||
|
||||
This template deploys an Azure virtual machine scale set with a jumpbox.
|
||||
|
||||
## Resources
|
||||
|
||||
| Terraform Resource Type | Description |
|
||||
| - | - |
|
||||
| `azurerm_resource_group` | The resource group all resources are deployed into |
|
||||
|
||||
## Variables
|
||||
|
||||
| Name | Description |
|
||||
|-|-|
|
||||
| `resource_group_name` | Name of the resource group in which the resources will be created |
|
||||
| `location` | Location where resources will be create |
|
||||
| `tags` | Map of the tags to use for the resources that are deployed |
|
||||
| `application_port` | Port that you want to expose to the external load balancer |
|
||||
| `admin_user` | User name to use as the admin account on the VMs that will be part of the VM scale set |
|
||||
| `admin_password` | Default password for admin account (NOTE: For security reasons, this value is not set in the plaintext variables.tf file.) |
|
||||
|
||||
## Example
|
||||
|
||||
To see how to run this example, see [https://docs.microsoft.com/azure/developer/terraform/create-vm-scaleset-network-disks-hcl]
|
31
quickstart/201-vmss-jumpbox/variables.tf
Normal file
31
quickstart/201-vmss-jumpbox/variables.tf
Normal file
@ -0,0 +1,31 @@
|
||||
variable "resource_group_name" {
|
||||
description = "Name of the resource group in which the resources will be created"
|
||||
default = "myResourceGroup"
|
||||
}
|
||||
|
||||
variable "location" {
|
||||
default = "eastus"
|
||||
description = "Location where resources will be created"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Map of the tags to use for the resources that are deployed"
|
||||
type = map(string)
|
||||
default = {
|
||||
environment = "codelab"
|
||||
}
|
||||
}
|
||||
|
||||
variable "application_port" {
|
||||
description = "Port that you want to expose to the external load balancer"
|
||||
default = 80
|
||||
}
|
||||
|
||||
variable "admin_user" {
|
||||
description = "User name to use as the admin account on the VMs that will be part of the VM scale set"
|
||||
default = "azureuser"
|
||||
}
|
||||
|
||||
variable "admin_password" {
|
||||
description = "Default password for admin account"
|
||||
}
|
3
quickstart/201-vmss-jumpbox/web.conf
Normal file
3
quickstart/201-vmss-jumpbox/web.conf
Normal file
@ -0,0 +1,3 @@
|
||||
#cloud-config
|
||||
packages:
|
||||
- nginx
|
Loading…
x
Reference in New Issue
Block a user