-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for managing
aws-auth
configmap using new `kubern…
…etes_config_map_v1_data` resource (#1999)
- Loading branch information
1 parent
3ff1720
commit da3d54c
Showing
16 changed files
with
263 additions
and
208 deletions.
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
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
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 |
---|---|---|
|
@@ -8,6 +8,18 @@ provider "aws" { | |
} | ||
} | ||
|
||
provider "kubernetes" { | ||
host = module.eks.cluster_endpoint | ||
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) | ||
|
||
exec { | ||
api_version = "client.authentication.k8s.io/v1alpha1" | ||
command = "aws" | ||
# This requires the awscli to be installed locally where Terraform is executed | ||
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_id] | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bryantbiggs
Author
Member
|
||
} | ||
|
||
locals { | ||
name = "ex-${replace(basename(path.cwd), "_", "-")}" | ||
region = "eu-west-1" | ||
|
@@ -180,6 +192,43 @@ module "eks" { | |
} | ||
} | ||
|
||
# aws-auth configmap | ||
manage_aws_auth_configmap = true | ||
|
||
aws_auth_node_iam_role_arns_non_windows = [ | ||
module.eks_managed_node_group.iam_role_arn, | ||
module.self_managed_node_group.iam_role_arn, | ||
] | ||
aws_auth_fargate_profile_pod_execution_role_arns = [ | ||
module.fargate_profile.fargate_profile_pod_execution_role_arn | ||
] | ||
|
||
aws_auth_roles = [ | ||
{ | ||
rolearn = "arn:aws:iam::66666666666:role/role1" | ||
username = "role1" | ||
groups = ["system:masters"] | ||
}, | ||
] | ||
|
||
aws_auth_users = [ | ||
{ | ||
userarn = "arn:aws:iam::66666666666:user/user1" | ||
username = "user1" | ||
groups = ["system:masters"] | ||
}, | ||
{ | ||
userarn = "arn:aws:iam::66666666666:user/user2" | ||
username = "user2" | ||
groups = ["system:masters"] | ||
}, | ||
] | ||
|
||
aws_auth_accounts = [ | ||
"777777777777", | ||
"888888888888", | ||
] | ||
|
||
tags = local.tags | ||
} | ||
|
||
|
@@ -269,80 +318,6 @@ module "disabled_self_managed_node_group" { | |
create = false | ||
} | ||
|
||
################################################################################ | ||
# aws-auth configmap | ||
# Only EKS managed node groups automatically add roles to aws-auth configmap | ||
# so we need to ensure fargate profiles and self-managed node roles are added | ||
################################################################################ | ||
|
||
data "aws_eks_cluster_auth" "this" { | ||
name = module.eks.cluster_id | ||
} | ||
|
||
locals { | ||
kubeconfig = yamlencode({ | ||
apiVersion = "v1" | ||
kind = "Config" | ||
current-context = "terraform" | ||
clusters = [{ | ||
name = module.eks.cluster_id | ||
cluster = { | ||
certificate-authority-data = module.eks.cluster_certificate_authority_data | ||
server = module.eks.cluster_endpoint | ||
} | ||
}] | ||
contexts = [{ | ||
name = "terraform" | ||
context = { | ||
cluster = module.eks.cluster_id | ||
user = "terraform" | ||
} | ||
}] | ||
users = [{ | ||
name = "terraform" | ||
user = { | ||
token = data.aws_eks_cluster_auth.this.token | ||
} | ||
}] | ||
}) | ||
|
||
# we have to combine the configmap created by the eks module with the externally created node group/profile sub-modules | ||
aws_auth_configmap_yaml = <<-EOT | ||
${chomp(module.eks.aws_auth_configmap_yaml)} | ||
- rolearn: ${module.eks_managed_node_group.iam_role_arn} | ||
username: system:node:{{EC2PrivateDNSName}} | ||
groups: | ||
- system:bootstrappers | ||
- system:nodes | ||
- rolearn: ${module.self_managed_node_group.iam_role_arn} | ||
username: system:node:{{EC2PrivateDNSName}} | ||
groups: | ||
- system:bootstrappers | ||
- system:nodes | ||
- rolearn: ${module.fargate_profile.fargate_profile_pod_execution_role_arn} | ||
username: system:node:{{SessionName}} | ||
groups: | ||
- system:bootstrappers | ||
- system:nodes | ||
- system:node-proxier | ||
EOT | ||
} | ||
|
||
resource "null_resource" "patch" { | ||
triggers = { | ||
kubeconfig = base64encode(local.kubeconfig) | ||
cmd_patch = "kubectl patch configmap/aws-auth --patch \"${local.aws_auth_configmap_yaml}\" -n kube-system --kubeconfig <(echo $KUBECONFIG | base64 --decode)" | ||
} | ||
|
||
provisioner "local-exec" { | ||
interpreter = ["/bin/bash", "-c"] | ||
environment = { | ||
KUBECONFIG = self.triggers.kubeconfig | ||
} | ||
command = self.triggers.cmd_patch | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Supporting resources | ||
################################################################################ | ||
|
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
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
Oops, something went wrong.
1 comment
on commit da3d54c
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.
This change reintroduces this issue #1280 (comment)
With e.g.