To create an AWS EKS service using a local AWS IAM role in Terraform, you can follow the steps below:

  1. Create an IAM role using Terraform:
resource "aws_iam_role" "eks_role" {
  name = "eks_role"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Effect = "Allow"
        Principal = {
          Service = "eks.amazonaws.com"
        }
        Action = "sts:AssumeRole"
      }
    ]
  })
}
  1. Attach the necessary policies to the IAM role:
resource "aws_iam_role_policy_attachment" "eks_role_policy_attachment" {
  policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
  role       = aws_iam_role.eks_role.name
}

resource "aws_iam_role_policy_attachment" "eks_role_policy_attachment_2" {
  policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
  role       = aws_iam_role.eks_role.name
}
  1. Create an EKS cluster using the IAM role:
resource "aws_eks_cluster" "eks_cluster" {
  name     = "eks_cluster"
  role_arn = aws_iam_role.eks_role.arn
  vpc_config {
    subnet_ids = ["subnet-xxxxxxxxx", "subnet-yyyyyyyyy", "subnet-zzzzzzzzz"]
  }
}
  1. Create an EKS node group using the IAM role:
resource "aws_eks_node_group" "eks_node_group" {
  cluster_name    = aws_eks_cluster.eks_cluster.name
  node_group_name = "eks_node_group"
  node_role_arn   = aws_iam_role.eks_role.arn
  subnet_ids      = ["subnet-xxxxxxxxx", "subnet-yyyyyyyyy", "subnet-zzzzzzzzz"]
}

Note: Replace the subnet IDs and policy ARNs with your own values. Also, make sure that you have the required permissions to create IAM roles, policies, EKS clusters, and node groups in AWS

terrafrom create service aws eks using local aws_iam_role

原文地址: https://www.cveoy.top/t/topic/cdn7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录