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

feat: add cluster_telemetry to beta submodules #728

Conversation

nguyenhoaibao
Copy link
Contributor

Closes #645

@comment-bot-dev
Copy link

comment-bot-dev commented Nov 2, 2020

Thanks for the PR! 🚀
✅ Lint checks have passed.

@nguyenhoaibao nguyenhoaibao force-pushed the feature/cluster-telemetry branch from 5b6a704 to ecd4609 Compare November 2, 2020 05:42
@nguyenhoaibao nguyenhoaibao changed the title feat: add cluster_telemetry for submodules feat: add cluster_telemetry to beta submodules Nov 2, 2020
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

CI is returning this error:

       Error: expected cluster_telemetry.0.type to be one of [DISABLED ENABLED SYSTEM_ONLY], got ENABLE
       
         on ../../../modules/beta-public-cluster/cluster.tf line 60, in resource "google_container_cluster" "primary":
         60:     type = var.cluster_telemetry_type
       
       
       
       Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 62, in resource "google_container_cluster" "primary":
         62:   logging_service    = var.logging_service
       
       "logging_service": conflicts with cluster_telemetry
       
       
       Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 63, in resource "google_container_cluster" "primary":
         63:   monitoring_service = var.monitoring_service
       
       "monitoring_service": conflicts with cluster_telemetry

Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

@nguyenhoaibao Looks like the provider docs needs to be updated, supported values are ENABLED, DISABLED, SYSTEM_ONLY
GoogleCloudPlatform/magic-modules#3853

@nguyenhoaibao
Copy link
Contributor Author

nguyenhoaibao commented Nov 3, 2020

@morgante @bharathkkb I fixed the cluster_telemetry supported values. Can you guys take a look?

cluster_telemetry {
type = var.cluster_telemetry_type
}
{% else %}
Copy link
Member

@bharathkkb bharathkkb Nov 3, 2020

Choose a reason for hiding this comment

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

We may want to keep logging_service and monitoring_service to keep supporting 1.14 clusters as the GKE API also supports these concurrently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently cluster_telemetry and logging_service/monitoring_service can't be set at the same time, see this and this. Also from the output of the failed CI above, when I set both cluster_telemetry and logging_service/monitoring_service:

Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 62, in resource "google_container_cluster" "primary":
         62:   logging_service    = var.logging_service
       
       "logging_service": conflicts with cluster_telemetry
       
       
       Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 63, in resource "google_container_cluster" "primary":
         63:   monitoring_service = var.monitoring_service
       
       "monitoring_service": conflicts with cluster_telemetry

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but the conditional should probably be based in the Terraform not the templating layer.

Copy link
Contributor Author

@nguyenhoaibao nguyenhoaibao Nov 4, 2020

Choose a reason for hiding this comment

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

Can you explain more? How can I use conditional in resource block? Is something like this ok?

locals {
  cluster_telemetry_type_is_set = var.cluster_telemetry_type != "" ? [1] : [0]
}

{% if beta_cluster %}
  dynamic "cluster_telemetry" {
    for_each = local.cluster_telemetry_type_is_set
    content {
      type = var.cluster_telemetry_type
    }
  }
{% else %}
  dynamic "cluster_telemetry" {
    for_each = length(local.cluster_telemetry_type_is_set) > 0 ? [] : [1]
    content {
      type = var.cluster_telemetry_type
    }
  }
  logging_service    = var.logging_service
  monitoring_service = var.monitoring_service
{% endif %}

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking something more like this:

locals {
  cluster_telemetry_type_is_set = var.cluster_telemetry_type != ""
}

dynamic "cluster_telemetry" {
    for_each = local.cluster_telemetry_type_is_set > 0 ? [] : [1]
    content {
      type = var.cluster_telemetry_type
    }
  }
  logging_service    = local.cluster_telemetry_type_is_set ? null : var.logging_service
  monitoring_service =  local.cluster_telemetry_type_is_set ? null : var.monitoring_service
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like an unrelated ephemeral error, re-running.

Copy link
Member

Choose a reason for hiding this comment

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

There might be an edge case where for 1.14 clusters you can use legacy logging_service="logging.googleapis.com" and this change will try to change to cluster_telemetry="ENABLED" since we set cluster_telemetry_type to ENABLED by default. However, this should be okay as it will be caught by the API and an error will be thrown.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm looks like we're getting an error on the sandbox-enabled-local example:

       
       Error: Required attribute is not set
       
         on ../../../modules/beta-public-cluster/cluster.tf line 22, in resource "google_container_cluster" "primary":
         22: resource "google_container_cluster" "primary" {
       
       
       
       Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 65, in resource "google_container_cluster" "primary":
         65:   logging_service    = local.cluster_telemetry_type_is_set ? null : var.logging_service
       
       "logging_service": conflicts with cluster_telemetry
       
       
       Error: ConflictsWith
       
         on ../../../modules/beta-public-cluster/cluster.tf line 66, in resource "google_container_cluster" "primary":
         66:   monitoring_service = local.cluster_telemetry_type_is_set ? null : var.monitoring_service
       
       "monitoring_service": conflicts with cluster_telemetry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm you have any idea to fix this?

Copy link
Member

Choose a reason for hiding this comment

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

@nguyenhoaibao I think this should be

- for_each = local.cluster_telemetry_type_is_set ? [1] : [0]
+ for_each = local.cluster_telemetry_type_is_set ? [1] : []

[0] is still a list with 1 element which is causing the creation of the dynamic block.

autogen/main/variables.tf.tmpl Outdated Show resolved Hide resolved
Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

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

LGTM

@morgante morgante merged commit e8291f0 into terraform-google-modules:master Nov 5, 2020
CPL-markus pushed a commit to WALTER-GROUP/terraform-google-kubernetes-engine that referenced this pull request Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for cluster_telemetry config
4 participants