This Terraform module deploys the following :
- Virtual Machine scalesets across Availability Zones with a default count of 3 based on Windows or Linux, standard or custom images
- Network Security Group with default inbound rule to allow remote access to the VMs (port 22 or 3389)
- Standard load balancer with the scaleset VMs added to the backend pool
Code block deploys VM scalesets across the AV zones based on the latest version of Ubuntu 18.04-LTS image.
resource "azurerm_resource_group" "mytfrg" {
name = "scaleset-rg"
location = "WestEurope"
}
resource "azurerm_virtual_network" "mytfvnet" {
name = "${var.scaleset_name}-vnet"
resource_group_name = "${azurerm_resource_group.mytfrg.name}"
location = "WestEurope"
address_space = ["172.17.0.0/16"]
}
resource "azurerm_subnet" "mytfsubnet" {
name = "subnet1"
resource_group_name = "${azurerm_virtual_network.mytfvnet.resource_group_name}"
virtual_network_name = "${azurerm_virtual_network.mytfvnet.name}"
address_prefix = "172.17.0.0/24"
}
module "linux-vm" {
source = "Azure/scalesets/azurerm"
location = "WestEurope"
adminPassword = "azvmss@123456"
os_type = "linux"
dns_name = "lbvmsslinux"
vnet_subnet_id = "${azurerm_subnet.mytfsubnet.id}"
}
Code block deploys VM scalesets across the AV zones based on the latest version of Windows Server 2016 image.
resource "azurerm_resource_group" "mytfrg" {
name = "scaleset-rg"
location = "WestEurope"
}
resource "azurerm_virtual_network" "mytfvnet" {
name = "${var.scaleset_name}-vnet"
resource_group_name = "${azurerm_resource_group.mytfrg.name}"
location = "WestEurope"
address_space = ["172.17.0.0/16"]
}
resource "azurerm_subnet" "mytfsubnet" {
name = "subnet1"
resource_group_name = "${azurerm_virtual_network.mytfvnet.resource_group_name}"
virtual_network_name = "${azurerm_virtual_network.mytfvnet.name}"
address_prefix = "172.17.0.0/24"
}
module "windows-vm" {
source = "../../"
resource_group_name = "${azurerm_subnet.mytfsubnet.resource_group_name}-win"
name = "${var.scaleset_name}"
location = "WestEurope"
adminPassword = "Welcome@123456"
os_type = "windows"
dns_name = "${var.dns_name}win"
vnet_subnet_id = "${azurerm_subnet.mytfsubnet.id}"
}
To create a scaleset with standard image OS publisher, offer, SKU and version needs to be specified. For custom images, image id needs to be specified.
We provide 2 ways to build, run, and test the module on a local development machine. Native (Mac/Linux) or Docker.
We provide simple script to quickly set up module development environment:
$ curl -sSL https://raw.githubusercontent.com/Azure/terramodtest/master/tool/env_setup.sh | sudo bash
Then simply run it in local shell:
$ cd $GOPATH/src/{directory_name}/
$ ./test.sh full
We provide a Dockerfile to build a new image based FROM
the microsoft/terraform-test
Docker hub image which adds additional tools / packages specific for this module.
$ docker build -t terraform-azurerm-scalesets .
This runs the local validation:
$ docker run --rm terraform-azurerm-scalesets /bin/bash -c "./test.sh validate"
This runs the full tests (deploys resources into your Azure subscription):
$ docker run -e "ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID" -e "ARM_CLIENT_ID=$AZURE_CLIENT_ID" -e "ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET" -e "ARM_TENANT_ID=$AZURE_TENANT_ID" -e "ARM_TEST_LOCATION=WestEurope" -e "ARM_TEST_LOCATION_ALT=NorthEurope" --rm terraform-azurerm-scalesets bash -c "./test.sh full"
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.