-
Notifications
You must be signed in to change notification settings - Fork 860
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 terraform for capz monitoring cluster #7776
Open
willie-yao
wants to merge
3
commits into
kubernetes:main
Choose a base branch
from
willie-yao:capz-monitoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−0
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
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 "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 = var.location | ||
name = var.resource_group_name | ||
tags = { | ||
DO-NOT-DELETE = "contact capz" | ||
creationTimestamp = "2024-10-24T00:00:00Z" | ||
} | ||
} | ||
|
||
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 | ||
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 = 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" | ||
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised that this resource group needs to be captured in the terraform. This is a RG that is managed by AKS and shouldn't be managed by terraform AFAIK.
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#node_resource_group-1
Says confirms that for me, in that we could provide a name but otherwise don't need to specify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense. I included it because I noticed that this resource group has been getting deleted on the CNCF sub periodically while I'm testing even though I have the do not delete tag set on it. Does this need to be in terraform if I don't want it to be deleted, or is that being caused by something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that if you put the tags do-not-delete on the AKS resource group and AKS cluster, it will carry those through when it creates managed RG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm okay, next time it gets deleted I might need some help figuring out what is causing it. Thanks!