Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/acm module #90

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions example/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locals {
tags = {
environment = var.environment
project = var.project
}
}
31 changes: 22 additions & 9 deletions example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ module "network" {
network = var.network
}

module "acm" {
source = "terraform-aws-modules/acm/aws"
version = "~> v2.0"

domain_name = var.domains[0]
subject_alternative_names = ["*.${var.domains[0]}"]
zone_id = module.system.route53_zone[0].zone_id
validate_certificate = var.aws_private == "false" ? true : false
tags = local.tags
}

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

Expand Down Expand Up @@ -104,15 +115,17 @@ module "nginx" {
google-cookie-secret = var.google-cookie-secret
}

#module "alb-ingress" {
# module_depends_on = [module.system.cert-manager]
# source = "../modules/ingress/alb-ingress"
# cluster_name = module.kubernetes.cluster_name
# domains = var.domains
# vpc_id = module.network.vpc_id
# aws_region = var.aws_region
# config_path = "${path.module}/kubeconfig_${var.cluster_name}"
#}
module "alb-ingress" {
module_depends_on = [module.system.cert-manager]
source = "../modules/ingress/alb-ingress"
cluster_name = module.kubernetes.cluster_name
domains = var.domains
vpc_id = module.network.vpc_id
aws_region = var.aws_region
config_path = "${path.module}/kubeconfig_${var.cluster_name}"
certificates_arns = [module.acm.this_acm_certificate_arn]
cluster_oidc_url = module.kubernetes.cluster_oidc_url
}

# Argoproj: all-in-one
module "argo" {
Expand Down
6 changes: 5 additions & 1 deletion example/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ output "route53_zone" {
value = module.system.route53_zone
}

# Kubernetes
output "wildcard_certificate" {
value = module.acm.this_acm_certificate_arn
}

// Kubernetes
output "cluster_name" {
value = module.kubernetes.cluster_name
}
Expand Down
4 changes: 2 additions & 2 deletions modules/airflow/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ resource "helm_release" "airflow" {
postgresql_host = var.airflow_postgresql_host
postgresql_port = var.airflow_postgresql_port
postgresql_username = var.airflow_postgresql_username
postgresql_password = var.airflow_postgresql_local == "true" ? random_password.airflow_postgresql_password.result : var.airflow_postgresql_password
postgresql_password = var.airflow_postgresql_local ? random_password.airflow_postgresql_password.result : var.airflow_postgresql_password
postgresql_database = var.airflow_postgresql_database
redis_local = var.airflow_redis_local
redis_host = var.airflow_redis_host
redis_port = var.airflow_redis_port
redis_username = var.airflow_redis_username
redis_password = var.airflow_redis_local == "true" ? random_password.airflow_redis_password.result : var.airflow_redis_password
redis_password = var.airflow_redis_local ? random_password.airflow_redis_password.result : var.airflow_redis_password
})
]
}
Expand Down
49 changes: 41 additions & 8 deletions modules/ingress/alb-ingress/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ resource "kubernetes_namespace" "alb-ingress-system" {
}
}

data "aws_eks_cluster" "this" {
depends_on = [
var.module_depends_on
]
name = var.cluster_name
}
data "aws_caller_identity" "current" {}


# Create role for alb-ingress
resource "aws_iam_policy" "alb-ingress" {
Expand Down Expand Up @@ -181,11 +177,11 @@ resource "aws_iam_role" "alb-ingress" {
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${replace(data.aws_eks_cluster.this.identity.0.oidc.0.issuer, "https://", "")}:sub": "system:serviceaccount:${kubernetes_namespace.alb-ingress-system.metadata[0].name}:*"
"${replace(var.cluster_oidc_url, "https://", "")}:sub": "system:serviceaccount:${kubernetes_namespace.alb-ingress-system.metadata[0].name}:alb-aws-alb-ingress-controller"
}
},
"Principal": {
"Federated": "arn:aws:iam::481193184231:oidc-provider/${replace(data.aws_eks_cluster.this.identity.0.oidc.0.issuer, "https://", "")}"
"Federated": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${replace(var.cluster_oidc_url, "https://", "")}"
},
"Effect": "Allow",
"Sid": ""
Expand Down Expand Up @@ -225,3 +221,40 @@ resource "helm_release" "alb-ingress" {
})
]
}

resource "kubernetes_ingress" "alb-nginx-ingress" {
metadata {
name = "alb-nginx-ingress"
namespace = kubernetes_namespace.alb-ingress-system.metadata[0].name
annotations = {
"alb.ingress.kubernetes.io/certificate-arn" = join(", ", var.certificates_arns)
"alb.ingress.kubernetes.io/healthcheck-path" = "/healthz"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/listen-ports" = "[{\"HTTP\":80}, {\"HTTPS\":443}]"
"alb.ingress.kubernetes.io/actions.ssl-redirect" = "{\"Type\": \"redirect\", \"RedirectConfig\": { \"Protocol\": \"HTTPS\", \"Port\": \"443\", \"StatusCode\": \"HTTP_301\"}}"
"kubernetes.io/ingress.class" = "alb"
}
}

spec {
rule {
host = var.domains[0]
http {
path {
path = "/*"
backend {
service_name = "ssl-redirect"
service_port = "use-annotation"
}
}
// path {
// path = "/*"
// backend {
// service_name = "test"
// service_port = "8080"
// }
// }
}
}
}
}
6 changes: 4 additions & 2 deletions modules/ingress/alb-ingress/values/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ awsRegion: ${region}
## Required if autoDiscoverAwsVpcID != true
awsVpcID: ${vpc_id}

podAnnotations:
iam.amazonaws.com/role: ${role-arn}
rbac:
serviceAccount:
annotations:
"eks.amazonaws.com/role-arn": ${role-arn}
10 changes: 10 additions & 0 deletions modules/ingress/alb-ingress/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ variable "config_path" {
description = "location of the kubeconfig file"
default = "~/.kube/config"
}

variable "certificates_arns" {
type = list(string)
description = "List of certificates to attach to ingress"
default = []
}

variable "cluster_oidc_url" {
type = string
}
2 changes: 1 addition & 1 deletion modules/system/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "null_resource" "wait-eks" {
}
}

# Install NVIDIA gpu support
# Install NVIDIA gpu support
# resources:
# limits:
# nvidia.com/gpu: 2 # requesting 2 GPUs
Expand Down