Skip to main content
main.tf1.4 KB
View on GitHub
locals {
name = "${var.project}-${var.stage}"
}

resource "azurerm_resource_group" "this" {
name = "${local.name}-rg"
location = var.location
}

resource "azurerm_virtual_network" "this" {
name = "${local.name}-vnet"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
address_space = var.address_space
}

resource "azurerm_subnet" "default" {
name = "default"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = var.subnet_prefixes
}

resource "azurerm_network_security_group" "default" {
name = "${local.name}-nsg"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name

security_rule {
name = "allow-vnet"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "VirtualNetwork"
destination_address_prefix = "VirtualNetwork"
}
}

resource "azurerm_subnet_network_security_group_association" "default" {
subnet_id = azurerm_subnet.default.id
network_security_group_id = azurerm_network_security_group.default.id
}

Related Documentation