Skip to content

Commit

Permalink
Add terraform for capz monitoring cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Feb 10, 2025
1 parent f12f4d2 commit 792ffdb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
81 changes: 81 additions & 0 deletions infra/azure/terraform/capz/capz-monitoring/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 6 additions & 0 deletions infra/azure/terraform/capz/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 792ffdb

Please sign in to comment.