forked from Azure/terraform-azurerm-vmss-cloudinit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
96 lines (80 loc) · 2.52 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
provider "azurerm" {
version = "~> 1.0"
}
provider "template" {
version = "~> 1.0"
}
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}"
}
data "template_file" "cloudconfig" {
template = "${file("${var.cloudconfig_file}")}"
}
data "template_cloudinit_config" "config" {
gzip = true
base64_encode = true
part {
content_type = "text/cloud-config"
content = "${data.template_file.cloudconfig.rendered}"
}
}
resource "azurerm_virtual_machine_scale_set" "vm-linux" {
count = "${var.nb_instance}"
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 = "${var.data_disk_size}"
}
os_profile {
computer_name_prefix = "${var.computer_name_prefix}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
custom_data = "${data.template_cloudinit_config.config.rendered}"
}
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}"]
}
}
}