-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
17 changed files
with
265 additions
and
163 deletions.
There are no files selected for viewing
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,3 @@ | ||
.terraform | ||
.terraform.lock.hcl | ||
terraform.tfstate.backup | ||
**/.terraform | ||
**/.terraform.lock.hcl | ||
**/terraform.tfstate.backup |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,20 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "< 5.0.0" | ||
} | ||
postgresql = { | ||
source = "cyrilgdn/postgresql" | ||
version = ">= 1.19.0" | ||
} | ||
} | ||
required_version = "~> 1.0" | ||
} | ||
|
||
provider "aws" { | ||
region = var.AWS_REGION | ||
access_key = var.AWS_ACCESS_KEY_ID | ||
secret_key = var.AWS_SECRET_ACCESS_KEY | ||
token = var.AWS_SESSION_TOKEN | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,160 @@ | ||
data "aws_eks_cluster" "main" { | ||
name = var.cluster_name | ||
} | ||
|
||
data "aws_eks_cluster_auth" "main" { | ||
name = var.cluster_name | ||
} | ||
|
||
data "aws_autoscaling_groups" "main" { | ||
filter { | ||
name = "tag:eks:cluster-name" | ||
values = [var.cluster_name] | ||
} | ||
} | ||
|
||
data "aws_eks_node_group" "worker" { | ||
cluster_name = var.cluster_name | ||
node_group_name = join("-", [ | ||
element(split("-", [for asg in data.aws_autoscaling_groups.main.names : asg if startswith(asg, "eks-worker-")][0]), 1), | ||
element(split("-", [for asg in data.aws_autoscaling_groups.main.names : asg if startswith(asg, "eks-worker-")][0]), 2) | ||
]) | ||
} | ||
|
||
locals { | ||
aws_account = element(split(":", data.aws_eks_cluster.main.arn), 4) | ||
oidc_issuer = element(split("//", data.aws_eks_cluster.main.identity[0].oidc[0].issuer), 1) | ||
} | ||
|
||
provider "kubernetes" { | ||
host = data.aws_eks_cluster.main.endpoint | ||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.main.certificate_authority[0].data) | ||
token = data.aws_eks_cluster_auth.main.token | ||
} | ||
|
||
provider "helm" { | ||
kubernetes { | ||
host = data.aws_eks_cluster.main.endpoint | ||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.main.certificate_authority[0].data) | ||
token = data.aws_eks_cluster_auth.main.token | ||
} | ||
} | ||
|
||
provider "kubectl" { | ||
apply_retry_count = 5 | ||
host = data.aws_eks_cluster.main.endpoint | ||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.main.certificate_authority[0].data) | ||
load_config_file = false | ||
token = data.aws_eks_cluster_auth.main.token | ||
} | ||
|
||
module "karpenter" { | ||
source = "terraform-aws-modules/eks/aws//modules/karpenter" | ||
version = "19.17.2" | ||
|
||
cluster_name = data.aws_eks_cluster.main.id | ||
|
||
irsa_oidc_provider_arn = join("", ["arn:aws:iam::", local.aws_account, ":oidc-provider/", local.oidc_issuer]) | ||
irsa_namespace_service_accounts = ["karpenter:karpenter"] | ||
|
||
create_iam_role = false | ||
iam_role_arn = data.aws_eks_node_group.worker.node_role_arn | ||
|
||
tags = merge(tomap({ "Name" : "${var.environment}-radar-base-karpenter" }), var.common_tags) | ||
} | ||
|
||
resource "helm_release" "karpenter" { | ||
namespace = "karpenter" | ||
create_namespace = true | ||
|
||
name = "karpenter" | ||
repository = "oci://public.ecr.aws/karpenter" | ||
chart = "karpenter" | ||
version = "v0.29.0" | ||
|
||
set { | ||
name = "settings.aws.clusterName" | ||
value = data.aws_eks_cluster.main.id | ||
} | ||
|
||
set { | ||
name = "settings.aws.clusterEndpoint" | ||
value = data.aws_eks_cluster.main.endpoint | ||
} | ||
|
||
set { | ||
name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" | ||
value = module.karpenter.irsa_arn | ||
} | ||
|
||
set { | ||
name = "settings.aws.defaultInstanceProfile" | ||
value = module.karpenter.instance_profile_name | ||
} | ||
|
||
set { | ||
name = "settings.aws.interruptionQueueName" | ||
value = module.karpenter.queue_name | ||
} | ||
|
||
} | ||
|
||
resource "kubectl_manifest" "karpenter_provisioner" { | ||
yaml_body = <<-YAML | ||
apiVersion: karpenter.sh/v1alpha5 | ||
kind: Provisioner | ||
metadata: | ||
name: default | ||
spec: | ||
requirements: | ||
- key: kubernetes.io/arch | ||
operator: In | ||
values: | ||
- amd64 | ||
- key: kubernetes.io/os | ||
operator: In | ||
values: | ||
- linux | ||
- key: karpenter.sh/capacity-type | ||
operator: In | ||
values: | ||
- "${lower(var.instance_capacity_type)}" | ||
- key: topology.kubernetes.io/zone | ||
operator: In | ||
values: | ||
- "${var.AWS_REGION}a" | ||
# - "${var.AWS_REGION}b" | ||
# - "${var.AWS_REGION}c" | ||
ttlSecondsAfterEmpty: 30 | ||
limits: | ||
resources: | ||
cpu: 64 | ||
memory: 256Gi | ||
providerRef: | ||
name: default | ||
YAML | ||
|
||
depends_on = [ | ||
helm_release.karpenter | ||
] | ||
} | ||
|
||
resource "kubectl_manifest" "karpenter_node_template" { | ||
yaml_body = <<-YAML | ||
apiVersion: karpenter.k8s.aws/v1alpha1 | ||
kind: AWSNodeTemplate | ||
metadata: | ||
name: default | ||
spec: | ||
subnetSelector: | ||
karpenter.sh/discovery: ${data.aws_eks_cluster.main.id} | ||
securityGroupSelector: | ||
karpenter.sh/discovery: ${data.aws_eks_cluster.main.id} | ||
tags: | ||
karpenter.sh/discovery: ${data.aws_eks_cluster.main.id} | ||
YAML | ||
|
||
depends_on = [ | ||
helm_release.karpenter | ||
] | ||
} |
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
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,59 @@ | ||
variable "AWS_REGION" { | ||
type = string | ||
default = "eu-west-2" | ||
} | ||
|
||
variable "AWS_ACCESS_KEY_ID" { | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "AWS_SECRET_ACCESS_KEY" { | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "AWS_SESSION_TOKEN" { | ||
type = string | ||
default = "" | ||
sensitive = true | ||
} | ||
|
||
variable "environment" { | ||
type = string | ||
default = "dev" | ||
} | ||
|
||
variable "common_tags" { | ||
type = map(string) | ||
default = { | ||
Project = "radar-base-development" | ||
Environment = "dev" | ||
} | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
} | ||
|
||
variable "instance_capacity_type" { | ||
type = string | ||
default = "SPOT" | ||
|
||
validation { | ||
condition = var.instance_capacity_type == "ON_DEMAND" || var.instance_capacity_type == "SPOT" | ||
error_message = "Invalid instance capacity type. Allowed values are 'ON_DEMAND' or 'SPOT'." | ||
} | ||
} | ||
|
||
# variable "karpenter_irsa_arn" { | ||
# type = string | ||
# } | ||
|
||
# variable "karpenter_instance_profile" { | ||
# type = string | ||
# } | ||
|
||
# variable "karpenter_interruption_queue_name" { | ||
# type = string | ||
# } |
Oops, something went wrong.