-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kumarvna/develop
Initial version
- Loading branch information
Showing
8 changed files
with
293 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
*.terraform.lock.hcl | ||
|
||
# Crash log files | ||
crash.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,106 @@ | ||
# terraform-azurerm-domain-join | ||
Terraform module to joins a VM to an Active Directory Domain | ||
# Join the Virtual Machines to existing Active Directory Domain | ||
|
||
Terraform module to join the virtual machines to an existing Active Directory domain using a Virtual Machine Extension. | ||
|
||
OU Path to keep your virtual machines to desired Organization Unit. By default, all virtual machines go to Computers OU. You can manage by setting up variable to `ou_path = "OU=Computers,OU=HQ,OU=Europe,DC=Consoto,DC=COM"` a valid OU string. | ||
|
||
## Module Usage | ||
|
||
```hcl | ||
module "virtual-machine" { | ||
source = "kumarvna/virtual-machine/azurerm" | ||
version = "2.1.0" | ||
resource_group_name = "rg-shared-westeurope-01" | ||
location = "westeurope" | ||
virtual_network_name = "vnet-shared-hub-westeurope-001" | ||
subnet_name = "snet-management" | ||
virtual_machine_name = "win-machine" | ||
os_flavor = "windows" | ||
windows_distribution_name = "windows2019dc" | ||
virtual_machine_size = "Standard_A2_v2" | ||
admin_username = "azureadmin" | ||
admin_password = "P@$$w0rd1234!" | ||
instances_count = 1 | ||
dns_servers = ["10.1.3.4", "168.63.129.16"] | ||
nsg_inbound_rules = [ | ||
{ | ||
name = "rdp" | ||
destination_port_range = "3389" | ||
source_address_prefix = "*" | ||
}, | ||
{ | ||
name = "http" | ||
destination_port_range = "80" | ||
source_address_prefix = "*" | ||
}, | ||
] | ||
} | ||
module "domain-join" { | ||
source = "kumarvna/domain-join/azurerm" | ||
version = "1.0.0" | ||
virtual_machine_id = element(concat(module.virtual-machine.windows_virtual_machine_ids, [""]), 0) | ||
active_directory_domain = "consoto.com" | ||
active_directory_username = "azureadmin" | ||
active_directory_password = "P@$$w0rd1234!" | ||
# Adding TAG's to your Azure resources (Required) | ||
# ProjectName and Env are already declared above, to use them here or create a varible. | ||
tags = { | ||
ProjectName = "demo-project" | ||
Env = "dev" | ||
Owner = "user@example.com" | ||
BusinessUnit = "CORP" | ||
ServiceClass = "Gold" | ||
} | ||
} | ||
``` | ||
|
||
## Requirements | ||
|
||
Name | Version | ||
-----|-------- | ||
terraform | >= 0.13 | ||
azurerm | >= 2.59.0 | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
azurerm | >= 2.59.0 | ||
|
||
## Inputs | ||
|
||
Name | Description | Type | Default | ||
---- | ----------- | ---- | ------- | ||
`virtual_machine_id` |The resource ID of the Virtual Machine| string | `""` | ||
`active_directory_domain`|The name of the Active Directory domain to join|string | `""` | ||
`ou_path`|An organizational unit (OU) within an Active Directory to place computers|string|`null` | ||
`active_directory_username`|The username of an account with permissions to bind machines to the Active Directory Domain|string|`""` | ||
`active_directory_password`|The password of the account with permissions to bind machines to the Active Directory Domain|string|`""` | ||
`Tags`|A map of tags to add to all resources|map|`{}` | ||
|
||
## Outputs | ||
|
||
|Name | Description| | ||
|---- | -----------| | ||
`windows_vm_extension_id`|Resource ID of Virtual Machine extension | ||
|
||
## Resource Graph | ||
|
||
 | ||
|
||
## Authors | ||
|
||
Originally created by [Kumaraswamy Vithanala](mailto:kumarvna@gmail.com) | ||
|
||
## Other resources | ||
|
||
* [Active Directory Setup](https://cloudblogs.microsoft.com/industry-blog/en-gb/technetuk/2016/06/08/setting-up-active-directory-via-powershell/) | ||
* [Join a Windows Server virtual machine to an Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory-domain-services/join-windows-vm-template) | ||
* [Virtual Machine Extensions](https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/features-windows#:~:text=Azure%20virtual%20machine%20(VM)%20extensions,VM%20extension%20can%20be%20used.) | ||
* [Terraform AzureRM Provider Documentation](https://www.terraform.io/docs/providers/azurerm/index.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Join the Virtual Machines to existing Active Directory Domain | ||
|
||
This terraform module to join the virtual machines to an existing Active Directory domain using a Virtual Machine Extension. | ||
|
||
## Module Usage | ||
|
||
```hcl | ||
module "virtual-machine" { | ||
source = "kumarvna/virtual-machine/azurerm" | ||
version = "2.1.0" | ||
resource_group_name = "rg-shared-westeurope-01" | ||
location = "westeurope" | ||
virtual_network_name = "vnet-shared-hub-westeurope-001" | ||
subnet_name = "snet-management" | ||
virtual_machine_name = "win-machine" | ||
os_flavor = "windows" | ||
windows_distribution_name = "windows2019dc" | ||
virtual_machine_size = "Standard_A2_v2" | ||
admin_username = "azureadmin" | ||
admin_password = "P@$$w0rd1234!" | ||
instances_count = 1 | ||
dns_servers = ["10.1.3.4", "168.63.129.16"] | ||
nsg_inbound_rules = [ | ||
{ | ||
name = "rdp" | ||
destination_port_range = "3389" | ||
source_address_prefix = "*" | ||
}, | ||
{ | ||
name = "http" | ||
destination_port_range = "80" | ||
source_address_prefix = "*" | ||
}, | ||
] | ||
} | ||
module "domain-join" { | ||
source = "kumarvna/domain-join/azurerm" | ||
version = "1.0.0" | ||
virtual_machine_id = element(concat(module.virtual-machine.windows_virtual_machine_ids, [""]), 0) | ||
active_directory_domain = "consoto.com" | ||
active_directory_username = "azureadmin" | ||
active_directory_password = "P@$$w0rd1234!" | ||
# Adding TAG's to your Azure resources (Required) | ||
# ProjectName and Env are already declared above, to use them here or create a varible. | ||
tags = { | ||
ProjectName = "demo-project" | ||
Env = "dev" | ||
Owner = "user@example.com" | ||
BusinessUnit = "CORP" | ||
ServiceClass = "Gold" | ||
} | ||
} | ||
``` | ||
|
||
## Terraform Usage | ||
|
||
To run this example you need to execute following Terraform commands | ||
|
||
```hcl | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
Run `terraform destroy` when you don't need these resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module "virtual-machine" { | ||
source = "kumarvna/virtual-machine/azurerm" | ||
version = "2.1.0" | ||
|
||
resource_group_name = "rg-shared-westeurope-01" | ||
location = "westeurope" | ||
virtual_network_name = "vnet-shared-hub-westeurope-001" | ||
subnet_name = "snet-management" | ||
virtual_machine_name = "win-machine" | ||
os_flavor = "windows" | ||
windows_distribution_name = "windows2019dc" | ||
virtual_machine_size = "Standard_A2_v2" | ||
admin_username = "azureadmin" | ||
admin_password = "P@$$w0rd1234!" | ||
instances_count = 1 | ||
dns_servers = ["10.1.3.4", "168.63.129.16"] | ||
|
||
nsg_inbound_rules = [ | ||
{ | ||
name = "rdp" | ||
destination_port_range = "3389" | ||
source_address_prefix = "*" | ||
}, | ||
|
||
{ | ||
name = "http" | ||
destination_port_range = "80" | ||
source_address_prefix = "*" | ||
}, | ||
] | ||
} | ||
|
||
module "domain-join" { | ||
source = "kumarvna/domain-join/azurerm" | ||
version = "1.0.0" | ||
|
||
virtual_machine_id = element(concat(module.virtual-machine.windows_virtual_machine_ids, [""]), 0) | ||
active_directory_domain = "consoto.com" | ||
active_directory_username = "azureadmin" | ||
active_directory_password = "P@$$w0rd1234!" | ||
|
||
# Adding TAG's to your Azure resources (Required) | ||
# ProjectName and Env are already declared above, to use them here or create a varible. | ||
tags = { | ||
ProjectName = "demo-project" | ||
Env = "dev" | ||
Owner = "user@example.com" | ||
BusinessUnit = "CORP" | ||
ServiceClass = "Gold" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
resource "azurerm_virtual_machine_extension" "join-domain" { | ||
name = "join-domain" | ||
virtual_machine_id = var.virtual_machine_id | ||
publisher = "Microsoft.Compute" | ||
type = "JsonADDomainExtension" | ||
type_handler_version = "1.3" | ||
auto_upgrade_minor_version = true | ||
tags = merge({ "ResourceName" = "join-domain" }, var.tags, ) | ||
|
||
settings = <<SETTINGS | ||
{ | ||
"Name": "${var.active_directory_domain}", | ||
"OUPath": "${var.ou_path != null ? var.ou_path : ""}", | ||
"User": "${var.active_directory_username}@${var.active_directory_domain}", | ||
"Restart": "true", | ||
"Options": "3" | ||
} | ||
SETTINGS | ||
|
||
protected_settings = <<SETTINGS | ||
{ | ||
"Password": "${var.active_directory_password}" | ||
} | ||
SETTINGS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
variable "virtual_machine_id" { | ||
description = "The resource ID of the Virtual Machine" | ||
} | ||
|
||
variable "active_directory_domain" { | ||
description = "The name of the Active Directory domain to join" | ||
} | ||
|
||
variable "ou_path" { | ||
description = "An organizational unit (OU) within an Active Directory to place computers" | ||
default = null | ||
} | ||
|
||
variable "active_directory_username" { | ||
description = "The username of an account with permissions to bind machines to the Active Directory Domain" | ||
} | ||
|
||
variable "active_directory_password" { | ||
description = "The password of the account with permissions to bind machines to the Active Directory Domain" | ||
} | ||
|
||
variable "tags" { | ||
description = "A map of tags to add to all resources" | ||
type = map(string) | ||
default = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = ">= 2.59.0" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |