Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Modules for DNS Zone, DNS A Record, User Assigned Identity and Update AKS-Firewall module #18

Merged
merged 6 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions modules/azurerm/AKS-Firewall/aks_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "azurerm_kubernetes_cluster" "aks_cluster" {
node_resource_group = join("-", ["rg", var.aks_node_pool_resource_group_name])
sku_tier = var.sku_tier
private_cluster_enabled = var.private_cluster_enabled
private_dns_zone_id = var.private_dns_zone_id
private_cluster_public_fqdn_enabled = var.private_cluster_public_fqdn_enable
role_based_access_control_enabled = true
azure_policy_enabled = var.azure_policy_enabled
Expand Down Expand Up @@ -60,8 +61,19 @@ resource "azurerm_kubernetes_cluster" "aks_cluster" {
only_critical_addons_enabled = var.default_node_pool_only_critical_addons_enabled
}

identity {
type = "SystemAssigned"
dynamic "identity" {
for_each = var.identity_type == "SystemAssigned" ? [1] : []
content {
type = "SystemAssigned"
}
}

dynamic "identity" {
for_each = var.identity_type == "SystemAssigned" ? [] : [1]
content {
type = "UserAssigned"
identity_ids = [var.user_assigned_identity_id]
}
}

azure_active_directory_role_based_access_control {
Expand Down
4 changes: 2 additions & 2 deletions modules/azurerm/AKS-Firewall/role_assignment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
resource "azurerm_role_assignment" "network_contributor_role_assignment_subnet" {
scope = azurerm_subnet.aks_node_pool_subnet.id
role_definition_name = "Network Contributor"
principal_id = azurerm_kubernetes_cluster.aks_cluster.identity[0].principal_id
principal_id = var.identity_type == "SystemAssigned" ? azurerm_kubernetes_cluster.aks_cluster.identity[0].principal_id : var.user_assigned_identity_principal_id
depends_on = [azurerm_kubernetes_cluster.aks_cluster, azurerm_subnet.aks_node_pool_subnet]
}

resource "azurerm_role_assignment" "aks_network_contributor_role_assignment_loadbalancer_subnet" {
scope = azurerm_subnet.internal_load_balancer_subnet.id
role_definition_name = "Network Contributor"
principal_id = azurerm_kubernetes_cluster.aks_cluster.identity[0].principal_id
principal_id = var.identity_type == "SystemAssigned" ? azurerm_kubernetes_cluster.aks_cluster.identity[0].principal_id : var.user_assigned_identity_principal_id
depends_on = [azurerm_kubernetes_cluster.aks_cluster, azurerm_subnet.internal_load_balancer_subnet]
}
23 changes: 23 additions & 0 deletions modules/azurerm/AKS-Firewall/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,26 @@ variable "internal_load_balancer_subnet_enforce_private_link_endpoint_network_po
description = "Enable or Disable network policies for the private link endpoint on the internal load balancer subnet"
type = bool
}

variable "private_dns_zone_id" {
description = "Private DNS zone id"
type = string
}

variable "identity_type" {
description = "Identity type"
type = string
default = "SystemAssigned"
}

variable "user_assigned_identity_id" {
description = "User assigned identity id"
type = string
default = ""
}

variable "user_assigned_identity_principal_id" {
description = "User assigned identity principal id"
type = string
default = ""
}
19 changes: 19 additions & 0 deletions modules/azurerm/DNS-A-Record/dns_a_record.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

resource "azurerm_dns_a_record" "dns_a_record" {
name = var.record_name
zone_name = var.dns_zone_name
resource_group_name = var.resource_group_name
ttl = var.ttl
records = var.records
tags = var.tags
}
40 changes: 40 additions & 0 deletions modules/azurerm/DNS-A-Record/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

variable "record_name" {
description = "The name of the CNAME record."
type = string
}

variable "dns_zone_name" {
description = "The name of the DNS zone in which the record should be created."
type = string
}

variable "resource_group_name" {
description = "The name of the resource group in which the DNS zone exists."
type = string
}

variable "ttl" {
description = "The Time To Live (TTL) of the DNS record in seconds."
type = number
}

variable "records" {
description = "The value of the CNAME records."
type = list(string)
}

variable "tags" {
description = "A mapping of tags to assign to the resource."
type = map(string)
}
20 changes: 20 additions & 0 deletions modules/azurerm/DNS-A-Record/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

terraform {
required_version = ">= 0.13"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.52.0"
}
}
}
2 changes: 1 addition & 1 deletion modules/azurerm/DNS-CNAME-RECORD/dns_cname_record.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# --------------------------------------------------------------------------------------

resource "azurerm_dns_cname_record" "example" {
resource "azurerm_dns_cname_record" "dns_cname_record" {
name = var.record_name
zone_name = var.dns_zone_name
resource_group_name = var.resource_group_name
Expand Down
15 changes: 15 additions & 0 deletions modules/azurerm/DNS-Zone/dns_zone.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

resource "azurerm_dns_zone" "dns_zone" {
name = var.dns_zone_name
resource_group_name = var.resource_group_name
}
15 changes: 15 additions & 0 deletions modules/azurerm/DNS-Zone/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

output "dns_zone_id" {
depends_on = [azurerm_dns_zone.dns_zone]
value = azurerm_dns_zone.dns_zone.id
}
20 changes: 20 additions & 0 deletions modules/azurerm/DNS-Zone/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

variable "dns_zone_name" {
description = "The name of the DNS zone."
type = string
}

variable "resource_group_name" {
description = "The name of the resource group."
type = string
}
20 changes: 20 additions & 0 deletions modules/azurerm/DNS-Zone/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

terraform {
required_version = ">= 0.13"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.52.0"
}
}
}
20 changes: 20 additions & 0 deletions modules/azurerm/User-Assigned-Identity/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

output "azurerm_user_assigned_identity_id" {
depends_on = [azurerm_user_assigned_identity.user_assigned_identity]
value = azurerm_user_assigned_identity.user_assigned_identity.id
}

output "azurerm_user_assigned_identity_principal_id" {
depends_on = [azurerm_user_assigned_identity.user_assigned_identity]
value = azurerm_user_assigned_identity.user_assigned_identity.principal_id
}
16 changes: 16 additions & 0 deletions modules/azurerm/User-Assigned-Identity/user_assigned_identity.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

resource "azurerm_user_assigned_identity" "user_assigned_identity" {
name = var.name
resource_group_name = var.resource_group_name
location = var.location
}
25 changes: 25 additions & 0 deletions modules/azurerm/User-Assigned-Identity/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

variable "name" {
description = "Name of the user assigned identity"
type = string
}

variable "resource_group_name" {
description = "Resource group name"
type = string
}

variable "location" {
description = "Azure region"
type = string
}
20 changes: 20 additions & 0 deletions modules/azurerm/User-Assigned-Identity/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------------------
#
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
#
# This software is the property of WSO2 LLC. and its suppliers, if any.
# Dissemination of any information or reproduction of any material contained
# herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
# You may not alter or remove any copyright or other notice from copies of this content.
#
# --------------------------------------------------------------------------------------

terraform {
required_version = ">= 0.13"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.52.0"
}
}
}
5 changes: 2 additions & 3 deletions modules/azurerm/Vnet-Peering/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ locals {
vnet_src_name = element(local.vnet_src_parts, 8)
vnet_src_resource_group_name = element(local.vnet_src_parts, 4)

vnet_dest_parts = split("/", var.vnet_dest_id)
vnet_dest_name = element(local.vnet_dest_parts, 8)
vnet_dest_resource_group_name = element(local.vnet_dest_parts, 4)
vnet_dest_parts = split("/", var.vnet_dest_id)
vnet_dest_name = element(local.vnet_dest_parts, 8)
}
22 changes: 6 additions & 16 deletions modules/azurerm/Vnet-Peering/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@
#
# --------------------------------------------------------------------------------------

output "vnet_peering_src_id" {
description = "Virtual network src peering id"
value = azurerm_virtual_network_peering.peering_src.id
output "vnet_peering_id" {
description = "Virtual network peering id"
value = azurerm_virtual_network_peering.vnet_peering.id
}

output "vnet_peering_src_name" {
description = "Virtual network src peering name"
value = azurerm_virtual_network_peering.peering_src.name
}

output "vnet_peering_dest_id" {
description = "Virtual network dest peering id"
value = azurerm_virtual_network_peering.peering_dest.id
}

output "vnet_peering_dest_name" {
description = "Virtual network dest peering name"
value = azurerm_virtual_network_peering.peering_dest.name
output "vnet_peering_name" {
description = "Virtual network peering name"
value = azurerm_virtual_network_peering.vnet_peering.name
}
Loading