mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-01-18 17:47:31 +01:00
Better examples, PR template changes, general tidy up (#375)
* adding 3 examples * removing old example * updating PR template * fix this typo * update after renaming default example * add missing launch_template_mixed stuff to aws_auth * fix 2 examples with public subnets * update changelog for new minor release
This commit is contained in:
135
examples/basic/main.tf
Normal file
135
examples/basic/main.tf
Normal file
@@ -0,0 +1,135 @@
|
||||
terraform {
|
||||
required_version = ">= 0.11.8"
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
version = ">= 2.6.0"
|
||||
region = "${var.region}"
|
||||
}
|
||||
|
||||
provider "random" {
|
||||
version = "= 1.3.1"
|
||||
}
|
||||
|
||||
data "aws_availability_zones" "available" {}
|
||||
|
||||
locals {
|
||||
cluster_name = "test-eks-${random_string.suffix.result}"
|
||||
}
|
||||
|
||||
resource "random_string" "suffix" {
|
||||
length = 8
|
||||
special = false
|
||||
}
|
||||
|
||||
resource "aws_security_group" "worker_group_mgmt_one" {
|
||||
name_prefix = "worker_group_mgmt_one"
|
||||
vpc_id = "${module.vpc.vpc_id}"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"10.0.0.0/8",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "worker_group_mgmt_two" {
|
||||
name_prefix = "worker_group_mgmt_two"
|
||||
vpc_id = "${module.vpc.vpc_id}"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"192.168.0.0/16",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "all_worker_mgmt" {
|
||||
name_prefix = "all_worker_management"
|
||||
vpc_id = "${module.vpc.vpc_id}"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
|
||||
cidr_blocks = [
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"192.168.0.0/16",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module "vpc" {
|
||||
source = "terraform-aws-modules/vpc/aws"
|
||||
version = "1.60.0"
|
||||
name = "test-vpc"
|
||||
cidr = "10.0.0.0/16"
|
||||
azs = ["${data.aws_availability_zones.available.names}"]
|
||||
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
|
||||
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
|
||||
enable_nat_gateway = true
|
||||
single_nat_gateway = true
|
||||
|
||||
tags = {
|
||||
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
|
||||
}
|
||||
|
||||
public_subnet_tags = {
|
||||
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
|
||||
}
|
||||
|
||||
private_subnet_tags = {
|
||||
"kubernetes.io/cluster/${local.cluster_name}" = "shared"
|
||||
"kubernetes.io/role/internal-elb" = "true"
|
||||
}
|
||||
}
|
||||
|
||||
module "eks" {
|
||||
source = "../.."
|
||||
cluster_name = "${local.cluster_name}"
|
||||
subnets = ["${module.vpc.private_subnets}"]
|
||||
|
||||
tags = {
|
||||
Environment = "test"
|
||||
GithubRepo = "terraform-aws-eks"
|
||||
GithubOrg = "terraform-aws-modules"
|
||||
}
|
||||
|
||||
vpc_id = "${module.vpc.vpc_id}"
|
||||
worker_group_count = 2
|
||||
|
||||
worker_groups = [
|
||||
{
|
||||
name = "worker-group-1"
|
||||
instance_type = "t2.small"
|
||||
additional_userdata = "echo foo bar"
|
||||
asg_desired_capacity = 2
|
||||
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_one.id}"
|
||||
},
|
||||
{
|
||||
name = "worker-group-2"
|
||||
instance_type = "t2.medium"
|
||||
additional_userdata = "echo foo bar"
|
||||
additional_security_group_ids = "${aws_security_group.worker_group_mgmt_two.id}"
|
||||
asg_desired_capacity = 1
|
||||
},
|
||||
]
|
||||
|
||||
worker_additional_security_group_ids = ["${aws_security_group.all_worker_mgmt.id}"]
|
||||
map_roles = "${var.map_roles}"
|
||||
map_roles_count = "${var.map_roles_count}"
|
||||
map_users = "${var.map_users}"
|
||||
map_users_count = "${var.map_users_count}"
|
||||
map_accounts = "${var.map_accounts}"
|
||||
map_accounts_count = "${var.map_accounts_count}"
|
||||
}
|
||||
24
examples/basic/outputs.tf
Normal file
24
examples/basic/outputs.tf
Normal file
@@ -0,0 +1,24 @@
|
||||
output "cluster_endpoint" {
|
||||
description = "Endpoint for EKS control plane."
|
||||
value = "${module.eks.cluster_endpoint}"
|
||||
}
|
||||
|
||||
output "cluster_security_group_id" {
|
||||
description = "Security group ids attached to the cluster control plane."
|
||||
value = "${module.eks.cluster_security_group_id}"
|
||||
}
|
||||
|
||||
output "kubectl_config" {
|
||||
description = "kubectl config as generated by the module."
|
||||
value = "${module.eks.kubeconfig}"
|
||||
}
|
||||
|
||||
output "config_map_aws_auth" {
|
||||
description = "A kubernetes configuration to authenticate to this EKS cluster."
|
||||
value = "${module.eks.config_map_aws_auth}"
|
||||
}
|
||||
|
||||
output "region" {
|
||||
description = "AWS region."
|
||||
value = "${var.region}"
|
||||
}
|
||||
62
examples/basic/variables.tf
Normal file
62
examples/basic/variables.tf
Normal file
@@ -0,0 +1,62 @@
|
||||
variable "region" {
|
||||
default = "us-west-2"
|
||||
}
|
||||
|
||||
variable "map_accounts" {
|
||||
description = "Additional AWS account numbers to add to the aws-auth configmap."
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
"777777777777",
|
||||
"888888888888",
|
||||
]
|
||||
}
|
||||
|
||||
variable "map_accounts_count" {
|
||||
description = "The count of accounts in the map_accounts list."
|
||||
type = "string"
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "map_roles" {
|
||||
description = "Additional IAM roles to add to the aws-auth configmap."
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
{
|
||||
role_arn = "arn:aws:iam::66666666666:role/role1"
|
||||
username = "role1"
|
||||
group = "system:masters"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
variable "map_roles_count" {
|
||||
description = "The count of roles in the map_roles list."
|
||||
type = "string"
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "map_users" {
|
||||
description = "Additional IAM users to add to the aws-auth configmap."
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
{
|
||||
user_arn = "arn:aws:iam::66666666666:user/user1"
|
||||
username = "user1"
|
||||
group = "system:masters"
|
||||
},
|
||||
{
|
||||
user_arn = "arn:aws:iam::66666666666:user/user2"
|
||||
username = "user2"
|
||||
group = "system:masters"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
variable "map_users_count" {
|
||||
description = "The count of roles in the map_users list."
|
||||
type = "string"
|
||||
default = 2
|
||||
}
|
||||
Reference in New Issue
Block a user