Skip to content

Commit

Permalink
feat: Allowlist Ips in Azure (#51)
Browse files Browse the repository at this point in the history
Co-authored-by: amanpruthi <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 10, 2024
1 parent 18f818b commit 18259c0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ resources that lack official modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_allowed_ip_ranges"></a> [allowed\_ip\_ranges](#input\_allowed\_ip\_ranges) | allowed public IP addresses or CIDR ranges. | `list(string)` | `[]` | no |
| <a name="input_app_wandb_env"></a> [app\_wandb\_env](#input\_app\_wandb\_env) | Extra environment variables for W&B | `map(string)` | `{}` | no |
| <a name="input_blob_container"></a> [blob\_container](#input\_blob\_container) | Use an existing bucket. | `string` | `""` | no |
| <a name="input_create_redis"></a> [create\_redis](#input\_create\_redis) | Boolean indicating whether to provision an redis instance (true) or not (false). | `bool` | `false` | no |
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module "networking" {
namespace = var.namespace
resource_group_name = azurerm_resource_group.default.name
location = azurerm_resource_group.default.location

tags = var.tags
allowed_ip_ranges = var.allowed_ip_ranges
tags = var.tags
}

module "database" {
Expand Down
51 changes: 51 additions & 0 deletions modules/networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,54 @@ resource "azurerm_subnet" "redis" {
address_prefixes = [var.network_redis_subnet_cidr]
virtual_network_name = azurerm_virtual_network.default.name
}

resource "azurerm_network_security_group" "default" {
count = length(var.allowed_ip_ranges) > 0 ? 1 : 0
name = "${var.namespace}-allowlist-nsg"
location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
}


resource "azurerm_network_security_rule" "allow_cidr" {
count = length(var.allowed_ip_ranges) > 0 ? length(var.allowed_ip_ranges) : 0
name = "allowRule-${count.index}"
priority = 100 + "${count.index}"
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefixes = [var.allowed_ip_ranges[count.index]]
destination_address_prefix = "*"
resource_group_name = var.resource_group_name
network_security_group_name = azurerm_network_security_group.default.0.name
depends_on = [azurerm_network_security_group.default]
}



resource "azurerm_network_security_rule" "default" {
count = length(var.allowed_ip_ranges) > 0 ? 1 : 0
name = "defaultAppGatewayV2SkuRule"
priority = 120
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "65200-65535"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = var.resource_group_name
network_security_group_name = azurerm_network_security_group.default.0.name
}



resource "azurerm_subnet_network_security_group_association" "public" {
count = length(var.allowed_ip_ranges) > 0 ? 1 : 0
subnet_id = azurerm_subnet.public.id
network_security_group_id = azurerm_network_security_group.default.0.id
depends_on = [ azurerm_network_security_rule.default ]
}
5 changes: 5 additions & 0 deletions modules/networking/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ variable "tags" {
type = map(string)
description = "Map of tags for resource"
}

variable "allowed_ip_ranges" {
description = "allowed public IP addresses or CIDR ranges."
type = list(string)
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ variable "kubernetes_node_count" {
type = number
}

##########################################
# Network #
##########################################

variable "allowed_ip_ranges" {
description = "allowed public IP addresses or CIDR ranges."
type = list(string)
default = []
}


variable "weave_wandb_env" {
type = map(string)
description = "Extra environment variables for W&B"
Expand All @@ -198,3 +209,4 @@ variable "parquet_wandb_env" {
description = "Extra environment variables for W&B"
default = {}
}

0 comments on commit 18259c0

Please sign in to comment.