diff --git a/quickstart/101-devtest-labs/main.tf b/quickstart/101-devtest-labs/main.tf new file mode 100644 index 00000000..ee3cf910 --- /dev/null +++ b/quickstart/101-devtest-labs/main.tf @@ -0,0 +1,55 @@ +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_password" "password" { + count = var.password == null ? 1 : 0 + length = 20 + special = true + min_numeric = 1 + min_upper = 1 + min_lower = 1 + min_special = 1 +} + +locals { + password = try(random_password.password[0].result, var.password) +} + +resource "azurerm_dev_test_lab" "lab" { + name = var.lab_name + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name +} + +resource "azurerm_dev_test_virtual_network" "vnet" { + name = "Dtl${var.lab_name}" + lab_name = azurerm_dev_test_lab.lab.name + resource_group_name = azurerm_resource_group.rg.name +} + +resource "azurerm_dev_test_windows_virtual_machine" "vm" { + name = var.vm_name + lab_name = azurerm_dev_test_lab.lab.name + lab_subnet_name = "Dtl${var.lab_name}Subnet" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + storage_type = "Standard" + size = var.vm_size + username = var.user_name + password = local.password + allow_claim = false + lab_virtual_network_id = azurerm_dev_test_virtual_network.vnet.id + + gallery_image_reference { + offer = "WindowsServer" + publisher = "MicrosoftWindowsServer" + sku = "2019-Datacenter" + version = "latest" + } +} diff --git a/quickstart/101-devtest-labs/outputs.tf b/quickstart/101-devtest-labs/outputs.tf new file mode 100644 index 00000000..d99a1f92 --- /dev/null +++ b/quickstart/101-devtest-labs/outputs.tf @@ -0,0 +1,8 @@ +output "lab_id" { + value = azurerm_dev_test_lab.lab.id +} + +output "password" { + sensitive = true + value = local.password +} diff --git a/quickstart/101-devtest-labs/providers.tf b/quickstart/101-devtest-labs/providers.tf new file mode 100644 index 00000000..e395f149 --- /dev/null +++ b/quickstart/101-devtest-labs/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">=0.12" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-devtest-labs/readme.md b/quickstart/101-devtest-labs/readme.md new file mode 100644 index 00000000..bedbeba6 --- /dev/null +++ b/quickstart/101-devtest-labs/readme.md @@ -0,0 +1,23 @@ +# Windows virtual machine in an Azure DevTest Lab + +This template deploys a Windows virtual machine within an Azure DevTest Lab. + +## 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_dev_test_lab](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dev_test_lab) +- [azurerm_dev_test_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dev_test_virtual_network) +- [azurerm_dev_test_windows_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/dev_test_windows_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 | +| `lab_name` | The name of the new lab instance to be created. | | +| `vm_name` | The name of the VM to be created. | | +| `vm_size` | The size of the VM to be created. | Standard_D4_v3 | +| `user_name` | The username for the local account that will be created on the new VM. | | +| `password` | The password for the local account that will be created on the new VM. | | diff --git a/quickstart/101-devtest-labs/variables.tf b/quickstart/101-devtest-labs/variables.tf new file mode 100644 index 00000000..7babeda6 --- /dev/null +++ b/quickstart/101-devtest-labs/variables.tf @@ -0,0 +1,42 @@ +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location for all resources." +} + +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "lab_name" { + type = string + description = "The name of the new lab instance to be created" + default = "ExampleLab" +} + +variable "vm_name" { + type = string + description = "The name of the vm to be created." + default = "example-vm" +} + +variable "vm_size" { + type = string + description = "The size of the vm to be created." + default = "Standard_D4_v3" +} + +variable "user_name" { + type = string + description = "The username for the local account that will be created on the new vm." + default = "exampleuser" +} + +variable "password" { + type = string + description = "The password for the local account that will be created on the new vm." + sensitive = true + default = null +}