Skip to content

Commit

Permalink
add: project main files
Browse files Browse the repository at this point in the history
  • Loading branch information
josephgoksu committed May 30, 2023
1 parent c8d8485 commit 9588a14
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Makefile
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
43 changes: 43 additions & 0 deletions README.md
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
```
45 changes: 45 additions & 0 deletions main.tf
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
}
19 changes: 19 additions & 0 deletions outputs.tf
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
}
3 changes: 3 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = var.region
}
11 changes: 11 additions & 0 deletions variables.tf
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"
}
31 changes: 31 additions & 0 deletions versions.tf
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"
}

0 comments on commit 9588a14

Please sign in to comment.