From 21e8cfee2daa63bf86b1d097b9a4e1ab58cbb949 Mon Sep 17 00:00:00 2001 From: willie-yao Date: Mon, 10 Feb 2025 23:39:05 +0000 Subject: [PATCH 1/3] Add terraform for capz monitoring cluster --- .../terraform/capz/capz-monitoring/main.tf | 81 +++++++++++++++++++ infra/azure/terraform/capz/main.tf | 6 ++ 2 files changed, 87 insertions(+) create mode 100644 infra/azure/terraform/capz/capz-monitoring/main.tf diff --git a/infra/azure/terraform/capz/capz-monitoring/main.tf b/infra/azure/terraform/capz/capz-monitoring/main.tf new file mode 100644 index 00000000000..dabdb1f4850 --- /dev/null +++ b/infra/azure/terraform/capz/capz-monitoring/main.tf @@ -0,0 +1,81 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +variable "subscription_id" { + type = string +} + +# Create the "capz-monitoring" resource group +resource "azurerm_resource_group" "capz-monitoring" { + location = "eastus" + name = "capz-monitoring" + tags = { + DO-NOT-DELETE = "contact capz" + creationTimestamp = "2024-10-24T00:00:00Z" + } +} + +resource "azurerm_resource_group" "MC_capz-monitoring_capz-monitoring_eastus" { + location = "eastus" + name = "MC_capz-monitoring_capz-monitoring_eastus" + tags = { + DO-NOT-DELETE = "contact capz" + creationTimestamp = "2024-10-24T00:00:00Z" + } +} + +resource "azurerm_user_assigned_identity" "capz_monitoring_user_identity" { + name = "capz-monitoring-user-identity" + location = azurerm_resource_group.capz-monitoring.location + resource_group_name = azurerm_resource_group.capz-monitoring.name +} + +resource "azurerm_role_assignment" "monitoring_reader" { + principal_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.principal_id + role_definition_name = "Monitoring Reader" + scope = "/subscriptions/${var.subscription_id}" + depends_on = [ azurerm_user_assigned_identity.capz_monitoring_user_identity ] +} + +resource "azurerm_kubernetes_cluster" "capz-monitoring" { + dns_prefix = "capz-monitoring" + location = azurerm_resource_group.capz-monitoring.location + name = "capz-monitoring" + resource_group_name = azurerm_resource_group.capz-monitoring.name + node_resource_group = azurerm_resource_group.MC_capz-monitoring_capz-monitoring_eastus.name + tags = { + DO-NOT-DELETE = "contact capz" + creationTimestamp = "2024-10-24T00:00:00Z" + } + depends_on = [ + azurerm_resource_group.capz-monitoring, + azurerm_user_assigned_identity.capz_monitoring_user_identity, + ] + kubelet_identity { + user_assigned_identity_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.id + } + identity { + type = "UserAssigned" + identity_ids = [ + azurerm_user_assigned_identity.capz_monitoring_user_identity.id + ] + } + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_Ds2_v2" + } +} diff --git a/infra/azure/terraform/capz/main.tf b/infra/azure/terraform/capz/main.tf index b94b887c834..03dde8104e0 100644 --- a/infra/azure/terraform/capz/main.tf +++ b/infra/azure/terraform/capz/main.tf @@ -133,3 +133,9 @@ module "cluster_api_gallery" { location = var.location depends_on = module.role_assignments } + +# Import CAPZ monitoring module +module "capz_monitoring" { + source = "./capz-monitoring" + subscription_id = data.azurerm_client_config.current.subscription_id +} From b1e6f3023d7df772af2f7886705fea0a01e07afd Mon Sep 17 00:00:00 2001 From: willie-yao Date: Tue, 4 Mar 2025 23:38:19 +0000 Subject: [PATCH 2/3] Change name and location to standard --- .../terraform/capz/capz-monitoring/main.tf | 22 +++++++++++++------ infra/azure/terraform/capz/main.tf | 4 +++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/infra/azure/terraform/capz/capz-monitoring/main.tf b/infra/azure/terraform/capz/capz-monitoring/main.tf index dabdb1f4850..ebdc1428f92 100644 --- a/infra/azure/terraform/capz/capz-monitoring/main.tf +++ b/infra/azure/terraform/capz/capz-monitoring/main.tf @@ -14,14 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ +variable "resource_group_name" { + type = string +} + +variable "location" { + type = string +} + variable "subscription_id" { type = string } # Create the "capz-monitoring" resource group resource "azurerm_resource_group" "capz-monitoring" { - location = "eastus" - name = "capz-monitoring" + location = var.location + name = var.resource_group_name tags = { DO-NOT-DELETE = "contact capz" creationTimestamp = "2024-10-24T00:00:00Z" @@ -29,7 +37,7 @@ resource "azurerm_resource_group" "capz-monitoring" { } resource "azurerm_resource_group" "MC_capz-monitoring_capz-monitoring_eastus" { - location = "eastus" + location = var.location name = "MC_capz-monitoring_capz-monitoring_eastus" tags = { DO-NOT-DELETE = "contact capz" @@ -51,10 +59,10 @@ resource "azurerm_role_assignment" "monitoring_reader" { } resource "azurerm_kubernetes_cluster" "capz-monitoring" { - dns_prefix = "capz-monitoring" - location = azurerm_resource_group.capz-monitoring.location - name = "capz-monitoring" - resource_group_name = azurerm_resource_group.capz-monitoring.name + dns_prefix = var.resource_group_name + location = var.location + name = var.resource_group_name + resource_group_name = var.resource_group_name node_resource_group = azurerm_resource_group.MC_capz-monitoring_capz-monitoring_eastus.name tags = { DO-NOT-DELETE = "contact capz" diff --git a/infra/azure/terraform/capz/main.tf b/infra/azure/terraform/capz/main.tf index 03dde8104e0..7e964485719 100644 --- a/infra/azure/terraform/capz/main.tf +++ b/infra/azure/terraform/capz/main.tf @@ -137,5 +137,7 @@ module "cluster_api_gallery" { # Import CAPZ monitoring module module "capz_monitoring" { source = "./capz-monitoring" - subscription_id = data.azurerm_client_config.current.subscription_id + resource_group_name = var.resource_group_name + location = var.location + subscription_id = data.azurerm_client_config.current.subscription_id } From 950847b1ed985b7e9ef8667a4e47cbbded721fbf Mon Sep 17 00:00:00 2001 From: willie-yao Date: Wed, 5 Mar 2025 21:57:28 +0000 Subject: [PATCH 3/3] Remove node resource group --- infra/azure/terraform/capz/capz-monitoring/main.tf | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/infra/azure/terraform/capz/capz-monitoring/main.tf b/infra/azure/terraform/capz/capz-monitoring/main.tf index ebdc1428f92..3b7c1b75d35 100644 --- a/infra/azure/terraform/capz/capz-monitoring/main.tf +++ b/infra/azure/terraform/capz/capz-monitoring/main.tf @@ -36,15 +36,6 @@ resource "azurerm_resource_group" "capz-monitoring" { } } -resource "azurerm_resource_group" "MC_capz-monitoring_capz-monitoring_eastus" { - location = var.location - name = "MC_capz-monitoring_capz-monitoring_eastus" - tags = { - DO-NOT-DELETE = "contact capz" - creationTimestamp = "2024-10-24T00:00:00Z" - } -} - resource "azurerm_user_assigned_identity" "capz_monitoring_user_identity" { name = "capz-monitoring-user-identity" location = azurerm_resource_group.capz-monitoring.location @@ -63,7 +54,6 @@ resource "azurerm_kubernetes_cluster" "capz-monitoring" { location = var.location name = var.resource_group_name resource_group_name = var.resource_group_name - node_resource_group = azurerm_resource_group.MC_capz-monitoring_capz-monitoring_eastus.name tags = { DO-NOT-DELETE = "contact capz" creationTimestamp = "2024-10-24T00:00:00Z"