Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/soat-fiap/bmb.infra into da…
Browse files Browse the repository at this point in the history
…tabase_subnets
  • Loading branch information
italopessoa committed Aug 25, 2024
2 parents 16e43f4 + a126e16 commit 00f3a46
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ jobs:
- name: Terraform Apply
if: github.ref == 'refs/heads/"main"'
# && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch')
run: terraform apply -auto-approve -input=false
run: terraform apply -input=false
18 changes: 9 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
terraform {
# backend "remote" {
# organization = "FiapPostech-SOAT"
# workspaces {
# name = "bmb-infra"
# }
# }
backend "remote" {
organization = "FiapPostech-SOAT"
workspaces {
name = "bmb-infra"
}
}
}

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

region = var.region
profile = var.profile
name = "${var.eks_vpc_name}-vpc"
name = var.eks_vpc_name
}

module "eks" {
Expand All @@ -26,10 +26,10 @@ module "eks" {
}

module "loadbalancer-controller" {
depends_on = [ module.eks ]
depends_on = [module.eks]
source = "./modules/loadbalancer-controller"
oidc_provider_arn = module.eks.oidc_provider_arn
app_name = "techchallenge-loadbalancer-controller"
name = "techchallenge-loadbalancer-controller"
cluster_name = module.eks.cluster_name
region = var.region
vpc_id = module.vpc.vpc_id
Expand Down
8 changes: 3 additions & 5 deletions modules/eks/main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.23.0"
version = "~> 20.23.0"

cluster_name = var.cluster_name
cluster_version = "1.30"

cluster_endpoint_public_access = true


create_kms_key = false
create_cloudwatch_log_group = true
cluster_encryption_config = {}


cluster_addons = {
coredns = {
most_recent = true
Expand Down Expand Up @@ -51,6 +49,6 @@ module "eks" {
enable_cluster_creator_admin_permissions = true

tags = {
Terraform = true
Terraform = "true"
}
}
}
36 changes: 30 additions & 6 deletions modules/loadbalancer-controller/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# load balancer controller role
module "lb_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 5.44.0"

role_name = "${var.app_name}_eks_lb"
role_name = "${var.name}_eks_lb"
attach_load_balancer_controller_policy = true

oidc_providers = {
Expand All @@ -14,6 +15,7 @@ module "lb_role" {
}

resource "kubernetes_service_account" "service-account" {
depends_on = [module.lb_role]
metadata {
name = "aws-load-balancer-controller"
namespace = "kube-system"
Expand Down Expand Up @@ -47,10 +49,10 @@ resource "helm_release" "alb-controller" {
}

# https://docs.aws.amazon.com/eks/latest/userguide/add-ons-images.html
# set {
# name = "image.repository"
# value = "602401143452.dkr.ecr.${var.region}.amazonaws.com/amazon/aws-load-balancer-controller"
# }
# set {
# name = "image.repository"
# value = "602401143452.dkr.ecr.${var.region}.amazonaws.com/amazon/aws-load-balancer-controller"
# }

set {
name = "serviceAccount.create"
Expand All @@ -67,3 +69,25 @@ resource "helm_release" "alb-controller" {
value = var.cluster_name
}
}

resource "kubernetes_service" "bmb-api-svc" {
depends_on = [helm_release.alb-controller]
metadata {
name = "nlb-controller-service"
annotations = {
"service.beta.kubernetes.io/aws-load-balancer-name" = "${var.name}-nlb"
}
}
spec {
port {
port = 80
target_port = 8080
node_port = 30000
protocol = "TCP"
}
type = "LoadBalancer"
selector = {
app : "nginx"
}
}
}
8 changes: 3 additions & 5 deletions modules/loadbalancer-controller/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
variable "app_name" {
variable "name" {
description = "Load balancer controller name"
type = string
default = "bmb-internal-connection"
}

variable "enabled" {
Expand All @@ -15,10 +17,6 @@ variable "region" {
type = string
}

# variable "env_name" {
# type = string
# }

variable "cluster_name" {
type = string
}
Expand Down
8 changes: 4 additions & 4 deletions modules/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.12.1"
version = "~> 5.12.1"

name = var.name

Expand All @@ -9,8 +9,8 @@ module "vpc" {
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
database_subnets = ["10.0.201.0/24", "10.0.202.0/24"]

enable_nat_gateway = true
single_nat_gateway = true
enable_nat_gateway = false
single_nat_gateway = false

public_subnet_tags = {
"kubernetes.io/role/elb" = 1
Expand All @@ -23,4 +23,4 @@ module "vpc" {
tags = {
Terraform = "true"
}
}
}
4 changes: 4 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
################################################################################
# VPC
################################################################################

output "vpc_id" {
description = "The ID of the VPC"
value = module.vpc.vpc_id
Expand Down
4 changes: 2 additions & 2 deletions providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.62.0"
version = "~>5.62.0"
}
}
required_version = "1.9.4"
required_version = "~>1.9.4"
}

provider "aws" {
Expand Down
40 changes: 40 additions & 0 deletions sampleapp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# name: nlb-sample-app
# # namespace: nlb-sample-app
# spec:
# replicas: 3
# selector:
# matchLabels:
# app: nginx
# template:
# metadata:
# labels:
# app: nginx
# spec:
# containers:
# - name: nginx
# image: public.ecr.aws/nginx/nginx:1.23
# ports:
# - name: tcp
# containerPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: nlb-sample-app
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: sampleapi-container
image: italopessoa/sampleapi:v1
3 changes: 1 addition & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "eks_vpc_name" {
description = "VPC name"
type = string
default = "eks-fiap"
default = "eks-fiap-vpc"
}

variable "profile" {
Expand All @@ -16,7 +16,6 @@ variable "region" {
default = "us-east-1"
}


variable "cluster_name" {
type = string
default = "quixada"
Expand Down

0 comments on commit 00f3a46

Please sign in to comment.