-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8d8485
commit 9588a14
Showing
8 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#Makefile | ||
|
||
.PHONY: all | ||
|
||
all: init plan build | ||
|
||
init: | ||
rm -rf .terraform/modules/ | ||
terraform init -reconfigure | ||
|
||
plan: init | ||
terraform plan -refresh=true | ||
|
||
build: init | ||
terraform apply -auto-approve | ||
|
||
check: init | ||
terraform plan -detailed-exitcode | ||
|
||
destroy: init | ||
terraform destroy -force | ||
|
||
docs: | ||
terraform-docs md . > README.md | ||
|
||
valid: | ||
tflint | ||
terraform fmt -check=true -diff=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
# Platform Engineering Exercise | ||
|
||
## Overview | ||
|
||
This repository contains the code for the Platform Engineering Exercise. The exercise is to create a Kubernetes cluster in AWS using Terraform. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- [Terraform](https://www.terraform.io/downloads.html) | ||
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) | ||
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) | ||
- flux2 (optional) | ||
|
||
### Components | ||
|
||
- VPC | ||
- EKS Cluster | ||
|
||
- EKS Addon: EBS CSI Driver | The EBS CSI driver addon is added to the Amazon EKS cluster to allow Kubernetes to use Amazon Elastic Block Store (EBS) volumes as persistent volumes in the cluster. | ||
|
||
- ECR Repository | ||
- Flux2 with Helm (Optional) | ||
- nginx with Helm (Optional) | ||
|
||
### Installing | ||
|
||
```bash | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
### Uninstalling | ||
|
||
```bash | ||
terraform destroy | ||
``` | ||
|
||
If you get an error related nodegroups, you can delete the nodegroup and cluster manually. | ||
|
||
```bash | ||
aws eks list-nodegroups --cluster-name exercise-eks | ||
aws eks delete-nodegroup --cluster-name exercise-eks --nodegroup-name exercise-eks-default-winning-chipmunk | ||
aws eks delete-cluster --name exercise-eks | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Description: This file is used to create the EKS cluster, VPC, and ECR repository | ||
# Author: Joseph Goksu | ||
|
||
# Set the local variables | ||
locals { | ||
cluster_name = "${var.project_name}-eks-${random_string.suffix.result}" | ||
vpc_name = "${var.project_name}-vpc-${random_string.suffix.result}" | ||
} | ||
|
||
# Generate a random string for the cluster name suffix | ||
resource "random_string" "suffix" { | ||
length = 8 | ||
special = false | ||
} | ||
|
||
# Create the VPC | ||
module "vpc" { | ||
source = "./modules/vpc" | ||
|
||
# Set the VPC name | ||
vpc_name = local.vpc_name | ||
|
||
# Set the cluster name | ||
cluster_name = local.cluster_name | ||
} | ||
|
||
# Create the EKS cluster | ||
module "eks" { | ||
source = "./modules/eks" | ||
|
||
cluster_name = local.cluster_name | ||
|
||
vpc_id = module.vpc.vpc_id | ||
private_subnets = module.vpc.private_subnets | ||
|
||
enable_ebs_csi_driver = true | ||
} | ||
|
||
# Create the ECR repository | ||
module "ecr" { | ||
source = "./modules/ecr" | ||
|
||
# Set the project name | ||
project_name = var.project_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 "region" { | ||
description = "AWS region" | ||
value = var.region | ||
} | ||
|
||
output "cluster_name" { | ||
description = "Kubernetes Cluster Name" | ||
value = module.eks.cluster_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
provider "aws" { | ||
region = var.region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "region" { | ||
description = "AWS region" | ||
type = string | ||
default = "eu-west-2" | ||
} | ||
|
||
variable "project_name" { | ||
description = "Project name" | ||
type = string | ||
default = "exercise" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Declare the required providers for this Terraform configuration | ||
terraform { | ||
required_providers { | ||
# Declare the AWS provider and specify the version to use | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 4.47.0" | ||
} | ||
|
||
# Declare the Random provider and specify the version to use | ||
random = { | ||
source = "hashicorp/random" | ||
version = "~> 3.4.3" | ||
} | ||
|
||
# Declare the TLS provider and specify the version to use | ||
tls = { | ||
source = "hashicorp/tls" | ||
version = "~> 4.0.4" | ||
} | ||
|
||
# Declare the CloudInit provider and specify the version to use | ||
cloudinit = { | ||
source = "hashicorp/cloudinit" | ||
version = "~> 2.2.0" | ||
} | ||
} | ||
|
||
# Specify the required version of Terraform for this configuration | ||
required_version = "~> 1.3" | ||
} |