mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-03-17 23:13:46 +01:00
refactor: Refactoring to match the rest of terraform-aws-modules (#1583)
This commit is contained in:
@@ -1,31 +1,27 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13.0"
|
||||
provider "aws" {
|
||||
region = local.region
|
||||
}
|
||||
|
||||
resource "tls_private_key" "nodes" {
|
||||
algorithm = "RSA"
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "nodes" {
|
||||
key_name = "bottlerocket-nodes"
|
||||
public_key = tls_private_key.nodes.public_key_openssh
|
||||
locals {
|
||||
region = "eu-west-1"
|
||||
k8s_version = "1.21"
|
||||
}
|
||||
|
||||
module "eks" {
|
||||
source = "../.."
|
||||
cluster_name = "bottlerocket"
|
||||
cluster_version = var.k8s_version
|
||||
subnets = data.aws_subnet_ids.default.ids
|
||||
source = "../.."
|
||||
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
cluster_name = "bottlerocket-${random_string.suffix.result}"
|
||||
cluster_version = local.k8s_version
|
||||
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
subnets = data.aws_subnet_ids.default.ids
|
||||
|
||||
write_kubeconfig = false
|
||||
manage_aws_auth = false
|
||||
|
||||
worker_groups_launch_template = [
|
||||
{
|
||||
name = "bottlerocket-nodes"
|
||||
# passing bottlerocket ami id
|
||||
name = "bottlerocket-nodes"
|
||||
ami_id = data.aws_ami.bottlerocket_ami.id
|
||||
instance_type = "t3a.small"
|
||||
asg_desired_capacity = 2
|
||||
@@ -42,9 +38,9 @@ module "eks" {
|
||||
# we are using this section to pass additional arguments for
|
||||
# userdata template rendering
|
||||
userdata_template_extra_args = {
|
||||
enable_admin_container = var.enable_admin_container
|
||||
enable_control_container = var.enable_control_container
|
||||
aws_region = data.aws_region.current.name
|
||||
enable_admin_container = false
|
||||
enable_control_container = true
|
||||
aws_region = local.region
|
||||
}
|
||||
# example of k8s/kubelet configuration via additional_userdata
|
||||
additional_userdata = <<EOT
|
||||
@@ -59,5 +55,41 @@ EOT
|
||||
# https://github.com/bottlerocket-os/bottlerocket/blob/develop/QUICKSTART-EKS.md#enabling-ssm
|
||||
resource "aws_iam_role_policy_attachment" "ssm" {
|
||||
role = module.eks.worker_iam_role_name
|
||||
policy_arn = data.aws_iam_policy.ssm.arn
|
||||
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Supporting Resources
|
||||
################################################################################
|
||||
|
||||
data "aws_vpc" "default" {
|
||||
default = true
|
||||
}
|
||||
|
||||
data "aws_subnet_ids" "default" {
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
}
|
||||
|
||||
data "aws_ami" "bottlerocket_ami" {
|
||||
most_recent = true
|
||||
owners = ["amazon"]
|
||||
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["bottlerocket-aws-k8s-${local.k8s_version}-x86_64-*"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_string" "suffix" {
|
||||
length = 8
|
||||
special = false
|
||||
}
|
||||
|
||||
resource "tls_private_key" "nodes" {
|
||||
algorithm = "RSA"
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "nodes" {
|
||||
key_name = "bottlerocket-nodes-${random_string.suffix.result}"
|
||||
public_key = tls_private_key.nodes.public_key_openssh
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user