forked from trstringer/terraform-azure-linux-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
123 lines (104 loc) · 4.09 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
resource "azurerm_resource_group" "rg" {
name = "${var.name_prefix}-rg"
location = "${var.location}"
}
resource "azurerm_virtual_network" "vnet" {
name = "${var.name_prefix}vnet"
location = "${var.location}"
address_space = ["${var.vnet_address_space}"]
resource_group_name = "${azurerm_resource_group.rg.name}"
}
resource "azurerm_subnet" "subnet" {
name = "${var.name_prefix}subnet"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${var.subnet_address_space}"
}
resource "azurerm_network_security_group" "nsg" {
name = "${var.name_prefix}nsg"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
}
resource "azurerm_network_security_rule" "rulessh" {
name = "${var.name_prefix}rulessh"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_security_group_name = "${azurerm_network_security_group.nsg.name}"
}
resource "azurerm_network_interface" "nic" {
name = "${var.name_prefix}nic"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_security_group_id = "${azurerm_network_security_group.nsg.id}"
ip_configuration {
name = "${var.name_prefix}ipconfig"
subnet_id = "${azurerm_subnet.subnet.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.pip.id}"
}
depends_on = ["azurerm_network_security_group.nsg"]
}
resource "azurerm_public_ip" "pip" {
name = "${var.name_prefix}-ip"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "${var.hostname}"
}
resource "azurerm_storage_account" "stor" {
name = "${var.hostname}stor"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
account_type = "${var.storage_account_type}"
}
resource "azurerm_storage_container" "storc" {
name = "${var.name_prefix}-vhds"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.stor.name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.name_prefix}vm"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
vm_size = "${var.vm_size}"
network_interface_ids = ["${azurerm_network_interface.nic.id}"]
storage_image_reference {
publisher = "${var.image_publisher}"
offer = "${var.image_offer}"
sku = "${var.image_sku}"
version = "${var.image_version}"
}
storage_os_disk {
name = "${var.name_prefix}osdisk"
vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.name_prefix}osdisk.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "${var.hostname}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
os_profile_linux_config {
disable_password_authentication = "${var.disable_password_authentication}"
ssh_keys = [{
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = "${var.ssh_public_key}"
}]
}
depends_on = ["azurerm_storage_account.stor"]
}
output "admin_username" {
value = "${var.admin_username}"
}
output "vm_fqdn" {
value = "${azurerm_public_ip.pip.fqdn}"
}