forked from Azure/terraform-azurerm-computegroup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
156 lines (133 loc) · 4.35 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
provider "azurerm" {
version = "~> 0.3"
}
module "os" {
source = "./os"
vm_os_simple = "${ var.vm_os_simple }"
}
resource "azurerm_resource_group" "vmss" {
name = "${var.resource_group_name}"
location = "${var.location}"
tags = "${var.tags}"
}
resource "azurerm_virtual_machine_scale_set" "vm-linux" {
count = "${ contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "WindowsServer") ? 0 : 1 }"
name = "${var.vmscaleset_name}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.vmss.name}"
upgrade_policy_mode = "Manual"
tags = "${var.tags}"
sku {
name = "${var.vm_size}"
tier = "Standard"
capacity = "${var.nb_instance}"
}
storage_profile_image_reference {
id = "${var.vm_os_id }"
publisher = "${coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher)}"
offer = "${coalesce(var.vm_os_offer, module.os.calculated_value_os_offer)}"
sku = "${coalesce(var.vm_os_sku, module.os.calculated_value_os_sku)}"
version = "${var.vm_os_version}"
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "${ var.managed_disk_type }"
}
storage_profile_data_disk {
lun = 0
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = 10
}
os_profile {
computer_name_prefix = "${var.computer_name_prefix}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = "${file("${var.ssh_key}")}"
}
}
network_profile {
name = "${var.network_profile}"
primary = true
ip_configuration {
name = "IPConfiguration"
subnet_id = "${var.vnet_subnet_id}"
load_balancer_backend_address_pool_ids = ["${var.load_balancer_backend_address_pool_ids}"]
}
}
extension {
name = "vmssextension"
publisher = "Microsoft.OSTCExtensions"
type = "CustomScriptForLinux"
type_handler_version = "1.2"
settings = <<SETTINGS
{
"commandToExecute": "${var.cmd_extension}"
}
SETTINGS
}
}
resource "azurerm_virtual_machine_scale_set" "vm-windows" {
count = "${ contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "WindowsServer") ? 1 : 0 }"
name = "${var.vmscaleset_name}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.vmss.name}"
upgrade_policy_mode = "Manual"
tags = "${var.tags}"
sku {
name = "${var.vm_size}"
tier = "Standard"
capacity = "${var.nb_instance}"
}
storage_profile_image_reference {
id = "${ var.vm_os_id }"
publisher = "${ coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) }"
offer = "${ coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) }"
sku = "${ coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) }"
version = "${ var.vm_os_version }"
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "${ var.managed_disk_type }"
}
storage_profile_data_disk {
lun = 0
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = 10
}
os_profile {
computer_name_prefix = "${var.computer_name_prefix}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
network_profile {
name = "${var.network_profile}"
primary = true
ip_configuration {
name = "IPConfiguration"
subnet_id = "${var.vnet_subnet_id}"
load_balancer_backend_address_pool_ids = ["${var.load_balancer_backend_address_pool_ids}"]
}
}
extension {
name = "vmssextension"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.8"
settings = <<SETTINGS
{
"commandToExecute": "${var.cmd_extension}"
}
SETTINGS
}
}