-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathvm-jbox.tf
95 lines (80 loc) · 2.84 KB
/
vm-jbox.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
# Create Network Security Group and rule
resource "azurerm_network_security_group" "tfjboxnsg" {
name = "${var.resource.prefix}-jboxnsg"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*" # add source addr
destination_address_prefix = "*"
}
tags = {
environment = var.resource.tag
}
}
# Create public IPs
resource "azurerm_public_ip" "tfjboxip" {
name = "${var.resource.prefix}-jboxip"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
allocation_method = "Static"
tags = {
environment = var.resource.tag
}
}
# Create network interface
resource "azurerm_network_interface" "tfjboxnic" {
name = "${var.resource.prefix}-jboxnic"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
#-network_security_group_id = azurerm_network_security_group.tfjboxnsg.id
ip_configuration {
name = "${var.resource.prefix}-jboxnic-conf"
subnet_id = azurerm_subnet.tfjboxvnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.tfjboxip.id
}
tags = {
environment = var.resource.tag
}
}
resource "azurerm_network_interface_security_group_association" "tfjboxnic" {
network_interface_id = azurerm_network_interface.tfjboxnic.id
network_security_group_id = azurerm_network_security_group.tfjboxnsg.id
}
# Create virtual machine
resource "azurerm_linux_virtual_machine" "tfjboxvm" {
name = "${var.resource.prefix}jboxvm"
location = var.resource.location
resource_group_name = azurerm_resource_group.tfrg.name
network_interface_ids = [azurerm_network_interface.tfjboxnic.id]
size = "Standard_DS1_v2"
computer_name = "tfjobxvm"
admin_username = var.vm.admin_username
admin_password = var.vm.admin_password
disable_password_authentication = false
os_disk {
name = "${var.resource.prefix}-ftosdisk-jbox"
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
tags = {
environment = var.resource.tag
}
}
# public_ip must be 'static' in order to print output properly
output "jumphost_ip" {
value = azurerm_public_ip.tfjboxip.ip_address
}