Skip to content

Commit

Permalink
Merge pull request #34 from WesleyCharlesBlake/ops/ec2-key
Browse files Browse the repository at this point in the history
adds ec2 key pair creation
  • Loading branch information
WesleyCharlesBlake authored Sep 24, 2019
2 parents b4d009d + 7e91cf3 commit f7313cc
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 58 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# terraform-aws-eks

[![CircleCI](https://circleci.com/gh/WesleyCharlesBlake/terraform-aws-eks.svg?style=svg)](https://circleci.com/gh/WesleyCharlesBlake/terraform-aws-eks)
[![TerraformRefigistry](https://img.shields.io/badge/Terraform%20Registry-v2.0.2-blue.svg)](https://registry.terraform.io/modules/WesleyCharlesBlake/eks/aws/)
[![TerraformRefigistry](https://img.shields.io/badge/Terraform%20Registry-version_2-blue.svg)](https://registry.terraform.io/modules/WesleyCharlesBlake/eks/aws/)


Deploy a full AWS EKS cluster with Terraform
Expand All @@ -24,26 +24,26 @@ Deploy a full AWS EKS cluster with Terraform

You can configure you config with the following input variables:

| Name | Description | Default |
| ------------------------- | ---------------------------------- | --------------------------------------------------------------------- |
| `cluster-name` | The name of your EKS Cluster | `eks-cluster` |
| `aws-region` | The AWS Region to deploy EKS | `us-east-1` |
| `availability-zones` | AWS Availability Zones | `["us-east-1a", "us-east-1b", "us-east-1c"]` |
| `k8s-version` | The desired K8s version to launch | `1.13` |
| `node-instance-type` | Worker Node EC2 instance type | `m4.large` |
| `root-block-size` | Size of the root EBS block device | `20` |
| `desired-capacity` | Autoscaling Desired node capacity | `2` |
| `max-size` | Autoscaling Maximum node capacity | `5` |
| `min-size` | Autoscaling Minimum node capacity | `1` |
| `public-min-size` | Public Node groups ASG capacity | `1` |
| `public-max-size` | Public Node groups ASG capacity | `1` |
| `public-desired-capacity` | Public Node groups ASG capacity | `1` |
| `vpc-subnet-cidr` | Subnet CIDR | `10.0.0.0/16` |
| `private-subnet-cidr` | Private Subnet CIDR | `["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19"]` |
| `public-subnet-cidr` | Public Subnet CIDR | `["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20"]` |
| `db-subnet-cidr` | DB/Spare Subnet CIDR | `["10.0.192.0/21", "10.0.200.0/21", "10.0.208.0/21"]` |
| `eks-cw-logging` | EKS Logging Components | `["api", "audit", "authenticator", "controllerManager", "scheduler"]` |
| `ec2-key` | EC2 Key Pair for bastion and nodes | `my-key` |
| Name | Description | Default |
| ------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cluster-name` | The name of your EKS Cluster | `eks-cluster` |
| `aws-region` | The AWS Region to deploy EKS | `us-east-1` |
| `availability-zones` | AWS Availability Zones | `["us-east-1a", "us-east-1b", "us-east-1c"]` |
| `k8s-version` | The desired K8s version to launch | `1.13` |
| `node-instance-type` | Worker Node EC2 instance type | `m4.large` |
| `root-block-size` | Size of the root EBS block device | `20` |
| `desired-capacity` | Autoscaling Desired node capacity | `2` |
| `max-size` | Autoscaling Maximum node capacity | `5` |
| `min-size` | Autoscaling Minimum node capacity | `1` |
| `public-min-size` | Public Node groups ASG capacity | `1` |
| `public-max-size` | Public Node groups ASG capacity | `1` |
| `public-desired-capacity` | Public Node groups ASG capacity | `1` |
| `vpc-subnet-cidr` | Subnet CIDR | `10.0.0.0/16` |
| `private-subnet-cidr` | Private Subnet CIDR | `["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19"]` |
| `public-subnet-cidr` | Public Subnet CIDR | `["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20"]` |
| `db-subnet-cidr` | DB/Spare Subnet CIDR | `["10.0.192.0/21", "10.0.200.0/21", "10.0.208.0/21"]` |
| `eks-cw-logging` | EKS Logging Components | `["api", "audit", "authenticator", "controllerManager", "scheduler"]` |
| `ec2-key-public-key` | EC2 Key Pair for bastion and nodes | `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]` |

> You can create a file called terraform.tfvars or copy [variables.tf](https://github.com/WesleyCharlesBlake/terraform-aws-eks/blob/master/variables.tf) into the project root, if you would like to over-ride the defaults.
Expand Down Expand Up @@ -82,7 +82,7 @@ module "eks" {
public-subnet-cidr = ["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20"]
db-subnet-cidr = ["10.0.192.0/21", "10.0.200.0/21", "10.0.208.0/21"]
eks-cw-logging = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
ec2-key = "my-key"
ec2-key-public-key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"
}
output "kubeconfig" {
Expand Down Expand Up @@ -118,7 +118,7 @@ module "eks" {
public-subnet-cidr = var.public-subnet-cidr
db-subnet-cidr = var.db-subnet-cidr
eks-cw-logging = var.eks-cw-logging
ec2-key = var.ec2-key
ec2-key-public-key = var.ec2-key
}
```

Expand Down
35 changes: 19 additions & 16 deletions examples/complete-cluster.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### VPC

# use terraform cloud remote backend
# use terraform cloud remote backend OR you can use your prefered remote backend

terraform {
backend "remote" {
Expand All @@ -13,22 +13,25 @@ terraform {


module "eks" {
source = "../modules/eks"
source = "../modules/eks"

aws-region = "us-east-1"
availability-zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
cluster-name = "my-cluster"
k8s-version = "1.13"
node-instance-type = "t3.medium"
desired-capacity = "3"
max-size = "5"
min-size = "1"
vpc-subnet-cidr = "10.0.0.0/16"
private-subnet-cidr = ["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19"]
public-subnet-cidr = ["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20"]
db-subnet-cidr = ["10.0.192.0/21", "10.0.200.0/21", "10.0.208.0/21"]
eks-cw-logging = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
ec2-key = "my-key"
aws-region = "us-east-1"
availability-zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
cluster-name = "my-cluster"
k8s-version = "1.13"
node-instance-type = "t3.medium"
desired-capacity = 3
max-size = 5
min-size = 1
public-min-size = 1
public-max-size = 5
public-desired-capacity = 3
vpc-subnet-cidr = "10.0.0.0/16"
private-subnet-cidr = ["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19"]
public-subnet-cidr = ["10.0.128.0/20", "10.0.144.0/20", "10.0.160.0/20"]
db-subnet-cidr = ["10.0.192.0/21", "10.0.200.0/21", "10.0.208.0/21"]
eks-cw-logging = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
ec2-key-public-key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"
}

output "kubeconfig" {
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module "eks" {
public-subnet-cidr = var.public-subnet-cidr
db-subnet-cidr = var.db-subnet-cidr
eks-cw-logging = var.eks-cw-logging
ec2-key = var.ec2-key
ec2-key-public-key = var.ec2-key-public-key

}

4 changes: 1 addition & 3 deletions modules/eks/bastion.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
### bastion

variable "ec2-key" {}

### bastion hosts
module "bastion-asg" {
source = "terraform-aws-modules/autoscaling/aws"
Expand Down Expand Up @@ -32,7 +30,7 @@ module "bastion-asg" {
max_size = 1
desired_capacity = 1
wait_for_capacity_timeout = 0
key_name = var.ec2-key
key_name = aws_key_pair.deployer.key_name

tags = [
{
Expand Down
6 changes: 6 additions & 0 deletions modules/eks/ec2-key.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
variable "ec2-key-public-key" {}

resource "aws_key_pair" "deployer" {
key_name = var.cluster-name
public_key = var.ec2-key-public-key
}
2 changes: 1 addition & 1 deletion modules/eks/eks-worker-nodes-public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module "public-eks-nodes-asg" {
desired_capacity = var.public-desired-capacity
wait_for_capacity_timeout = 0

key_name = var.ec2-key
key_name = aws_key_pair.deployer.key_name

iam_instance_profile = "${aws_iam_instance_profile.node.name}"
user_data = local.eks-public-node-userdata
Expand Down
2 changes: 1 addition & 1 deletion modules/eks/eks-worker-nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module "eks-nodes-asg" {
desired_capacity = var.desired-capacity
wait_for_capacity_timeout = 0

key_name = var.ec2-key
key_name = aws_key_pair.deployer.key_name

iam_instance_profile = "${aws_iam_instance_profile.node.name}"
user_data = local.eks-node-userdata
Expand Down
7 changes: 0 additions & 7 deletions modules/locals.tf

This file was deleted.

Binary file removed terraform
Binary file not shown.
12 changes: 6 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ variable "min-size" {
variable "public-min-size" {
default = 1
type = string
description = "Public Node groups ASG capacity"
description = "Public Node groups min ASG capacity"
}

variable "public-max-size" {
default = 1
type = string
description = "Public Node groups ASG capacity"
description = "Public Node groups max ASG capacity"
}

variable "public-desired-capacity" {
default = 1
type = string
description = "Public Node groups ASG capacity"
description = "Public Node groups desired ASG capacity"
}

variable "ec2-key" {
default = "my-key"
variable "ec2-key-public-key" {
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]"
type = string
description = "Autoscaling Minimum node capacity"
description = "AWS EC2 public key data"
}

0 comments on commit f7313cc

Please sign in to comment.