我们正在建立一些绿色领域的AWS基础设施。
我们在组织帐户级别有一个IAM用户,Terraform将其认证为使用访问密钥。然后,我们将Terraform代码设置为在它们各自的git repos中“承担角色”到我们的子帐户中(我们每个帐户有一个git )。就像,
provider "aws" {
assume_role {
role_arn = "arn:aws:iam::XXXXXXXXXX:role/TerraformCloudRole"
}
}我们遇到了使用terraform-aws-modules/eks/aws模块设置EKS集群的问题。集群创建得很好,但是我们已经设置了manage_aws_auth_configmap = true,这样我们就可以提供IAM角色/用户并管理他们可以对其进行身份验证的内容。我们实际上看到了多个错误,这取决于我们创建或更新的位置,以及代码的一些细微变化。从本质上讲,
Error: The configmap "aws-auth" does not exist
with module.eks_main.module.eks.kubernetes_config_map_v1_data.aws_auth[0]
on .terraform/modules/eks_main.eks/main.tf line 470, in resource "kubernetes_config_map_v1_data" "aws_auth":或
Error: Get "http://localhost/api/v1/namespaces/kube-system/configmaps/aws-auth": dial tcp [::1]:80: connect: connection refused
with module.eks_main.module.eks.kubernetes_config_map_v1_data.aws_auth[0]
on .terraform/modules/eks_main.eks/main.tf line 470, in resource "kubernetes_config_map_v1_data" "aws_auth":我们搜索了一下,发现了本期。我们添加了一个提供者,这似乎解决了一些问题,特别是使用这种方法。原因是因为exec路线对我们不起作用。它似乎试图使用基本访问键而不是假定的角色来执行AWS命令。但是,当我们对集群进行更新或试图运行破坏时,错误又回来了!它似乎并没有因为某种原因而接上供应商。以上的后一个错误是在计划阶段,而不是应用。
所以,我的问题,。当AWS承担角色/交叉帐户时,我们如何设置Terraform来连接/管理EKS集群?
发布于 2022-08-23 18:41:55
也许能帮上忙:
provider "aws" {
alias = "main"
region = var.aws_region
}
data "aws_eks_cluster" "selected" {
provider = aws.main
name = local.eks_cluster_name
}
data "aws_eks_cluster_auth" "selected" {
provider = aws.main
name = local.eks_cluster_name
}
provider "kubernetes" {
host = element(concat(data.aws_eks_cluster.selected[*].endpoint, tolist([""])), 0)
cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.selected[*].certificate_authority.0.data, tolist([""])), 0))
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["token", "-i", element(concat(data.aws_eks_cluster.selected[*].id, tolist([""])), 0)]
command = "aws-iam-authenticator"
}
}
provider "helm" {
kubernetes {
host = element(concat(data.aws_eks_cluster.selected[*].endpoint, tolist([""])), 0)
cluster_ca_certificate = base64decode(element(concat(data.aws_eks_cluster.selected[*].certificate_authority.0.data, tolist([""])), 0))
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["token", "-i", element(concat(data.aws_eks_cluster.selected[*].id, tolist([""])), 0)]
command = "aws-iam-authenticator"
}
}
}我不确定这将是最新的,但我相信这将对您有很大帮助,您可以将命令更改为tho,因为它使用aws-iam-authenticator二进制
https://stackoverflow.com/questions/73444426
复制相似问题