|
| 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 | +} |
0 commit comments