Skip to content

Commit 91767af

Browse files
authored
Merge pull request #7776 from willie-yao/capz-monitoring
Add terraform for capz monitoring cluster
2 parents 77d5b16 + aa762e8 commit 91767af

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
variable "resource_group_name" {
18+
type = string
19+
}
20+
21+
variable "location" {
22+
type = string
23+
}
24+
25+
variable "subscription_id" {
26+
type = string
27+
}
28+
29+
# Create the "capz-monitoring" resource group
30+
resource "azurerm_resource_group" "capz-monitoring" {
31+
location = var.location
32+
name = var.resource_group_name
33+
tags = {
34+
DO-NOT-DELETE = "contact capz"
35+
creationTimestamp = timestamp()
36+
}
37+
}
38+
39+
resource "azurerm_user_assigned_identity" "capz_monitoring_user_identity" {
40+
name = "capz-monitoring-user-identity"
41+
location = azurerm_resource_group.capz-monitoring.location
42+
resource_group_name = azurerm_resource_group.capz-monitoring.name
43+
}
44+
45+
resource "azurerm_role_assignment" "monitoring_reader" {
46+
principal_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.principal_id
47+
role_definition_name = "Monitoring Reader"
48+
scope = "/subscriptions/${var.subscription_id}"
49+
depends_on = [ azurerm_user_assigned_identity.capz_monitoring_user_identity ]
50+
}
51+
52+
resource "azurerm_kubernetes_cluster" "capz-monitoring" {
53+
dns_prefix = var.resource_group_name
54+
location = var.location
55+
name = var.resource_group_name
56+
resource_group_name = var.resource_group_name
57+
tags = {
58+
DO-NOT-DELETE = "contact capz"
59+
creationTimestamp = timestamp()
60+
}
61+
depends_on = [
62+
azurerm_resource_group.capz-monitoring,
63+
azurerm_user_assigned_identity.capz_monitoring_user_identity,
64+
]
65+
kubelet_identity {
66+
user_assigned_identity_id = azurerm_user_assigned_identity.capz_monitoring_user_identity.id
67+
}
68+
identity {
69+
type = "UserAssigned"
70+
identity_ids = [
71+
azurerm_user_assigned_identity.capz_monitoring_user_identity.id
72+
]
73+
}
74+
default_node_pool {
75+
name = "default"
76+
node_count = 1
77+
vm_size = "Standard_Ds2_v2"
78+
}
79+
}

infra/azure/terraform/capz/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,11 @@ module "cluster_api_gallery" {
133133
location = var.location
134134
depends_on = module.role_assignments
135135
}
136+
137+
# Import CAPZ monitoring module
138+
module "capz_monitoring" {
139+
source = "./capz-monitoring"
140+
resource_group_name = var.resource_group_name
141+
location = var.location
142+
subscription_id = data.azurerm_client_config.current.subscription_id
143+
}

0 commit comments

Comments
 (0)