This commit is contained in:
Tom Archer 2024-10-25 15:01:17 -07:00
parent 2e32ee6be9
commit e6c148c0f4
8 changed files with 46 additions and 565 deletions

View File

@ -1,375 +0,0 @@
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" "azurerm_virtual_network_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_virtual_network" "example" {
name = coalesce(var.virtual_network_name, "vnet-${random_string.azurerm_virtual_network_name.result}")
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
}
resource "random_string" "azurerm_subnet_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_subnet" "example" {
name = coalesce(var.subnet_name, "subnet-${random_string.azurerm_subnet_name.result}")
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.0.0/24"]
}
resource "random_string" "azurerm_public_ip_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_public_ip" "vm" {
name = coalesce(var.public_ip_name, "pip-${random_string.azurerm_public_ip_name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
}
resource "random_string" "azurerm_network_security_group_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_network_security_group" "example" {
name = coalesce(var.network_security_group_name, "nsg-${random_string.azurerm_network_security_group_name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_network_security_rule" "RDPRule" {
name = "RDPRule"
resource_group_name = azurerm_resource_group.rg.name
priority = 1000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = 3389
source_address_prefix = "167.220.255.0/25"
destination_address_prefix = "*"
network_security_group_name = azurerm_network_security_group.example.name
}
resource "azurerm_network_security_rule" "MSSQLRule" {
name = "MSSQLRule"
resource_group_name = azurerm_resource_group.rg.name
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = 1433
source_address_prefix = "167.220.255.0/25"
destination_address_prefix = "*"
network_security_group_name = azurerm_network_security_group.example.name
}
resource "random_string" "azurerm_network_interface_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_network_interface" "example" {
name = coalesce(var.network_interface_name, "nic-${random_string.azurerm_network_interface_name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = "exampleconfiguration1"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.vm.id
}
}
resource "azurerm_network_interface_security_group_association" "example" {
network_interface_id = azurerm_network_interface.example.id
network_security_group_id = azurerm_network_security_group.example.id
}
resource "random_string" "azurerm_virtual_machine_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_virtual_machine" "example" {
name = coalesce(var.virtual_machine_name, "vm-${random_string.azurerm_virtual_machine_name.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.example.id]
vm_size = "Standard_DS14_v2"
storage_image_reference {
publisher = "MicrosoftSQLServer"
offer = "SQL2017-WS2016"
sku = "SQLDEV"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
os_profile {
computer_name = "winhost01"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_windows_config {
timezone = "Pacific Standard Time"
provision_vm_agent = true
enable_automatic_upgrades = true
}
}
resource "azurerm_mssql_virtual_machine" "example" {
virtual_machine_id = azurerm_virtual_machine.example.id
sql_license_type = "PAYG"
}
resource "random_string" "azurerm_virtual_network_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_virtual_network" "test" {
name = coalesce(var.virtual_network_name_2, "vnet-${random_string.azurerm_virtual_network_name_2.result}")
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
}
resource "random_string" "azurerm_subnet_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_subnet" "test" {
name = coalesce(var.subnet_name_2, "subnet-${random_string.azurerm_subnet_name_2.result}")
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.2.0/24"]
}
resource "random_string" "azurerm_public_ip_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_public_ip" "test" {
name = coalesce(var.public_ip_name_2, "pip-${random_string.azurerm_public_ip_name_2.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
allocation_method = "Dynamic"
}
resource "random_string" "azurerm_network_interface_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_network_interface" "test" {
name = coalesce(var.network_interface_name_2, "nic-${random_string.azurerm_network_interface_name_2.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.test.id
}
}
resource "random_string" "azurerm_virtual_machine_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_virtual_machine" "test" {
name = coalesce(var.virtual_machine_name_2, "vm-${random_string.azurerm_virtual_machine_name_2.result}")
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.test.id]
vm_size = "Standard_F4"
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "winhost01"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_windows_config {
timezone = "Pacific Standard Time"
provision_vm_agent = true
}
}
resource "azurerm_virtual_machine_extension" "test" {
name = "hostname"
virtual_machine_id = azurerm_virtual_machine.test.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = jsonencode({
"fileUris" = ["https://raw.githubusercontent.com/Azure/azure-quickstart-templates/00b79d2102c88b56502a63041936ef4dd62cf725/101-vms-with-selfhost-integration-runtime/gatewayInstall.ps1"],
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File gatewayInstall.ps1 ${azurerm_data_factory_integration_runtime_self_hosted.host.primary_authorization_key} && timeout /t 120"
})
}
resource "random_pet" "azurerm_resource_group_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "host" {
name = random_pet.azurerm_resource_group_name.id
location = var.resource_group_location
}
resource "random_string" "azurerm_data_factory_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_data_factory" "host" {
name = coalesce(var.data_factory_name, "df-${random_string.azurerm_data_factory_name.result}")
location = azurerm_resource_group.host.location
resource_group_name = azurerm_resource_group.host.name
}
resource "random_string" "azurerm_data_factory_integration_runtime_self_hosted_name" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_data_factory_integration_runtime_self_hosted" "host" {
name = coalesce(var.data_factory_integration_runtime_self_hosted_name, "ir-${random_string.azurerm_data_factory_integration_runtime_self_hosted_name.result}")
data_factory_id = azurerm_data_factory.host.id
}
resource "random_pet" "azurerm_resource_group_name_2" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "target" {
name = random_pet.azurerm_resource_group_name_2.id
location = var.resource_group_location
}
resource "azurerm_role_assignment" "target" {
scope = azurerm_data_factory.host.id
role_definition_name = "Contributor"
principal_id = azurerm_data_factory.target.identity[0].principal_id
}
resource "random_string" "azurerm_data_factory_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_data_factory" "target" {
name = coalesce(var.data_factory_name_2, "df-${random_string.azurerm_data_factory_name_2.result}")
location = azurerm_resource_group.target.location
resource_group_name = azurerm_resource_group.target.name
identity {
type = "SystemAssigned"
}
}
resource "random_string" "azurerm_data_factory_integration_runtime_self_hosted_name_2" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_data_factory_integration_runtime_self_hosted" "target" {
name = coalesce(var.data_factory_integration_runtime_self_hosted_name_2, "ir-${random_string.azurerm_data_factory_integration_runtime_self_hosted_name_2.result}")
data_factory_id = azurerm_data_factory.target.id
rbac_authorization {
resource_id = azurerm_data_factory_integration_runtime_self_hosted.host.id
}
depends_on = [azurerm_role_assignment.target, azurerm_virtual_machine_extension.test]
}

View File

@ -1,75 +0,0 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "virtual_network_name" {
value = azurerm_virtual_network.example.name
}
output "subnet_name" {
value = azurerm_subnet.example.name
}
output "public_ip_name" {
value = azurerm_public_ip.vm.name
}
output "network_security_group_name" {
value = azurerm_network_security_group.example.name
}
output "network_interface_name" {
value = azurerm_network_interface.example.name
}
output "virtual_machine_name" {
value = azurerm_virtual_machine.example.name
}
output "mssql_virtual_machine_name" {
value = azurerm_mssql_virtual_machine.example.name
}
output "virtual_network_name_2" {
value = azurerm_virtual_network.test.name
}
output "subnet_name_2" {
value = azurerm_subnet.test.name
}
output "public_ip_name_2" {
value = azurerm_public_ip.test.name
}
output "network_interface_name_2" {
value = azurerm_network_interface.test.name
}
output "virtual_machine_name_2" {
value = azurerm_virtual_machine.test.name
}
output "resource_group_name_host" {
value = azurerm_resource_group.host.name
}
output "data_factory_name_host" {
value = azurerm_data_factory.host.name
}
output "data_factory_integration_runtime_self_hosted_name_host" {
value = azurerm_data_factory_integration_runtime_self_hosted.host.name
}
output "resource_group_name_target" {
value = azurerm_resource_group.target.name
}
output "data_factory_name_target" {
value = azurerm_data_factory.target.name
}
output "data_factory_integration_runtime_self_hosted_name_target" {
value = azurerm_data_factory_integration_runtime_self_hosted.target.name
}

View File

@ -1,101 +0,0 @@
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 "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}
variable "virtual_network_name" {
type = string
description = "The name of the virtual network resource. The value will be randomly generated if blank."
default = ""
}
variable "subnet_name" {
type = string
description = "The name of the virtual network subnet. The value will be randomly generated if blank."
default = ""
}
variable "public_ip_name" {
type = string
description = "The name of the public IP resource. The value will be randomly generated if blank."
default = ""
}
variable "network_security_group_name" {
type = string
description = "The name of the network security group resource. The value will be randomly generated if blank."
default = ""
}
variable "network_interface_name" {
type = string
description = "The name of the network interface resource. The value will be randomly generated if blank."
default = ""
}
variable "virtual_machine_name" {
type = string
description = "The name of the virtual machine resource. The value will be randomly generated if blank."
default = ""
}
variable "virtual_network_name_2" {
type = string
description = "The name of the second virtual network resource. The value will be randomly generated if blank."
default = ""
}
variable "subnet_name_2" {
type = string
description = "The name of the second virtual network subnet. The value will be randomly generated if blank."
default = ""
}
variable "public_ip_name_2" {
type = string
description = "The name of the second public IP resource. The value will be randomly generated if blank."
default = ""
}
variable "network_interface_name_2" {
type = string
description = "The name of the second network interface resource. The value will be randomly generated if blank."
default = ""
}
variable "virtual_machine_name_2" {
type = string
description = "The name of the second virtual machine resource. The value will be randomly generated if blank."
default = ""
}
variable "data_factory_name" {
type = string
description = "The name of the data factory resource. The value will be randomly generated if blank."
default = ""
}
variable "data_factory_integration_runtime_self_hosted_name" {
type = string
description = "The name of the data factory integration runtime self hosted resource. The value will be randomly generated if blank."
default = ""
}
variable "data_factory_name_2" {
type = string
description = "The name of the second data factory resource. The value will be randomly generated if blank."
default = ""
}
variable "data_factory_integration_runtime_self_hosted_name_2" {
type = string
description = "The name of the second data factory integration runtime self hosted resource. The value will be randomly generated if blank."
default = ""
}

View File

@ -1,24 +1,12 @@
# Azure Data Factory Integration Runtime
# Azure Data Factory
This template deploys an Azure Data Factory Integration Runtime.
This template deploys an Azure Data Factory instance.
## 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_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_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip)
- [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)
- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface)
- [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association)
- [azurerm_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine)
- [azurerm_mssql_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_virtual_machine)
- [azurerm_virtual_machine_extension](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension)
- [azurerm_data_factory](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_factory)
- [azurerm_data_factory_integration_runtime_self_hosted](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/data_factory_integration_runtime_self_hosted)
- [azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment)
## Variables

View File

@ -0,0 +1,26 @@
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" "azurerm_data_factory" {
length = 13
lower = true
numeric = false
special = false
upper = false
}
resource "azurerm_data_factory" "example" {
name = random_string.azurerm_data_factory.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
identity {
type = "SystemAssigned"
}
}

View File

@ -0,0 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "data_factory_name" {
value = azurerm_data_factory.example.name
}

View File

@ -0,0 +1,11 @@
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 "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}