This repository was archived by the owner on Jan 15, 2025. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
99 lines (83 loc) · 3.49 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
terraform {
required_version = ">= 0.10"
}
locals {
environment = "${terraform.workspace == "default" ? "test" : terraform.workspace}"
}
data "azurerm_resource_group" "existing_rg_for_resources" {
name = "${var.existing_rg_for_resources}"
}
resource "azurerm_network_interface" "default" {
name = "${var.name_prefix}-${var.vm_type}-${count.index+1}-${local.environment}"
resource_group_name = "${data.azurerm_resource_group.existing_rg_for_resources.name}"
location = "${var.location}"
count = "${var.num_instances}"
ip_configuration {
name = "IPconfig${count.index+1}"
subnet_id = "${var.existing_subnet_id}"
private_ip_address_allocation = "dynamic"
}
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
}
}
resource "random_id" "random_storageacc" {
byte_length = 3
}
resource "azurerm_storage_account" "diag_storageacc" {
count = "${var.boot_diagnostics == "true" ? 1 : 0}"
name = "${var.name_prefix}bootdiag${random_id.random_storageacc.hex}"
resource_group_name = "${data.azurerm_resource_group.existing_rg_for_resources.name}"
location = "${var.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_availability_set" "default" {
name = "${var.name_prefix}-availabilityset-${var.vm_type}-${local.environment}"
resource_group_name = "${data.azurerm_resource_group.existing_rg_for_resources.name}"
location = "${var.location}"
platform_fault_domain_count = 3
platform_update_domain_count = 5
managed = true
tags = {
Environment = "${local.environment}"
ManagedBy = "TF"
}
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.name_prefix}-${var.vm_type}-${count.index+1}-${local.environment}"
resource_group_name = "${data.azurerm_resource_group.existing_rg_for_resources.name}"
location = "${var.location}"
availability_set_id = "${azurerm_availability_set.default.id}"
network_interface_ids = ["${element(azurerm_network_interface.default.*.id, count.index)}"]
vm_size = "${var.vm_size}"
count = "${var.num_instances}"
delete_os_disk_on_termination = true
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}-osdiskvm${count.index+1}-${local.environment}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${var.name_prefix}-${var.vm_type}${count.index+1}"
admin_username = "${var.vm_username}"
admin_password = "${var.vm_password}"
}
os_profile_windows_config {
enable_automatic_upgrades = false
provision_vm_agent = true
}
boot_diagnostics {
enabled = "${var.boot_diagnostics}"
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.diag_storageacc.*.primary_blob_endpoint) : "" }"
}
tags = "${merge(var.tags, map("ssh_ip", element(azurerm_network_interface.default.*.private_ip_address, count.index)), map("Name", "${var.name_prefix}-${var.vm_type}${count.index+1}"))}"
}