mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-04-10 19:16:50 +02:00
docs: Move examples that are more like test cases to the new tests/ directory; add better example configurations (#3069)
* chore: Move examples that are more like test cases to the new `tests/` directory * chore: Stash * feat: Add better examples for EKS managed node groups * chore: Add better examples for self-managed node groups * chore: Update docs and correct `nodegroup` to `node group`
This commit is contained in:
161
tests/fargate-profile/main.tf
Normal file
161
tests/fargate-profile/main.tf
Normal file
@@ -0,0 +1,161 @@
|
||||
provider "aws" {
|
||||
region = local.region
|
||||
}
|
||||
|
||||
data "aws_availability_zones" "available" {}
|
||||
|
||||
locals {
|
||||
name = "ex-${basename(path.cwd)}"
|
||||
cluster_version = "1.30"
|
||||
region = "eu-west-1"
|
||||
|
||||
vpc_cidr = "10.0.0.0/16"
|
||||
azs = slice(data.aws_availability_zones.available.names, 0, 3)
|
||||
|
||||
tags = {
|
||||
Test = local.name
|
||||
GithubRepo = "terraform-aws-eks"
|
||||
GithubOrg = "terraform-aws-modules"
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# EKS Module
|
||||
################################################################################
|
||||
|
||||
module "eks" {
|
||||
source = "../.."
|
||||
|
||||
cluster_name = local.name
|
||||
cluster_version = local.cluster_version
|
||||
cluster_endpoint_public_access = true
|
||||
|
||||
cluster_addons = {
|
||||
kube-proxy = {}
|
||||
vpc-cni = {}
|
||||
coredns = {
|
||||
configuration_values = jsonencode({
|
||||
computeType = "fargate"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
vpc_id = module.vpc.vpc_id
|
||||
subnet_ids = module.vpc.private_subnets
|
||||
control_plane_subnet_ids = module.vpc.intra_subnets
|
||||
|
||||
# Fargate profiles use the cluster primary security group so these are not utilized
|
||||
create_cluster_security_group = false
|
||||
create_node_security_group = false
|
||||
|
||||
fargate_profile_defaults = {
|
||||
iam_role_additional_policies = {
|
||||
additional = aws_iam_policy.additional.arn
|
||||
}
|
||||
}
|
||||
|
||||
fargate_profiles = {
|
||||
example = {
|
||||
name = "example"
|
||||
selectors = [
|
||||
{
|
||||
namespace = "backend"
|
||||
labels = {
|
||||
Application = "backend"
|
||||
}
|
||||
},
|
||||
{
|
||||
namespace = "app-*"
|
||||
labels = {
|
||||
Application = "app-wildcard"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
# Using specific subnets instead of the subnets supplied for the cluster itself
|
||||
subnet_ids = [module.vpc.private_subnets[1]]
|
||||
|
||||
tags = {
|
||||
Owner = "secondary"
|
||||
}
|
||||
}
|
||||
kube-system = {
|
||||
selectors = [
|
||||
{ namespace = "kube-system" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
tags = local.tags
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Sub-Module Usage on Existing/Separate Cluster
|
||||
################################################################################
|
||||
|
||||
module "fargate_profile" {
|
||||
source = "../../modules/fargate-profile"
|
||||
|
||||
name = "separate-fargate-profile"
|
||||
cluster_name = module.eks.cluster_name
|
||||
|
||||
subnet_ids = module.vpc.private_subnets
|
||||
selectors = [{
|
||||
namespace = "kube-system"
|
||||
}]
|
||||
|
||||
tags = merge(local.tags, { Separate = "fargate-profile" })
|
||||
}
|
||||
|
||||
module "disabled_fargate_profile" {
|
||||
source = "../../modules/fargate-profile"
|
||||
|
||||
create = false
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Supporting Resources
|
||||
################################################################################
|
||||
|
||||
module "vpc" {
|
||||
source = "terraform-aws-modules/vpc/aws"
|
||||
version = "~> 5.0"
|
||||
|
||||
name = local.name
|
||||
cidr = local.vpc_cidr
|
||||
|
||||
azs = local.azs
|
||||
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
|
||||
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
|
||||
intra_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 52)]
|
||||
|
||||
enable_nat_gateway = true
|
||||
single_nat_gateway = true
|
||||
|
||||
public_subnet_tags = {
|
||||
"kubernetes.io/role/elb" = 1
|
||||
}
|
||||
|
||||
private_subnet_tags = {
|
||||
"kubernetes.io/role/internal-elb" = 1
|
||||
}
|
||||
|
||||
tags = local.tags
|
||||
}
|
||||
|
||||
resource "aws_iam_policy" "additional" {
|
||||
name = "${local.name}-additional"
|
||||
|
||||
policy = jsonencode({
|
||||
Version = "2012-10-17"
|
||||
Statement = [
|
||||
{
|
||||
Action = [
|
||||
"ec2:Describe*",
|
||||
]
|
||||
Effect = "Allow"
|
||||
Resource = "*"
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user