-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
121 lines (107 loc) · 3.99 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
# Create a resource group
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = var.location
}
# Create a network
resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}
# Create a subnet
resource "azurerm_subnet" "internal" {
name = "${var.prefix}-subnet"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.1.0/24"]
}
# Create public IP
resource "azurerm_public_ip" "main" {
name = "${var.prefix}-public-ip"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
allocation_method = "Static"
}
# Create network Interface
resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
ip_configuration {
name = "${var.prefix}-ip-config"
subnet_id = azurerm_subnet.internal.id
public_ip_address_id = azurerm_public_ip.main.id
private_ip_address_allocation = "Dynamic"
}
}
# Create security group and rules to open needed ports
resource "azurerm_network_security_group" "main" {
name = "${var.prefix}-security-group"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}
resource "azurerm_network_security_rule" "main" {
name = "${var.prefix}-security-rules"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
destination_port_ranges = ["22", "25", "80", "122", "443", "8080", "8443", "9418"]
source_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.main.name
network_security_group_name = azurerm_network_security_group.main.name
}
# Create Virtual machine
resource "azurerm_virtual_machine" "main" {
name = "${var.prefix}-vm"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = "Standard_E8-4ads_v5"
storage_image_reference {
publisher = "GitHub"
offer = "GitHub-Enterprise"
sku = "GitHub-Enterprise"
version = var.ghes-version
}
# Create OS Disk
storage_os_disk {
name = "${var.prefix}-os-storage"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
disk_size_gb = "200"
}
os_profile {
computer_name = "hostname"
admin_username = var.linux_admin_username
}
os_profile_linux_config {
disable_password_authentication = true
# Update the path to your own public key
ssh_keys {
path = "/home/${var.linux_admin_username}/.ssh/authorized_keys"
key_data = file("~/.ssh/unused/id_rsa.pub")
# key_data = var.ssh_public_key
}
}
}
# Create the 2nd HDD needed as one of the requirements
resource "azurerm_managed_disk" "main" {
name = "${var.prefix}-data-disk"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
storage_account_type = "Premium_LRS"
create_option = "Empty"
disk_size_gb = 200
}
resource "azurerm_virtual_machine_data_disk_attachment" "main" {
managed_disk_id = azurerm_managed_disk.main.id
virtual_machine_id = azurerm_virtual_machine.main.id
lun = "10"
caching = "ReadWrite"
}