Azure / Azure/azure-quickstart-templates

Domain Join

Open
#4,311 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Bicep
Stars
14.9k
Forks
16.2k
Avg merge
6d 21h
Merged PRs (30d)
6

Description

[201-vm-domain-join-existing](https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-domain-join-existing)

### Issue Details
Basically I am trying to create a VM in a vnet connected back to on-prem (with vnet peering etc) which all works I can RDP to the machine with no issues. I would like to somehow use the template above to take my newly created VM and add it to my local/on-prem domain controller.

I can add the VM manually to the domain after the VM is built but I would like to automate this if possible:

Main Template:

# Build the Resource Group
resource "azurerm_resource_group" "rsg" {
name = "${var.rsg}"
location = "${var.location}"
}

# Build the Virtual Network
resource "azurerm_virtual_network" "vnet" {
name = "${var.rsg}-vnet"
address_space = ["${var.add-space}"]
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rsg.name}"
}

# Build subnet
resource "azurerm_subnet" "subnet1" {
name = "Publishing"
resource_group_name = "${azurerm_resource_group.rsg.name}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
address_prefix = "${var.add-subnet1}"
}

# Network Security Group
resource "azurerm_network_security_group" "nsg" {
name = "${var.rsg}-nsg"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rsg.name}"

security_rule {
name = "RDP"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = 3389
destination_port_range = 3389
source_address_prefix = "10.0.0.0/8"
destination_address_prefix = "*"
}

tags {
environment = "Production"
}
}

# Set the private and public IP
resource "azurerm_network_interface" "ni" {
name = "${var.hostname}-ni"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rsg.name}"
network_security_group_id = "${azurerm_network_security_group.nsg.id}"

# dynamic IP configuration
ip_configuration {
name = "${var.hostname}-ipconfig"
subnet_id = "${azurerm_subnet.subnet1.id}"
private_ip_address_allocation = "dynamic"
}
}

# Build Virtual Machine
resource "azurerm_virtual_machine" "vm" {
name = "${var.hostname}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rsg.name}"
network_interface_ids = ["${azurerm_network_interface.ni.id}"]
vm_size = "${var.vmsize}"

storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "${var.sku}"
version = "latest"
}

storage_os_disk {
name = "${var.hostname}-osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "${var.storagetype}"
}

os_profile {
computer_name = "${var.hostname}"
admin_username = "${var.username}"
admin_password = "${var.password}"
}

os_profile_windows_config {
enable_automatic_upgrades = false
}

tags {
environment = "Production"
}
}

#Build Peer To Main vnet
resource "azurerm_virtual_network_peering" "spoketohub" {
name = "terraformpocPEERnet-terraform"
resource_group_name = "terraformpoc"
virtual_network_name = "terraformpoc-vnet"
remote_virtual_network_id = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rsg-terraformpoc/providers/Microsoft.Network/virtualNetworks/net-terraformpoc"
allow_virtual_network_access = true
allow_forwarded_traffic = false
allow_gateway_transit = false
use_remote_gateways = true
}

#Build Peer from Main vnet
resource "azurerm_virtual_network_peering" "hubtospoke" {
name = "terraformPEERtonetterraformpoc"
resource_group_name = "rsg-terraform"
virtual_network_name = "net-terraform"
remote_virtual_network_id = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/terraformpoc/providers/Micrisoft.Network/virtualNetworks/terraformpoc-vnet"
allow_virtual_network_access = true
allow_forwarded_traffic = false
allow_gateway_transit = true
use_remote_gateways = false
}
resource "azurerm_virtual_machine_extension" "terraformpoc" {
name = "JoinDomain"
location = "West US"
resource_group_name = "terraformpoc"
virtual_machine_name = "vmpoc5"
publisher = "Microsoft.Compute"
type = "JsonADDomainExtension"
type_handler_version = "1.3"

settings = <

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the 201-vm-domain-join-existing template and the azurerm_virtual_machine_extension using JsonADDomainExtension. Review the reported VMAgentStatusCommunicationError and the VM agent or outbound connectivity requirements; done means the extension completes successfully and the newly created VM joins the on-premises domain automatically.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.