Skip to content

Commit 006155f

Browse files
authored
feat: DTOSS 4393 Initial modules commit (#2)
* Initial modules commit * renamed RBAC folder
1 parent 5463e67 commit 006155f

File tree

21 files changed

+482
-0
lines changed

21 files changed

+482
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
resource "azurerm_user_assigned_identity" "mi" {
3+
name = var.uai_name
4+
resource_group_name = var.resource_group_name
5+
location = var.location
6+
7+
tags = var.tags
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "name" {
2+
value = azurerm_user_assigned_identity.mi.name
3+
}
4+
5+
output "id" {
6+
value = azurerm_user_assigned_identity.mi.id
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "resource_group_name" {
2+
type = string
3+
description = "The name of the resource group in which to create the VNET. Changing this forces a new resource to be created."
4+
}
5+
6+
variable "location" {
7+
type = string
8+
description = ""
9+
}
10+
11+
variable "uai_name" {
12+
type = string
13+
description = "The name of the user assigned identity."
14+
}
15+
16+
variable "tags" {
17+
type = map(string)
18+
description = "Resource tags to be applied throughout the deployment."
19+
default = {}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "azurerm_network_security_group" "this" {
2+
name = var.name
3+
location = var.location
4+
resource_group_name = var.resource_group_name
5+
6+
# Dynamically create security rules from the variable
7+
dynamic "security_rule" {
8+
for_each = var.nsg_rules
9+
content {
10+
name = security_rule.value.name
11+
priority = security_rule.value.priority
12+
direction = security_rule.value.direction
13+
access = security_rule.value.access
14+
protocol = security_rule.value.protocol
15+
source_port_range = security_rule.value.source_port_range
16+
destination_port_range = security_rule.value.destination_port_range
17+
source_address_prefix = security_rule.value.source_address_prefix
18+
destination_address_prefix = security_rule.value.destination_address_prefix
19+
}
20+
}
21+
22+
tags = var.tags
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "name" {
2+
value = azurerm_network_security_group.this.name
3+
}
4+
5+
output "id" {
6+
value = azurerm_network_security_group.this.id
7+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
variable "name" {
2+
type = string
3+
description = "The name of the nsg."
4+
}
5+
6+
variable "resource_group_name" {
7+
type = string
8+
description = "The name of the resource group in which to create the NSG. Changing this forces a new resource to be created."
9+
}
10+
11+
variable "location" {
12+
type = string
13+
description = "location"
14+
}
15+
16+
variable "tags" {
17+
type = map(string)
18+
description = "Resource tags to be applied throughout the deployment."
19+
default = {}
20+
}
21+
22+
variable "nsg_rules" {
23+
description = "Additional NSG rules for securing subnets (Optional)."
24+
type = list(object({
25+
name = string
26+
priority = number
27+
direction = string
28+
access = string
29+
protocol = string
30+
source_port_range = string
31+
destination_port_range = string
32+
source_address_prefix = string
33+
destination_address_prefix = string
34+
}))
35+
36+
validation {
37+
condition = length(var.nsg_rules) == 0 || alltrue([
38+
for rule in var.nsg_rules : (
39+
rule.name != "" &&
40+
rule.priority > 99 &&
41+
contains(["Inbound", "Outbound"], rule.direction) &&
42+
contains(["Allow", "Deny"], rule.access) &&
43+
contains(["Tcp", "Udp", "Icmp", "*"], rule.protocol) &&
44+
rule.source_port_range != "" &&
45+
rule.destination_port_range != "" &&
46+
rule.source_address_prefix != "" &&
47+
rule.destination_address_prefix != ""
48+
)
49+
])
50+
error_message = "Each network security group rule must have a valid name, priority, direction (Inbound or Outbound), access (Allow or Deny), protocol (Tcp, Udp, Icmp, or *), source port range, destination port range, source address prefix, and destination address prefix."
51+
}
52+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Note it is not necessary to declare the name for the role assignment as this is auto-generated in GUID format.
2+
resource "azurerm_role_assignment" "role_assignment" {
3+
scope = var.scope
4+
principal_id = var.principal_id
5+
role_definition_id = data.azurerm_role_definition.role_definition.id
6+
}
7+
8+
# Look up the role definition by name as a convenience for the user
9+
data "azurerm_role_definition" "role_definition" {
10+
name = var.role_definition_name
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "name" {
2+
value = azurerm_role_assignment.role_assignment.name
3+
}
4+
5+
output "id" {
6+
value = azurerm_role_assignment.role_assignment.id
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "scope" {
2+
description = "The scope at which the role assignment will be created."
3+
type = string
4+
}
5+
6+
variable "principal_id" {
7+
description = "The principal ID (e.g., user, group, or service principal) to which the role will be assigned."
8+
type = string
9+
}
10+
11+
variable "role_definition_name" {
12+
description = "The name of the role definition to assign."
13+
type = string
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "azurerm_route_table" "route_table" {
2+
name = var.name
3+
location = var.location
4+
resource_group_name = var.resource_group_name
5+
6+
tags = var.tags
7+
8+
bgp_route_propagation_enabled = var.bgp_route_propagation_enabled
9+
10+
dynamic "route" {
11+
for_each = var.routes
12+
content {
13+
name = route.value.name
14+
address_prefix = route.value.address_prefix
15+
next_hop_type = route.value.next_hop_type
16+
next_hop_in_ip_address = route.value.next_hop_in_ip_address
17+
}
18+
}
19+
}
20+
21+
resource "azurerm_subnet_route_table_association" "route_table_association" {
22+
count = length(var.subnet_ids)
23+
24+
subnet_id = var.subnet_ids[count.index]
25+
route_table_id = azurerm_route_table.route_table.id
26+
}

0 commit comments

Comments
 (0)