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

Unable to set some boolean values on addon Helm configuration #942

Closed
1 task done
wjam opened this issue Sep 9, 2022 · 0 comments · Fixed by #943
Closed
1 task done

Unable to set some boolean values on addon Helm configuration #942

wjam opened this issue Sep 9, 2022 · 0 comments · Fixed by #943

Comments

@wjam
Copy link
Contributor

wjam commented Sep 9, 2022

Description

I'm unable to set the prometheus.io/scrape flag on the cluster-autoscaler deployment using the cluster_autoscaler addon using the set pattern. [1]

Applying this Terraform:

module "eks_blueprints_kubernetes_addons" {
  source = "github.com/aws-ia/terraform-aws-eks-blueprints//modules/kubernetes-addons?ref=v4.8.1"

  eks_cluster_id       = var.eks_cluster_id
  eks_cluster_endpoint = var.eks_cluster_endpoint
  eks_oidc_provider    = var.oidc_provider
  eks_cluster_version  = var.eks_cluster_version

  enable_cluster_autoscaler           = true
  cluster_autoscaler_helm_config = {
    set = [
      {
        name = "podLabels.prometheus\\.io/scrape",
        value = "true",
      }
    ]
  }
}

Results in the error:

│ Error: failed to create resource: Deployment in version "v1" cannot be handled as a Deployment: json: cannot unmarshal bool into Go struct field LabelSelector.spec.selector.matchLabels of type string
│
│   with module.eks_blueprints_kubernetes_addons.module.cluster_autoscaler[0].module.helm_addon.helm_release.addon[0],
│   on .terraform/modules/eks_blueprints_kubernetes_addons/modules/kubernetes-addons/helm-addon/main.tf line 1, in resource "helm_release" "addon":
│    1: resource "helm_release" "addon" {
│

While I haven't tested other addons, I suspect they will suffer from the same problem.

[1] It would be possible to pass in the configuration using values rather than set, but this then hits aws-ia/terraform-aws-eks-blueprints-addons#38.

  • ✋ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]: 4.8.1
  • Terraform version: v1.2.8
  • Provider version(s):
  • provider registry.terraform.io/gavinbunney/kubectl v1.14.0
  • provider registry.terraform.io/hashicorp/aws v4.29.0
  • provider registry.terraform.io/hashicorp/helm v2.6.0
  • provider registry.terraform.io/hashicorp/kubernetes v2.13.1
  • provider registry.terraform.io/hashicorp/time v0.8.0

Reproduction Code [Required]

Steps to reproduce the behavior:

Provision an EKS cluster with cluster-autoscaler with the Helm config set to:

cluster_autoscaler_helm_config = {
    set = [
      {
        name = "podLabels.prometheus\\.io/scrape",
        value = "true",
      }
    ]
  }

Expected behaviour

There should be a mechanism to set values that Kuebrnetes expect to be string but Go/HCL forces them to be a boolean or number.

Actual behaviour

Terraform fails to apply the changes and returns the error:

│ Error: failed to create resource: Deployment in version "v1" cannot be handled as a Deployment: json: cannot unmarshal bool into Go struct field LabelSelector.spec.selector.matchLabels of type string
│
│   with module.eks_blueprints_kubernetes_addons.module.cluster_autoscaler[0].module.helm_addon.helm_release.addon[0],
│   on .terraform/modules/eks_blueprints_kubernetes_addons/modules/kubernetes-addons/helm-addon/main.tf line 1, in resource "helm_release" "addon":
│    1: resource "helm_release" "addon" {
│

Terminal Output Screenshot(s)

Additional context

wjam added a commit to wjam/terraform-aws-eks-blueprints that referenced this issue Sep 9, 2022
Certain values in a Kubernetes resource _must_ be a string and
Kubernetes will complain if the value is of another type rather than
automatically convert it into a string. An example of this problem would
be the value `true` on a `Pod` label - in YAML, this must be `"true"`
for Kubernetes to be satisfied.

This adds a new optional attribute for the `set` element of all
`*_helm_config` variables which allows the user to switch from the
default behaviour of handling the `value` - `auto` - to `string`, which
will force the `value` to be handled as text rather than a boolean or
number.

Fixes aws-ia#942
bryantbiggs pushed a commit that referenced this issue Sep 9, 2022
Certain values in a Kubernetes resource _must_ be a string and
Kubernetes will complain if the value is of another type rather than
automatically convert it into a string. An example of this problem would
be the value `true` on a `Pod` label - in YAML, this must be `"true"`
for Kubernetes to be satisfied.

This adds a new optional attribute for the `set` element of all
`*_helm_config` variables which allows the user to switch from the
default behaviour of handling the `value` - `auto` - to `string`, which
will force the `value` to be handled as text rather than a boolean or
number.

Fixes #942
allamand pushed a commit to allamand/terraform-aws-eks-blueprints that referenced this issue Dec 15, 2022
Certain values in a Kubernetes resource _must_ be a string and
Kubernetes will complain if the value is of another type rather than
automatically convert it into a string. An example of this problem would
be the value `true` on a `Pod` label - in YAML, this must be `"true"`
for Kubernetes to be satisfied.

This adds a new optional attribute for the `set` element of all
`*_helm_config` variables which allows the user to switch from the
default behaviour of handling the `value` - `auto` - to `string`, which
will force the `value` to be handled as text rather than a boolean or
number.

Fixes aws-ia#942
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 a pull request may close this issue.

1 participant