mirror of
https://github.com/terraform-aws-modules/terraform-aws-eks.git
synced 2025-09-09 19:32:58 +08:00
refactor: Refactoring to match the rest of terraform-aws-modules (#1583)
This commit is contained in:
@@ -1,7 +1,71 @@
|
||||
# AWS Bottlerocket based nodes
|
||||
# AWS EKS cluster running Bottlerocket AMI
|
||||
|
||||
This is a minimalistic example that shows how to use functionality of this module to deploy
|
||||
nodes based on [AWS Bottlerocket container OS](https://github.com/bottlerocket-os/bottlerocket)
|
||||
Configuration in this directory creates EKS cluster with nodes running [AWS Bottlerocket OS](https://github.com/bottlerocket-os/bottlerocket)
|
||||
|
||||
Example is minimalistic by purpose - it shows what knobs to turn to make Bottlerocket work.
|
||||
Do not use default VPC for your workloads deployment.
|
||||
This is a minimalistic example which shows what knobs to turn to make Bottlerocket work.
|
||||
|
||||
See [the official documentation](https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami-bottlerocket.html) for more details.
|
||||
|
||||
## Usage
|
||||
|
||||
To run this example you need to execute:
|
||||
|
||||
```bash
|
||||
$ terraform init
|
||||
$ terraform plan
|
||||
$ terraform apply
|
||||
```
|
||||
|
||||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
|
||||
|
||||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
|
||||
## Requirements
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
|
||||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.22.0 |
|
||||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |
|
||||
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 2.0 |
|
||||
|
||||
## Providers
|
||||
|
||||
| Name | Version |
|
||||
|------|---------|
|
||||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.22.0 |
|
||||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |
|
||||
| <a name="provider_tls"></a> [tls](#provider\_tls) | >= 2.0 |
|
||||
|
||||
## Modules
|
||||
|
||||
| Name | Source | Version |
|
||||
|------|--------|---------|
|
||||
| <a name="module_eks"></a> [eks](#module\_eks) | ../.. | |
|
||||
|
||||
## Resources
|
||||
|
||||
| Name | Type |
|
||||
|------|------|
|
||||
| [aws_iam_role_policy_attachment.ssm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
|
||||
| [aws_key_pair.nodes](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair) | resource |
|
||||
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
|
||||
| [tls_private_key.nodes](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
|
||||
| [aws_ami.bottlerocket_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
|
||||
| [aws_subnet_ids.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
|
||||
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
|
||||
|
||||
## Inputs
|
||||
|
||||
No inputs.
|
||||
|
||||
## Outputs
|
||||
|
||||
| Name | Description |
|
||||
|------|-------------|
|
||||
| <a name="output_cluster_endpoint"></a> [cluster\_endpoint](#output\_cluster\_endpoint) | Endpoint for EKS control plane. |
|
||||
| <a name="output_cluster_security_group_id"></a> [cluster\_security\_group\_id](#output\_cluster\_security\_group\_id) | Security group ids attached to the cluster control plane. |
|
||||
| <a name="output_config_map_aws_auth"></a> [config\_map\_aws\_auth](#output\_config\_map\_aws\_auth) | A kubernetes configuration to authenticate to this EKS cluster. |
|
||||
| <a name="output_kubectl_config"></a> [kubectl\_config](#output\_kubectl\_config) | kubectl config as generated by the module. |
|
||||
| <a name="output_node_groups"></a> [node\_groups](#output\_node\_groups) | Outputs from node groups |
|
||||
| <a name="output_region"></a> [region](#output\_region) | AWS region. |
|
||||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
data "aws_ami" "bottlerocket_ami" {
|
||||
most_recent = true
|
||||
owners = ["amazon"]
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["bottlerocket-aws-k8s-${var.k8s_version}-x86_64-*"]
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_region" "current" {}
|
||||
|
||||
data "aws_vpc" "default" {
|
||||
default = true
|
||||
}
|
||||
|
||||
data "aws_subnet_ids" "default" {
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
}
|
||||
|
||||
data "aws_iam_policy" "ssm" {
|
||||
arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
output "region" {
|
||||
description = "AWS region."
|
||||
value = local.region
|
||||
}
|
||||
|
||||
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 "node_groups" {
|
||||
description = "Outputs from node groups"
|
||||
value = module.eks.node_groups
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
variable "k8s_version" {
|
||||
description = "k8s cluster version"
|
||||
default = "1.20"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "enable_admin_container" {
|
||||
description = "Enable/disable admin container"
|
||||
default = false
|
||||
type = bool
|
||||
}
|
||||
|
||||
variable "enable_control_container" {
|
||||
description = "Enable/disable control container"
|
||||
default = true
|
||||
type = bool
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13.1"
|
||||
|
||||
required_providers {
|
||||
aws = ">= 3.22.0"
|
||||
random = ">= 2.1"
|
||||
tls = ">= 2.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user