From deeba2765268cc8080d34ab15fae6e947d736101 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 15 Feb 2023 10:27:14 -0800 Subject: [PATCH 1/6] New sample (converted from Bicep via OpenAI) --- quickstart/101-devtest-labs/main.tf | 41 ++++++++++++++++++++++++ quickstart/101-devtest-labs/outputs.tf | 3 ++ quickstart/101-devtest-labs/providers.tf | 16 +++++++++ quickstart/101-devtest-labs/readme.md | 21 ++++++++++++ quickstart/101-devtest-labs/variables.tf | 30 +++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 quickstart/101-devtest-labs/main.tf create mode 100644 quickstart/101-devtest-labs/outputs.tf create mode 100644 quickstart/101-devtest-labs/providers.tf create mode 100644 quickstart/101-devtest-labs/readme.md create mode 100644 quickstart/101-devtest-labs/variables.tf diff --git a/quickstart/101-devtest-labs/main.tf b/quickstart/101-devtest-labs/main.tf new file mode 100644 index 00000000..f7c80c1b --- /dev/null +++ b/quickstart/101-devtest-labs/main.tf @@ -0,0 +1,41 @@ +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 "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 = var.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..917d478f --- /dev/null +++ b/quickstart/101-devtest-labs/outputs.tf @@ -0,0 +1,3 @@ +output "lab_id" { + value = azurerm_dev_test_lab.lab.id +} 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..305f17da --- /dev/null +++ b/quickstart/101-devtest-labs/readme.md @@ -0,0 +1,21 @@ +# 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 | +|-|-|-| +| `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..c90cc87f --- /dev/null +++ b/quickstart/101-devtest-labs/variables.tf @@ -0,0 +1,30 @@ +variable "resource_group_location" { + default = "eastus" + description = "Location for all resources." +} + +variable "resource_group_name_prefix" { + 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" { + description = "The name of the new lab instance to be created" +} + +variable "vm_name" { + description = "The name of the vm to be created." +} + +variable "vm_size" { + description = "The size of the vm to be created." + default = "Standard_D4_v3" +} + +variable "user_name" { + description = "The username for the local account that will be created on the new vm." +} + +variable "password" { + description = "The password for the local account that will be created on the new vm." +} From bef739cc06ccb82de49c45ade30a54ee866d3de3 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 15 Feb 2023 12:27:05 -0800 Subject: [PATCH 2/6] Added log file --- quickstart/101-devtest-labs/TestRecord.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 quickstart/101-devtest-labs/TestRecord.md diff --git a/quickstart/101-devtest-labs/TestRecord.md b/quickstart/101-devtest-labs/TestRecord.md new file mode 100644 index 00000000..5808cbaa --- /dev/null +++ b/quickstart/101-devtest-labs/TestRecord.md @@ -0,0 +1 @@ +Article not yet tested by automated testing pipeline. \ No newline at end of file From d57838d056b7d9fe257e4b696475aefbfd2532dd Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 15 Feb 2023 13:15:52 -0800 Subject: [PATCH 3/6] Updated README.MD --- quickstart/101-devtest-labs/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickstart/101-devtest-labs/readme.md b/quickstart/101-devtest-labs/readme.md index 305f17da..bedbeba6 100644 --- a/quickstart/101-devtest-labs/readme.md +++ b/quickstart/101-devtest-labs/readme.md @@ -14,6 +14,8 @@ This template deploys a Windows virtual machine within an Azure DevTest Lab. | 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 | From d8e9d4b7ae1f5eff5910e24142325c9fc4de5c59 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 16 Feb 2023 10:55:02 -0800 Subject: [PATCH 4/6] Edits per Code Review --- quickstart/101-devtest-labs/TestRecord.md | 1 - quickstart/101-devtest-labs/main.tf | 36 ++++++++++++++++------- quickstart/101-devtest-labs/outputs.tf | 5 ++++ quickstart/101-devtest-labs/variables.tf | 1 + 4 files changed, 31 insertions(+), 12 deletions(-) delete mode 100644 quickstart/101-devtest-labs/TestRecord.md diff --git a/quickstart/101-devtest-labs/TestRecord.md b/quickstart/101-devtest-labs/TestRecord.md deleted file mode 100644 index 5808cbaa..00000000 --- a/quickstart/101-devtest-labs/TestRecord.md +++ /dev/null @@ -1 +0,0 @@ -Article not yet tested by automated testing pipeline. \ No newline at end of file diff --git a/quickstart/101-devtest-labs/main.tf b/quickstart/101-devtest-labs/main.tf index f7c80c1b..ee3cf910 100644 --- a/quickstart/101-devtest-labs/main.tf +++ b/quickstart/101-devtest-labs/main.tf @@ -7,6 +7,20 @@ resource "azurerm_resource_group" "rg" { 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 @@ -20,17 +34,17 @@ resource "azurerm_dev_test_virtual_network" "vnet" { } 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 = var.password - allow_claim = false - lab_virtual_network_id = azurerm_dev_test_virtual_network.vnet.id + 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" diff --git a/quickstart/101-devtest-labs/outputs.tf b/quickstart/101-devtest-labs/outputs.tf index 917d478f..d99a1f92 100644 --- a/quickstart/101-devtest-labs/outputs.tf +++ b/quickstart/101-devtest-labs/outputs.tf @@ -1,3 +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/variables.tf b/quickstart/101-devtest-labs/variables.tf index c90cc87f..e3c2f38a 100644 --- a/quickstart/101-devtest-labs/variables.tf +++ b/quickstart/101-devtest-labs/variables.tf @@ -27,4 +27,5 @@ variable "user_name" { variable "password" { description = "The password for the local account that will be created on the new vm." + sensitive = true } From 93f6488941dea09f05f6c38bdd47e1d2f00ea650 Mon Sep 17 00:00:00 2001 From: hezijie Date: Thu, 23 Feb 2023 09:23:44 +0800 Subject: [PATCH 5/6] fix 101-devtest-labs automation test --- quickstart/101-devtest-labs/variables.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/quickstart/101-devtest-labs/variables.tf b/quickstart/101-devtest-labs/variables.tf index e3c2f38a..06fa1bb4 100644 --- a/quickstart/101-devtest-labs/variables.tf +++ b/quickstart/101-devtest-labs/variables.tf @@ -10,10 +10,12 @@ variable "resource_group_name_prefix" { variable "lab_name" { description = "The name of the new lab instance to be created" + default = "ExampleLab" } variable "vm_name" { description = "The name of the vm to be created." + default = "example-vm" } variable "vm_size" { @@ -23,9 +25,11 @@ variable "vm_size" { variable "user_name" { description = "The username for the local account that will be created on the new vm." + default = "exampleuser" } variable "password" { description = "The password for the local account that will be created on the new vm." sensitive = true + default = null } From dfcd06404e36a6e75a97cb134d6b8a80d6d4f8ee Mon Sep 17 00:00:00 2001 From: hezijie Date: Thu, 23 Feb 2023 09:26:31 +0800 Subject: [PATCH 6/6] add type for variables --- quickstart/101-devtest-labs/variables.tf | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/quickstart/101-devtest-labs/variables.tf b/quickstart/101-devtest-labs/variables.tf index 06fa1bb4..7babeda6 100644 --- a/quickstart/101-devtest-labs/variables.tf +++ b/quickstart/101-devtest-labs/variables.tf @@ -1,34 +1,41 @@ 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