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

fix: Karpenter node IAM role policies variable should be a map of strings, not list #2771

Merged

Conversation

bryantbiggs
Copy link
Member

Description

  • Karpenter node IAM role policies variable should be a map of strings, not list
  • Update Karpenter example to show attaching policies on the node IAM role which is more common that attaching additional policies on the IRSA role

Motivation and Context

Breaking Changes

  • No

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@bryantbiggs bryantbiggs merged commit f4766e5 into terraform-aws-modules:master Oct 10, 2023
17 checks passed
@bryantbiggs bryantbiggs deleted the fix/karpenter-policies branch October 10, 2023 15:57
antonbabenko pushed a commit that referenced this pull request Oct 10, 2023
### [19.17.2](v19.17.1...v19.17.2) (2023-10-10)

### Bug Fixes

* Karpenter node IAM role policies variable should be a map of strings, not list ([#2771](#2771)) ([f4766e5](f4766e5))
@antonbabenko
Copy link
Member

This PR is included in version 19.17.2 🎉

@kkopachev
Copy link

Was not that a breaking change?

@bryantbiggs
Copy link
Member Author

Was not that a breaking change?

No - are you seeing an issue?

@kkopachev
Copy link

I had a code which was passing this old style as a list and it's breaking now.

Error: Invalid value for input variable

  on ../../modules/k8s-addons/karpenter/main.tf line 8, in module "karpenter":
   8:   iam_role_additional_policies = [
   9:     "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
  10:   ]

The given value is not suitable for
module.karpenter.module.karpenter.var.iam_role_additional_policies declared
at
.terraform/modules/karpenter.karpenter/modules/karpenter/variables.tf:224,1-40:
map of string required.

Module code was

module "karpenter" {
  source  = "terraform-aws-modules/eks/aws//modules/karpenter"
  version = "~>19.13"

  cluster_name           = var.cluster_name
  irsa_oidc_provider_arn = var.oidc_provider_arn

  iam_role_additional_policies = [
    "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
  ]
}

Not a big deal, but unexpected

@kamirendawkins
Copy link

Just wanted to hop on this this, its not a huge deal but watching a number of workspaces suddenly have issue leads me to feel that this is not fix but a potentially breaking change for those that are automatically pulling in patch levels.

@mkunkel
Copy link

mkunkel commented Oct 10, 2023

We also found this to be a breaking change. We have two workspaces that suddenly began to fail with this change.

@bryantbiggs
Copy link
Member Author

my apologies for the disruption, that was not intended. I am somewhat shocked the prior variable type didn't raise issues before because the usage is written to accept a map, not a list

for_each = { for k, v in var.iam_role_additional_policies : k => v if local.create_iam_role }

I guess HCL must silently convert the list index to the key when using for_each over a list 🤔

@kamirendawkins
Copy link

@bryantbiggs I asked the same "how did this ever work question", basically k becomes 0 as that is the "key" in the list if I understand what happened correctly.

@kkopachev
Copy link

If you had already old format variable and just changing it to be a map, beware. Unless you use moved block to map old to new, there is a chance that terraform will try to create same policy (and ignore duplicate error) and then delete old policy, meaning that you'll end up without a policy at all.
Either apply twice, or use moved block

@absolutemikex
Copy link

I won't upgrade yet - but what is the recommended change to handle this gracefully? As others have mentioned I have this in my TF.

 iam_role_additional_policies = [
  "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
    ]

Was the intention just to have you swap it to {} ?

@bryantbiggs
Copy link
Member Author

You would change that to:

iam_role_additional_policies = {
  AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
} 

Note: the key portion doesn't really matter so you can name the key anything you like, it just has to be unique within the map

cdenneen pushed a commit to cdenneen/terraform-aws-eks that referenced this pull request Oct 16, 2023
* Karpenter node IAM role policies variable should be a map of strings, not list ([terraform-aws-modules#2771](terraform-aws-modules#2771)) ([f4766e5](terraform-aws-modules@f4766e5))

(cherry picked from commit 51cc6be)
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[karpenter] Set SSMSessionManager on node IAM role by default
6 participants