From 1eb6e680f9fb45eef1e64f143b16d3933717ad50 Mon Sep 17 00:00:00 2001 From: Eric D Date: Thu, 15 Dec 2022 10:42:43 -0500 Subject: [PATCH 1/4] created new 101 folder and added tf files and readme.md --- .../101-windows-vm-with-iis-server/main.tf | 149 ++++++++++++++++++ .../101-windows-vm-with-iis-server/outputs.tf | 7 + .../providers.tf | 22 +++ .../101-windows-vm-with-iis-server/readme.md | 30 ++++ .../variables.tf | 13 ++ 5 files changed, 221 insertions(+) create mode 100644 quickstart/101-windows-vm-with-iis-server/main.tf create mode 100644 quickstart/101-windows-vm-with-iis-server/outputs.tf create mode 100644 quickstart/101-windows-vm-with-iis-server/providers.tf create mode 100644 quickstart/101-windows-vm-with-iis-server/readme.md create mode 100644 quickstart/101-windows-vm-with-iis-server/variables.tf diff --git a/quickstart/101-windows-vm-with-iis-server/main.tf b/quickstart/101-windows-vm-with-iis-server/main.tf new file mode 100644 index 00000000..cdd9f08d --- /dev/null +++ b/quickstart/101-windows-vm-with-iis-server/main.tf @@ -0,0 +1,149 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +# Create virtual network +resource "azurerm_virtual_network" "my_terraform_network" { + name = "myVnet" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name +} + +# Create subnet +resource "azurerm_subnet" "my_terraform_subnet" { + name = "mySubnet" + resource_group_name = azurerm_resource_group.rg.name + virtual_network_name = azurerm_virtual_network.my_terraform_network.name + address_prefixes = ["10.0.1.0/24"] +} + +# Create public IPs +resource "azurerm_public_ip" "my_terraform_public_ip" { + name = "myPublicIP" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + allocation_method = "Dynamic" +} + +# Create Network Security Group and rules +resource "azurerm_network_security_group" "my_terraform_nsg" { + name = "myNetworkSecurityGroup" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + security_rule { + name = "RDP" + priority = 1000 + direction = "Inbound" + access = "Allow" + protocol = "*" + source_port_range = "*" + destination_port_range = "3389" + source_address_prefix = "*" + destination_address_prefix = "*" + } + security_rule { + name = "web" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "80" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +# Create network interface +resource "azurerm_network_interface" "my_terraform_nic" { + name = "myNIC" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + ip_configuration { + name = "my_nic_configuration" + subnet_id = azurerm_subnet.my_terraform_subnet.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.my_terraform_public_ip.id + } +} + +# Connect the security group to the network interface +resource "azurerm_network_interface_security_group_association" "example" { + network_interface_id = azurerm_network_interface.my_terraform_nic.id + network_security_group_id = azurerm_network_security_group.my_terraform_nsg.id +} + +# Generate random text for a unique storage account name +resource "random_id" "random_id" { + keepers = { + # Generate a new ID only when a new resource group is defined + resource_group = azurerm_resource_group.rg.name + } + + byte_length = 8 +} + +# Create storage account for boot diagnostics +resource "azurerm_storage_account" "my_storage_account" { + name = "diag${random_id.random_id.hex}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = "LRS" +} + + +# Create virtual machine +resource "azurerm_windows_virtual_machine" "my_terraform_vm" { + name = "myVM" + admin_username = "azureuser" + admin_password = var.admin_password + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + network_interface_ids = [azurerm_network_interface.my_terraform_nic.id] + size = "Standard_DS1_v2" + + os_disk { + name = "myOsDisk" + caching = "ReadWrite" + storage_account_type = "Premium_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2022-datacenter-azure-edition" + version = "latest" + } + + + boot_diagnostics { + storage_account_uri = azurerm_storage_account.my_storage_account.primary_blob_endpoint + } +} + +# Install IIS web server to the virtual machine +resource "azurerm_virtual_machine_extension" "web_server_install" { + name = "web_server_install" + virtual_machine_id = azurerm_windows_virtual_machine.my_terraform_vm.id + publisher = "Microsoft.Compute" + type = "CustomScriptExtension" + type_handler_version = "1.8" + auto_upgrade_minor_version = true + + settings = < Date: Tue, 10 Jan 2023 14:06:48 -0500 Subject: [PATCH 2/4] removed depends_on line --- quickstart/101-windows-vm-with-iis-server/main.tf | 2 -- 1 file changed, 2 deletions(-) diff --git a/quickstart/101-windows-vm-with-iis-server/main.tf b/quickstart/101-windows-vm-with-iis-server/main.tf index cdd9f08d..4ef032b7 100644 --- a/quickstart/101-windows-vm-with-iis-server/main.tf +++ b/quickstart/101-windows-vm-with-iis-server/main.tf @@ -144,6 +144,4 @@ resource "azurerm_virtual_machine_extension" "web_server_install" { "commandToExecute": "powershell -ExecutionPolicy Unrestricted Install-WindowsFeature -Name Web-Server -IncludeAllSubFeature -IncludeManagementTools" } SETTINGS - - depends_on = [ azurerm_windows_virtual_machine.my_terraform_vm ] } \ No newline at end of file From adbdb46a71078c5c060f8a370d2b7f655d035d5e Mon Sep 17 00:00:00 2001 From: Eric D Date: Tue, 10 Jan 2023 16:39:20 -0500 Subject: [PATCH 3/4] added default column and values to readme.md --- quickstart/101-windows-vm-with-iis-server/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/101-windows-vm-with-iis-server/readme.md b/quickstart/101-windows-vm-with-iis-server/readme.md index 44e9ec9a..301620e9 100644 --- a/quickstart/101-windows-vm-with-iis-server/readme.md +++ b/quickstart/101-windows-vm-with-iis-server/readme.md @@ -19,11 +19,11 @@ This template deploys a Windows Server virtual machine that includes a virtual n ## Variables -| Name | Description | +| 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. | -| `admin_password` | The password to assign to the Windows Administrator user account. +| `admin_password` | The password to assign to the Windows Administrator user account. | None. The supplied password must be 6-72 characters long and must satisfy at least three of the following password complexity requirements: one uppercase character, one lowercase character, one numeric digit, or one special character. ## Example From 141c92701153c0da8345754ef5302f110d16dd07 Mon Sep 17 00:00:00 2001 From: Eric D Date: Thu, 12 Jan 2023 19:21:11 -0500 Subject: [PATCH 4/4] corrected markdown table format --- quickstart/101-windows-vm-with-iis-server/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quickstart/101-windows-vm-with-iis-server/readme.md b/quickstart/101-windows-vm-with-iis-server/readme.md index 301620e9..4fb7395f 100644 --- a/quickstart/101-windows-vm-with-iis-server/readme.md +++ b/quickstart/101-windows-vm-with-iis-server/readme.md @@ -19,10 +19,10 @@ This template deploys a Windows Server virtual machine that includes a virtual n ## Variables -| Name | Description | Default -|-|-| +| 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. | +| `resource_group_location` | Location of the resource group. | eastus | | `admin_password` | The password to assign to the Windows Administrator user account. | None. The supplied password must be 6-72 characters long and must satisfy at least three of the following password complexity requirements: one uppercase character, one lowercase character, one numeric digit, or one special character. ## Example