Skip to content

Commit

Permalink
Merge pull request #4 from zachrundle/eks
Browse files Browse the repository at this point in the history
start eks module and fix tf fmt checker
  • Loading branch information
zachrundle committed Aug 16, 2024
2 parents 2b53346 + 57452d1 commit 561ed82
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tf-fmt-check.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: tfactions
name: tf-fmt-check
on:
push:
branches:
- main
pull_request:
jobs:
tfactions:
name: tfactions
name: tf-fmt-check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -18,4 +18,4 @@ jobs:

- name: Terraform fmt
id: fmt
run: terraform fmt -check
run: terraform fmt -check
74 changes: 73 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,76 @@ module "network" {
name = var.name
create_ngw = false
vpc_cidr = "10.0.0.0/16"
}
}
module "eks" {
source = "./modules/eks"
create_eks = false
cluster_name = "${var.name}-cluster"
cluster_version = "1.30"

subnet_ids = module.network.private_subnet_ids
control_plane_subnet_ids = module.network.private_subnet_ids
}


# module "eks" {
# source = "terraform-aws-modules/eks/aws"
# version = "~> 20.0"

# cluster_name = "${var.name}-cluster"
# cluster_version = "1.30"

# cluster_endpoint_public_access = true

# cluster_addons = {
# coredns = {}
# eks-pod-identity-agent = {}
# kube-proxy = {}
# vpc-cni = {}
# }

# vpc_id = module.network.vpc
# subnet_ids = module.network.private_subnet_ids
# control_plane_subnet_ids = module.network.private_subnet_ids

# # EKS Managed Node Group(s)
# eks_managed_node_group_defaults = {
# instance_types = ["m6i.large", "m5.large", "m5n.large", "m5zn.large"]
# }

# eks_managed_node_groups = {
# example = {
# # Starting on 1.30, AL2023 is the default AMI type for EKS managed node groups
# ami_type = "AL2023_x86_64_STANDARD"
# instance_types = ["m5.xlarge"]

# min_size = 1
# max_size = 10
# desired_size = 1
# }
# }

# # Cluster access entry
# # To add the current caller identity as an administrator
# enable_cluster_creator_admin_permissions = true

# access_entries = {
# # One access entry with a policy associated
# example = {
# policy_associations = {
# example = {
# policy_arn = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy"
# access_scope = {
# namespaces = ["default"]
# type = "namespace"
# }
# }
# }
# }
# }

# tags = {
# Environment = "dev"
# Terraform = "true"
# }
# }
29 changes: 29 additions & 0 deletions modules/eks/eks_roles.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"

principals {
type = "Service"
identifiers = ["eks.amazonaws.com"]
}

actions = ["sts:AssumeRole"]
}
}

resource "aws_iam_role" "example" {
name = "eks-cluster-example"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

resource "aws_iam_role_policy_attachment" "example-AmazonEKSClusterPolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.example.name
}

# Optionally, enable Security Groups for Pods
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html
resource "aws_iam_role_policy_attachment" "example-AmazonEKSVPCResourceController" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.example.name
}
18 changes: 18 additions & 0 deletions modules/eks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_eks_cluster" "this" {
name = var.cluster_name
role_arn = aws_iam_role.example.arn
count = var.create_eks ? 1 : 0
version = var.cluster_version

vpc_config {
subnet_ids = coalescelist(var.control_plane_subnet_ids, var.subnet_ids)
}

# Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
# Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
depends_on = [
aws_iam_role_policy_attachment.example-AmazonEKSClusterPolicy,
aws_iam_role_policy_attachment.example-AmazonEKSVPCResourceController,
]
}

7 changes: 7 additions & 0 deletions modules/eks/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# output "endpoint" {
# value = aws_eks_cluster.this.endpoint
# }

# output "kubeconfig-certificate-authority-data" {
# value = aws_eks_cluster.this.certificate_authority[0].data
# }
84 changes: 84 additions & 0 deletions modules/eks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
variable "create_eks" {
type = bool
default = false
}

variable "cluster_name" {
description = "Name of the EKS cluster"
type = string
default = ""
}

variable "cluster_version" {
description = "Kubernetes `<major>.<minor>` version to use for the EKS cluster (i.e.: `1.27`)"
type = string
default = null
}

# variable "authentication_mode" {
# description = "The authentication mode for the cluster. Valid values are `CONFIG_MAP`, `API` or `API_AND_CONFIG_MAP`"
# type = string
# default = "API_AND_CONFIG_MAP"
# }

variable "control_plane_subnet_ids" {
description = "A list of subnet IDs where the EKS cluster control plane (ENIs) will be provisioned. Used for expanding the pool of subnets used by nodes/node groups without replacing the EKS control plane"
type = list(string)
default = []
}

variable "subnet_ids" {
description = "A list of subnet IDs where the nodes/node groups will be provisioned. If `control_plane_subnet_ids` is not provided, the EKS cluster control plane (ENIs) will be provisioned in these subnets"
type = list(string)
default = []
}

# variable "cluster_endpoint_private_access" {
# description = "Indicates whether or not the Amazon EKS private API server endpoint is enabled"
# type = bool
# default = true
# }

# variable "cluster_endpoint_public_access" {
# description = "Indicates whether or not the Amazon EKS public API server endpoint is enabled"
# type = bool
# default = false
# }

# variable "cluster_endpoint_public_access_cidrs" {
# description = "List of CIDR blocks which can access the Amazon EKS public API server endpoint"
# type = list(string)
# default = ["0.0.0.0/0"]
# }

# variable "cluster_encryption_config" {
# description = "Configuration block with encryption configuration for the cluster. To disable secret encryption, set this value to `{}`"
# type = any
# default = {
# resources = ["secrets"]
# }
# }

# variable "attach_cluster_encryption_policy" {
# description = "Indicates whether or not to attach an additional policy for the cluster IAM role to utilize the encryption key provided"
# type = bool
# default = true
# }

# variable "cluster_tags" {
# description = "A map of additional tags to add to the cluster"
# type = map(string)
# default = {}
# }

# variable "create_cluster_primary_security_group_tags" {
# description = "Indicates whether or not to tag the cluster's primary security group. This security group is created by the EKS service, not the module, and therefore tagging is handled after cluster creation"
# type = bool
# default = true
# }

# variable "enable_cluster_creator_admin_permissions" {
# description = "Indicates whether or not to add the cluster creator (the identity used by Terraform) as an administrator via access entry"
# type = bool
# default = true
# }
6 changes: 5 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ output "public_subnets" {

output "private_subnets" {
value = module.network.private_subnet_cidr_block
}
}

# output "eks_endpoint" {
# value = module.eks.endpoint
# }
5 changes: 3 additions & 2 deletions terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
name = "playground"
region = "us-west-2"
name = "playground"
region = "us-west-2"
create_eks = true
6 changes: 5 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ variable "region" {

variable "aws_account" {
description = "Account number to create aws resources in. This variable should be defined in the terraform cloud workspace settings"
}
}

variable "create_eks" {
default = false
}

0 comments on commit 561ed82

Please sign in to comment.