Data Engineering/DevOps
Terraform으로 AWS EKS의 aws-auth configmap 관리하기
혜성 Hyesung
2022. 4. 28. 22:58
반응형
terraform import kubernetes_config_map.aws_auth kube-system/aws-auth
EKS 클러스터 생성 후 사용자 역할을 추가하기 위해 aws-auth configmap를 Terraform resource로 관리하게 되었다. 참고
resource "kubernetes_config_map" "aws_auth" {
data = yamldecode(local.eks_prod_aws_auth_configmap_yaml)["data"]
metadata {
name = "aws-auth"
namespace = "kube-system"
}
}
aws-auth configmap의 경우 EKS 클러스터가 만들어질 때 자동으로 클러스터 생성자의 IAM Role이 systemr:masters 그룹에 추가되게 된다.
따라서 무작정 terraform apply를 하게 되면 configmaps "aws-auth" already exists 같은 에러 로그를 확인할 수 있다.
이 때, 가능한 해결책이다.
먼저, terraform import로 기생성된 resource를 terraform state file로 Import 해온다.
terraform import kubernetes_config_map.aws_auth kube-system/aws-auth
만약 이 때, 아래와 같은 에러가 발생한다면
Error: Invalid provider configuration
│
│ on /Users/ohyeseong/Desktop/ridi/terraform/ridi-prod-data-kubernetes/main.tf line 28:
│ 28: provider "kubernetes" {
│
│ The configuration for provider["registry.terraform.io/hashicorp/kubernetes"] depends on values that cannot be determined until apply.
terraform plan을 한번 실행해준다.
이후 다시 terraform import를 실행하게 되면 성공적으로 완료되는 것을 확인할 수 있다.
Acquiring state lock. This may take a few moments...
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
반응형