This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
131 lines (111 loc) · 4.49 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
terraform {
required_version = ">=0.10"
}
locals {
environment = "${terraform.workspace == "default" ? "test" : terraform.workspace}"
}
resource "azurerm_resource_group" "bastion" {
name = "${var.resource_group}"
location = "${var.location}"
}
resource "random_integer" "rdp_port" {
min = 1111
max = 9999
}
resource "random_string" "bastion_password" {
length = 10
special = true
}
data "azurerm_resource_group" "existing_rg_for_vnet" {
name = "${var.existing_rg_for_vnet}"
}
resource "azurerm_lb" "bastion" {
name = "${var.name_prefix}-bastion-load-balancer-${local.environment}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
depends_on = ["azurerm_public_ip.bastion"]
frontend_ip_configuration {
name = "lb-frontend-${local.environment}"
public_ip_address_id = "${azurerm_public_ip.bastion.id}"
}
}
resource "azurerm_lb_backend_address_pool" "bastion" {
name = "${var.name_prefix}-bastion-lb-backend-address-pool-${local.environment}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
loadbalancer_id = "${azurerm_lb.bastion.id}"
}
resource "azurerm_lb_nat_rule" "bastion_nat_rule" {
name = "RDPAccess"
resource_group_name = "${azurerm_resource_group.bastion.name}"
loadbalancer_id = "${azurerm_lb.bastion.id}"
protocol = "Tcp"
frontend_port = "${random_integer.rdp_port.result}"
backend_port = 3389
frontend_ip_configuration_name = "lb-frontend-${local.environment}"
}
resource "azurerm_public_ip" "bastion" {
name = "${var.name_prefix}-bastion-public-ip-${local.environment}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
public_ip_address_allocation = "static"
location = "${var.location}"
}
resource "azurerm_subnet" "bastion" {
name = "${var.name_prefix}-bastion-subnet-${local.environment}"
resource_group_name = "${data.azurerm_resource_group.existing_rg_for_vnet.name}"
virtual_network_name = "${var.existing_vnet_name}"
address_prefix = "${var.subnet_address_prefix}"
route_table_id = "${var.existing_rt_id}"
}
resource "azurerm_network_interface" "bastion" {
name = "${var.name_prefix}-bastion-nic-${local.environment}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
location = "${var.location}"
network_security_group_id = "${azurerm_network_security_group.bastion.id}"
ip_configuration {
name = "BastionIPConfig"
subnet_id = "${azurerm_subnet.bastion.id}"
private_ip_address_allocation = "dynamic"
load_balancer_backend_address_pools_ids = ["${azurerm_lb_backend_address_pool.bastion.id}"]
load_balancer_inbound_nat_rules_ids = ["${azurerm_lb_nat_rule.bastion_nat_rule.id}"]
}
}
resource "azurerm_network_security_group" "bastion" {
name = "${var.name_prefix}-bastion-nsg-${local.environment}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
location = "${var.location}"
}
resource "azurerm_virtual_machine" "bastion" {
name = "${var.name_prefix}-bastion-vm-${local.environment}"
resource_group_name = "${azurerm_resource_group.bastion.name}"
location = "${var.location}"
network_interface_ids = ["${azurerm_network_interface.bastion.id}"]
vm_size = "${var.vm_size}"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
storage_os_disk {
name = "${var.name_prefix}-bastion-os-disk-${local.environment}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${var.name_prefix}-bastion"
admin_username = "${var.bastion_username}"
admin_password = "${random_string.bastion_password.result}"
}
os_profile_windows_config {
enable_automatic_upgrades = false
provision_vm_agent = true
}
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
role = "bastion"
Name = "${var.name_prefix}-bastion"
}
}