Skip to content
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 msi_auth_for_monitoring_enabled #446

Merged

Conversation

admincasper
Copy link
Contributor

No description provided.

@admincasper
Copy link
Contributor Author

@microsoft-github-policy-service agree

@zioproto
Copy link
Collaborator

@admincasper thanks for your contribution. Could you please run the pre-commit and pr-check steps like described in our module docs ? https://github.com/Azure/terraform-azurerm-aks#pre-commit--pr-check--test

Thanks

@admincasper
Copy link
Contributor Author

admincasper commented Sep 21, 2023

Just ran both pre-commit and pr-check.
They ran without error, pushed the formatted code.

@@ -446,6 +446,7 @@ resource "azurerm_kubernetes_cluster" "main" {

content {
log_analytics_workspace_id = local.log_analytics_workspace.id
msi_auth_for_monitoring_enabled = var.msi_auth_for_monitoring_enabled
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already present in provider version 3.47.0:
hashicorp/terraform-provider-azurerm#20757

No need to bump versions. All good.

@zioproto
Copy link
Collaborator

Just ran both pre-commit and pr-check. They ran without error, pushed the formatted code.

I dont see the new changes. main.tf had a formatting issue, and there must be a patch to the Readme.

variables.tf Outdated
@@ -689,6 +689,13 @@ variable "maintenance_window_node_os" {
EOT
}

variable "msi_auth_for_monitoring_enabled" {
type = bool
default = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@admincasper admincasper Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running module aks with log_analytics_workspace_enabled = true without specifying msi_auth_for_monitoring_enabled the value is false by default. I checked by running az aks addon show --addon monitoring.

So I thought default value was false.

Copy link
Contributor Author

@admincasper admincasper Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weird, because enabling monitoring addon with az aks CLI the default value is True..
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is nullable = false, I interpreted it as only possible values should be either False or True? Correct me if I'm wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @zioproto, according to the provider schema, this msi_auth_for_monitoring_enabled argument's default value is null, setting default value to false could cause a configuration drift. Would you please set the default value to null?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@admincasper It is often the case that Terraform has true false and null. But when you read back from the azurerm API the values are just true or false. Now we are interested if this value is explicit in the Terraform state as false. I hope this clarifies why you dont get back null from your az aks show operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thanks for clarifying! I've pushed up the changes.

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @admincasper thanks for opening this pr! Almost LGTM but some review comments to be solved.

variables.tf Outdated
@@ -689,6 +689,13 @@ variable "maintenance_window_node_os" {
EOT
}

variable "msi_auth_for_monitoring_enabled" {
type = bool
default = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @zioproto, according to the provider schema, this msi_auth_for_monitoring_enabled argument's default value is null, setting default value to false could cause a configuration drift. Would you please set the default value to null?

variables.tf Outdated
variable "msi_auth_for_monitoring_enabled" {
type = bool
default = false
description = "(Optional) Is managed identity authentication for monitoring enabled? Defaults to `false`"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove "Defaults to false" here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@admincasper on line 695 at the end of the description string, can you remove:

Defaults to `false`

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@admincasper on line 695 at the end of the description string, can you remove:

Defaults to `false`

Thanks

@zioproto I think it needs to default to null. So I changed it to null.

I think everything should be ok now then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@admincasper line 694 is ok, the correct default is null. don't touch it. In line 695 you have to remove the last statement in the description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zioproto Done. Removed "Defaults to 'null'" in description.

variables.tf Outdated
type = bool
default = false
description = "(Optional) Is managed identity authentication for monitoring enabled? Defaults to `false`"
nullable = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable could be set to null, we can just remove this setting.

main.tf Show resolved Hide resolved
@avekrivoy
Copy link

@admincasper did you manage to resolve all the issues? Looking forward to the feature

@admincasper
Copy link
Contributor Author

@admincasper did you manage to resolve all the issues? Looking forward to the feature

I thought I had already done so.. I couldn't figure out what @lonegunmanb meant..

I actually think this works okay already? I don't understand why msi_auth_for_monitoring_enabled != null should create oms_agent block.

  1. If log_analytics_workspace_enabled = true, and msi_auth_for_monitoring_enabled = null:
    oms_agent block is OK
  2. If log_analytics_workspace_enabled = true, and msi_auth_for_monitoring_enabled = True || False:
    oms_agent block is OK
  3. If log_analytics_workspace_enabled = false:
    oms_agent block is EMPTY (N/A).

@avekrivoy
Copy link

avekrivoy commented Oct 4, 2023

@lonegunmanb could you please take a look?

@lonegunmanb
Copy link
Member

lonegunmanb commented Oct 13, 2023

@admincasper @zioproto Apology for the confusion.

@lonegunmanb: I think adding msi_auth_for_monitoring_enabled just make this for_each complex, now if var.log_analytics_workspace_enabled is true OR var.msi_auth_for_monitoring_enabled is not null should create an oms_agent block. Would you please add a new locals expression in locals.tf file as a new toggle and use it here?

My representation was incorrect, as @admincasper pointed out.

@admincasper 3. If log_analytics_workspace_enabled = false: oms_agent block is EMPTY (N/A).

I've checked the current logic:

dynamic "oms_agent" {
    for_each = var.log_analytics_workspace_enabled ? ["oms_agent"] : []

    content {
      log_analytics_workspace_id = local.log_analytics_workspace.id
    }
  }

I think it is possible that var.log_analytics_workspace_enabled = true and local.log_analytics_workspace.id = null generate an empty block, now I understand that it's irrelevant to this pr.

I'd like to open a separate pr to add a precondition block to prevent such empty oms_agent block once this pr has been merged, thanks @zioproto for your suggestion!

@lonegunmanb
Copy link
Member

@admincasper Only one issue left, modify your new variable's description then I think we're good to go.

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor update for line 695 would unblock this pr from testing.

@admincasper admincasper temporarily deployed to acctests October 13, 2023 06:46 — with GitHub Actions Inactive
@admincasper
Copy link
Contributor Author

A minor update for line 695 would unblock this pr from testing.

Done

@zioproto
Copy link
Collaborator

https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-enable-aks?tabs=azure-cli#existing-clusters-with-system-or-user-assigned-identity

A minor update for line 695 would unblock this pr from testing.

Done

Have you run again the pre-commit and pr-check steps ? it seems the README is not up to date

@admincasper
Copy link
Contributor Author

https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-enable-aks?tabs=azure-cli#existing-clusters-with-system-or-user-assigned-identity

A minor update for line 695 would unblock this pr from testing.

Done

Have you run again the pre-commit and pr-check steps ? it seems the README is not up to date

Done

Copy link
Collaborator

@zioproto zioproto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! @lonegunmanb please merge

@avekrivoy
Copy link

@lonegunmanb could you please merge it? without this feature we can't control metrics scrape period time

@avekrivoy
Copy link

@zioproto could you please merge those changes? @lonegunmanb is clearly not around and this tiny PR from a volunteer has already taken a month

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apology for the late reply @admincasper. LGTM.

@lonegunmanb lonegunmanb merged commit a07880a into Azure:main Oct 23, 2023
3 of 4 checks passed
@admincasper admincasper deleted the add-msi_auth_for_monitoring_enabled branch October 23, 2023 09:59
skolobov pushed a commit to skolobov/terraform-azurerm-aks that referenced this pull request Oct 29, 2023
* add msi_auth_for_monitoring_enabled
@lonegunmanb lonegunmanb added this to the 7.5.0 milestone Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants