Skip to content

Commit

Permalink
Initial put
Browse files Browse the repository at this point in the history
  • Loading branch information
TomArcherMsft committed Dec 7, 2024
1 parent 8ef801d commit ebc0886
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 0 deletions.
30 changes: 30 additions & 0 deletions quickstart/101-dns-private-zone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Azure Private DNS Zone

This template deploys an Azure Private DNS Zone.

## 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)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [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_private_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone)
- [azurerm_private_dns_zone_virtual_network_link](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link)
- [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password)
- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface)
- [azurerm_windows_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_virtual_machine)
- [azurerm_private_dns_a_record](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_a_record)
- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group)
- [azurerm_network_security_rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule)

## Variables

| Name | Description | Default value |
|-|-|-|
| `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 |
| `address_space` | The address space that is used the virtual network. | ["10.0.0.0/16"] |
| `description` | The address prefixes to use for the subnet. | ["10.0.2.0/24"] |
| `private_dns_zone_name` | Name of the private DNS zone resource. | "" |
| `admin_username` | Admin usernames for the Windows VMs. | "adminuser" |
151 changes: 151 additions & 0 deletions quickstart/101-dns-private-zone/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
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
}

resource "random_string" "name" {
length = 8
special = false
upper = false
lower = true
numeric = false
}
resource "azurerm_virtual_network" "vnet" {
name = "vnet-${random_string.name.id}"
address_space = var.address_space
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_subnet" "subnet" {
name = "subnet-${random_string.name.id}"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = var.address_prefixes
}

resource "azurerm_private_dns_zone" "dns_zone" {
name = var.private_dns_zone_name
resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "dsn_vnet_link" {
name = "dns-vnet-link-${random_string.name.id}"
resource_group_name = azurerm_resource_group.rg.name
private_dns_zone_name = azurerm_private_dns_zone.dns_zone.name
virtual_network_id = azurerm_virtual_network.vnet.id
}

resource "random_password" "vm1_admin_password" {
length = 16
special = true
}

resource "random_password" "vm2_admin_password" {
length = 16
special = true
}

resource "azurerm_network_interface" "nic1" {
name = "nic1-${random_string.name.id}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_network_interface" "nic2" {
name = "nic2-${random_string.name.id}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_windows_virtual_machine" "vm1" {
name = "vm1-${random_string.name.id}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = "Standard_F2"
admin_username = var.admin_username
admin_password = random_password.vm1_admin_password.result
network_interface_ids = [
azurerm_network_interface.nic1.id,
]

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}

resource "azurerm_windows_virtual_machine" "vm2" {
name = "vm2-${random_string.name.id}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = "Standard_F2"
admin_username = var.admin_username
admin_password = random_password.vm1_admin_password.result
network_interface_ids = [
azurerm_network_interface.nic2.id,
]

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
}

resource "azurerm_private_dns_a_record" "pdar" {
name = "test"
zone_name = azurerm_private_dns_zone.dns_zone.name
resource_group_name = azurerm_resource_group.rg.name
ttl = 300
records = [azurerm_windows_virtual_machine.vm1.private_ip_address]
}

resource "azurerm_network_security_group" "nsg" {
name = "nsg-${random_string.name.result}"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_network_security_rule" "nsr_icmp" {
name = "Allow-ICMP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Icmp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.rg.name
network_security_group_name = azurerm_network_security_group.nsg.name
}
31 changes: 31 additions & 0 deletions quickstart/101-dns-private-zone/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "windows_virtual_machine_1_name" {
value = azurerm_windows_virtual_machine.vm1.name
}

output "windows_virtual_machine_2_name" {
value = azurerm_windows_virtual_machine.vm2.name
}

output "windows_virtual_machine_1_password" {
value = azurerm_windows_virtual_machine.vm1.admin_password
sensitive = true
}

output "windows_virtual_machine_2_password" {
value = azurerm_windows_virtual_machine.vm2.admin_password
sensitive = true
}

output "windows_virtual_machine_1_admin_username" {
value = azurerm_windows_virtual_machine.vm1.admin_username
sensitive = true
}

output "windows_virtual_machine_2_admin_username" {
value = azurerm_windows_virtual_machine.vm2.admin_username
sensitive = true
}
18 changes: 18 additions & 0 deletions quickstart/101-dns-private-zone/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}

provider "azurerm" {
features {}
}
35 changes: 35 additions & 0 deletions quickstart/101-dns-private-zone/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}

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 "address_space" {
type = list(string)
default = ["10.0.0.0/16"]
description = "The address space that is used the virtual network."
}

variable "address_prefixes" {
type = list(string)
default = ["10.0.2.0/24"]
description = "The address prefixes to use for the subnet"
}

variable "private_dns_zone_name" {
type = string
default = "private.contoso.com"
description = "The name of the Private DNS Zone. Must be a valid domain name. Changing this value forces a new resource to be created."
}

variable "admin_username" {
type = string
default = "adminuser"
description = "The username for the Windows virtual machines."
}

0 comments on commit ebc0886

Please sign in to comment.