-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVM.tf
More file actions
129 lines (108 loc) · 4.21 KB
/
Copy pathVM.tf
File metadata and controls
129 lines (108 loc) · 4.21 KB
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
resource "azurerm_resource_group" "example" {
name = "Sample-resources"
location = "West Europe"
tags = {
Location = "West Europe" # Matches the policy requirements
Owner = "abdulla.kamil@adesso.com" # Or your team/department
}
}
data "azurerm_key_vault" "vmvaultkamil" {
name = "vmvaultkamil" # Fixed the name to match your actual Key Vault
resource_group_name = "rg-adesso-aks-cluster-kamil-alz"
}
data "azurerm_key_vault_secret" "admin-username" {
name = "vm-admin-username" # This secret must exist in your Key Vault
key_vault_id = data.azurerm_key_vault.vmvaultkamil.id
}
data "azurerm_key_vault_secret" "admin-password" {
name = "vm-admin-password" # This secret must exist in your Key Vault
key_vault_id = data.azurerm_key_vault.vmvaultkamil.id
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.example.id
}
}
# Public IP for the VM
resource "azurerm_public_ip" "example" {
name = "example-public-ip"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
allocation_method = "Static"
sku = "Standard"
}
# Network Security Group
resource "azurerm_network_security_group" "example" {
name = "example-nsg"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
security_rule {
name = "RDP"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
# Associate NSG with NIC
resource "azurerm_network_interface_security_group_association" "example" {
network_interface_id = azurerm_network_interface.example.id
network_security_group_id = azurerm_network_security_group.example.id
}
resource "azurerm_windows_virtual_machine" "example" {
name = "VMmachine"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_F2"
admin_username = data.azurerm_key_vault_secret.admin-username.value
admin_password = data.azurerm_key_vault_secret.admin-password.value
network_interface_ids = [
azurerm_network_interface.example.id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
}
# resource "azurerm_managed_disk" "datadisk" {
# name = "winserver-datadisk"
# location = azurerm_resource_group.example.location
# resource_group_name = azurerm_resource_group.example.name
# storage_account_type = "Standard_LRS"
# create_option = "Empty"
# disk_size_gb = 10
# }
# resource "azurerm_virtual_machine_data_disk_attachment" "datadisk_attach" {
# managed_disk_id = azurerm_managed_disk.datadisk.id
# virtual_machine_id = azurerm_windows_virtual_machine.example.id
# lun = 0
# caching = "ReadWrite"
# }