-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathmain.tf
81 lines (70 loc) · 2.19 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
# Terraform
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "2.40.0"
}
}
}
#Azure provider
provider "azurerm" {
features {}
}
#create resource group
resource "azurerm_resource_group" "rg" {
name = "rg-webserver-cs"
location = "westus2"
}
#Create virtual network
resource "azurerm_virtual_network" "vnet" {
name = "vnet-webserver-${azurerm_resource_group.rg.location}-001"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
# Create subnet
resource "azurerm_subnet" "subnet" {
name = "snet-webserver-${azurerm_resource_group.rg.location}-001"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.0.0/24"]
}
#Create NSG
resource "azurerm_network_security_group" "nsg" {
name = "nsg-rdpallow-001"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
security_rule {
name = "RDP-Inbound"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "10.0.0.0/16"
destination_address_prefix = "*"
}
}
#NSG and Subnet Association
resource "azurerm_subnet_network_security_group_association" "nsg_sub_assoc" {
subnet_id = azurerm_subnet.subnet.id
network_security_group_id = azurerm_network_security_group.nsg.id
}
module "server" {
source = "./modules/terraform-azure-server"
subnet_id = azurerm_subnet.subnet.id
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
servername = "server1"
vm_size = "Standard_B2s"
admin_username = "terraadmin"
admin_password = "P@ssw0rdP@ssw0rd"
os = {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
}