diff --git a/quickstart/101-vm-cluster-linux/main.tf b/quickstart/101-vm-cluster-linux/main.tf new file mode 100644 index 00000000..b747c87a --- /dev/null +++ b/quickstart/101-vm-cluster-linux/main.tf @@ -0,0 +1,123 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +resource "random_pet" "azurerm_virtual_network_name" { + prefix = "vn" +} + +resource "azurerm_virtual_network" "test" { + name = random_pet.azurerm_virtual_network_name.id + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name +} + +resource "random_pet" "azurerm_subnet_name" { + prefix = "sub" +} + +resource "azurerm_subnet" "test" { + name = random_pet.azurerm_subnet_name.id + resource_group_name = azurerm_resource_group.rg.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_public_ip" "test" { + name = "publicIPForLB" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + allocation_method = "Static" +} + +resource "azurerm_lb" "test" { + name = "loadBalancer" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + frontend_ip_configuration { + name = "publicIPAddress" + public_ip_address_id = azurerm_public_ip.test.id + } +} + +resource "azurerm_lb_backend_address_pool" "test" { + loadbalancer_id = azurerm_lb.test.id + name = "BackEndAddressPool" +} + +resource "azurerm_network_interface" "test" { + count = 2 + name = "acctni${count.index}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + ip_configuration { + name = "testConfiguration" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_managed_disk" "test" { + count = 2 + name = "datadisk_existing_${count.index}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "1023" +} + +resource "azurerm_availability_set" "avset" { + name = "avset" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + platform_fault_domain_count = 2 + platform_update_domain_count = 2 + managed = true +} + +resource "random_pet" "azurerm_linux_virtual_machine_name" { + prefix = "vm" +} + +resource "azurerm_linux_virtual_machine" "test" { + count = 2 + name = "${random_pet.azurerm_linux_virtual_machine_name.id}${count.index}" + location = azurerm_resource_group.rg.location + availability_set_id = azurerm_availability_set.avset.id + resource_group_name = azurerm_resource_group.rg.name + network_interface_ids = [element(azurerm_network_interface.test.*.id, count.index)] + size = "Standard_DS1_v2" + + # Uncomment this line to delete the OS disk automatically when deleting the VM + # delete_os_disk_on_termination = true + + # Uncomment this line to delete the data disks automatically when deleting the VM + # delete_data_disks_on_termination = true + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + name = "myosdisk${count.index}" + } + + computer_name = "hostname" + admin_username = "testadmin" + admin_password = "Password1234!" + disable_password_authentication = false +} \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/outputs.tf b/quickstart/101-vm-cluster-linux/outputs.tf new file mode 100644 index 00000000..ebd79188 --- /dev/null +++ b/quickstart/101-vm-cluster-linux/outputs.tf @@ -0,0 +1,15 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "azurerm_virtual_network_name" { + value = azurerm_virtual_network.test.name +} + +output "azurerm_subnet_name" { + value = azurerm_subnet.test.name +} + +output "azurerm_linux_virtual_machine_names2" { + value = [for s in azurerm_linux_virtual_machine.test : s.name[*]] +} \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/providers.tf b/quickstart/101-vm-cluster-linux/providers.tf new file mode 100644 index 00000000..4fd5f6ba --- /dev/null +++ b/quickstart/101-vm-cluster-linux/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">=1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/readme.md b/quickstart/101-vm-cluster-linux/readme.md new file mode 100644 index 00000000..8cc548f0 --- /dev/null +++ b/quickstart/101-vm-cluster-linux/readme.md @@ -0,0 +1,28 @@ +# Azure Linux VM cluster + +This template deploys a Windows VM cluster on Azure. + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) +- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) +- [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) +- [azurerm_lb](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb) +- [azurerm_lb_backend_address_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_backend_address_pool) +- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) +- [azurerm_managed_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk) +- [azurerm_availability_set](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/availability_set) +- [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) + +## Variables + +| Name | Description | Default | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | + +## Example + +To see how to run this example, see [Create an Azure VM cluster with Terraform and HC](https://learn.microsoft.com/azure/developer/terraform/create-vm-cluster-with-infrastructure). diff --git a/quickstart/101-vm-cluster-linux/variables.tf b/quickstart/101-vm-cluster-linux/variables.tf new file mode 100644 index 00000000..22a8f6a5 --- /dev/null +++ b/quickstart/101-vm-cluster-linux/variables.tf @@ -0,0 +1,11 @@ +variable "resource_group_location" { + type = string + description = "Location for all resources." + default = "eastus" +} + +variable "resource_group_name_prefix" { + type = string + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." + default = "rg" +} \ No newline at end of file