-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
143 lines (122 loc) · 3.68 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
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.34.0"
}
}
backend "azurerm" {}
}
provider "azurerm" {
features {}
skip_provider_registration = true
}
data "azurerm_client_config" "current" {}
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
}
resource "azurerm_virtual_network" "vnet" {
resource_group_name = azurerm_resource_group.rg.name
location = var.location
name = "vnet-${var.prefix}"
address_space = var.vnetAdressSpace
}
resource "azurerm_subnet" "subnets" {
for_each = var.subnets
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = each.value.address
}
resource "azurerm_log_analytics_workspace" "law" {
name = "law-${var.prefix}"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_monitor_diagnostic_setting" "vnet-diagnostics" {
name = "vnet-diagnostics"
target_resource_id = azurerm_virtual_network.vnet.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.law.id
# log {
# category = "allLogs"
# retention_policy {
# enabled = false
# }
# }
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}
resource "azurerm_key_vault" "kv" {
name = "kv-${var.prefix}349787"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
sku_name = "standard"
tenant_id = data.azurerm_client_config.current.tenant_id
enable_rbac_authorization = true
}
resource "azurerm_monitor_diagnostic_setting" "kv-diagnostics" {
name = "kv-diagnostics"
target_resource_id = azurerm_key_vault.kv.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.law.id
log {
category = "AuditEvent"
retention_policy {
enabled = false
}
}
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}
data "azurerm_key_vault_secret" "admin-pw" {
name = "admin-pw"
key_vault_id = azurerm_key_vault.kv.id
}
resource "azurerm_network_interface" "nic" {
name = "nic-${var.prefix}"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = "ipconfig1"
subnet_id = azurerm_subnet.subnets["subnet01"].id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "vm" {
name = "vm-${var.prefix}"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.nic.id]
vm_size = "Standard_DS1_v2"
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2022-datacenter-g2"
version = "latest"
}
storage_os_disk {
name = "osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "host01"
admin_username = "testadmin"
admin_password = data.azurerm_key_vault_secret.admin-pw.value
}
os_profile_windows_config {
provision_vm_agent = true
}
}