Skip to content
Draft
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
2 changes: 2 additions & 0 deletions aws/platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ You can then use it to manually edit the aws-auth ConfigMap:
| <a name="module_auth_config_map"></a> [auth\_config\_map](#module\_auth\_config\_map) | ./modules/auth-config-map | n/a |
| <a name="module_aws_ebs_csi_driver"></a> [aws\_ebs\_csi\_driver](#module\_aws\_ebs\_csi\_driver) | ./modules/aws-ebs-csi-driver | n/a |
| <a name="module_aws_load_balancer_controller"></a> [aws\_load\_balancer\_controller](#module\_aws\_load\_balancer\_controller) | ./modules/load-balancer-controller | n/a |
| <a name="module_cloudwatch_adapter_service_account_role"></a> [cloudwatch\_adapter\_service\_account\_role](#module\_cloudwatch\_adapter\_service\_account\_role) | ./modules/cloudwatch-adapter-service-account-role | n/a |
| <a name="module_cloudwatch_logs"></a> [cloudwatch\_logs](#module\_cloudwatch\_logs) | ./modules/cloudwatch-logs | n/a |
| <a name="module_cluster_autoscaler_service_account_role"></a> [cluster\_autoscaler\_service\_account\_role](#module\_cluster\_autoscaler\_service\_account\_role) | ./modules/cluster-autoscaler-service-account-role | n/a |
| <a name="module_cluster_name"></a> [cluster\_name](#module\_cluster\_name) | ../cluster-name | n/a |
Expand Down Expand Up @@ -170,6 +171,7 @@ You can then use it to manually edit the aws-auth ConfigMap:
| <a name="input_aws_tags"></a> [aws\_tags](#input\_aws\_tags) | Tags to be applied to created AWS resources | `map(string)` | `{}` | no |
| <a name="input_cert_manager_values"></a> [cert\_manager\_values](#input\_cert\_manager\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_certificate_issuer"></a> [certificate\_issuer](#input\_certificate\_issuer) | YAML spec for certificate issuer; defaults to self-signed | `string` | `null` | no |
| <a name="input_cloudwatch_adapter_values"></a> [cloudwatch\_adapter\_values](#input\_cloudwatch\_adapter\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_cluster_autoscaler_values"></a> [cluster\_autoscaler\_values](#input\_cluster\_autoscaler\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the EKS cluster | `string` | n/a | yes |
| <a name="input_custom_roles"></a> [custom\_roles](#input\_custom\_roles) | Additional IAM roles which have custom cluster privileges | `map(string)` | `{}` | no |
Expand Down
24 changes: 24 additions & 0 deletions aws/platform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ module "common_platform" {
var.cert_manager_values
)

cloudwatch_adapter_values = concat(
local.cloudwatch_adapter_values,
var.cloudwatch_adapter_values
)

cluster_autoscaler_values = concat(
local.cluster_autoscaler_values,
var.cluster_autoscaler_values
Expand Down Expand Up @@ -128,6 +133,15 @@ module "cloudwatch_logs" {
skip_destroy = var.logs_skip_destroy
}

module "cloudwatch_adapter_service_account_role" {
source = "./modules/cloudwatch-adapter-service-account-role"

aws_namespace = [module.cluster_name.full]
aws_tags = var.aws_tags
k8s_namespace = var.k8s_namespace
oidc_issuer = data.aws_ssm_parameter.oidc_issuer.value
}

module "cluster_autoscaler_service_account_role" {
source = "./modules/cluster-autoscaler-service-account-role"

Expand Down Expand Up @@ -251,6 +265,16 @@ locals {
})
]

cloudwatch_adapter_values = [
yamlencode({
serviceAccount = {
annotations = {
"eks.amazonaws.com/role-arn" = module.cloudwatch_adapter_service_account_role.arn
}
}
})
]

cluster_autoscaler_values = [
yamlencode({
autoDiscovery = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.8 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_cloudwatch_adapter_service_account_role"></a> [cloudwatch\_adapter\_service\_account\_role](#module\_cloudwatch\_adapter\_service\_account\_role) | ../../../service-account-role | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_aws_namespace"></a> [aws\_namespace](#input\_aws\_namespace) | Prefix to be applied to created AWS resources | `list(string)` | `[]` | no |
| <a name="input_aws_tags"></a> [aws\_tags](#input\_aws\_tags) | Tags to be applied to created AWS resources | `map(string)` | `{}` | no |
| <a name="input_k8s_namespace"></a> [k8s\_namespace](#input\_k8s\_namespace) | Kubernetes namespace in which resources should be created | `string` | n/a | yes |
| <a name="input_oidc_issuer"></a> [oidc\_issuer](#input\_oidc\_issuer) | OIDC issuer of the Kubernetes cluster | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the created role |
| <a name="output_service_account_role_arn"></a> [service\_account\_role\_arn](#output\_service\_account\_role\_arn) | ARN of the AWS IAM role created for service accounts |
<!-- END_TF_DOCS -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "cloudwatch_adapter_service_account_role" {
source = "../../../service-account-role"

name = "cloudwatch-adapter"
namespace = var.aws_namespace
oidc_issuers = [var.oidc_issuer]
service_accounts = ["${var.k8s_namespace}:cloudwatch-adapter"]
tags = var.aws_tags
}

resource "aws_iam_policy" "this" {
name = module.cloudwatch_adapter_service_account_role.name
policy = data.aws_iam_policy_document.this.json
}

resource "aws_iam_role_policy_attachment" "this" {
role = module.cloudwatch_adapter_service_account_role.name
policy_arn = aws_iam_policy.this.arn
}

data "aws_iam_policy_document" "this" {
statement {
actions = [
"cloudwatch:GetMetricData"
]
resources = ["*"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
MODULEFILES := $(wildcard *.tf)
TFLINTRC ?= ../../.tflint.hcl
TFDOCSRC ?= ../../.terraform-docs.yml

.PHONY: default
default: checkfmt validate docs lint

.PHONY: checkfmt
checkfmt: .fmt

.PHONY: fmt
fmt: $(MODULEFILES)
terraform fmt
@touch .fmt

.PHONY: validate
validate: .validate

.PHONY: docs
docs: README.md

.PHONY: lint
lint: .lint

.lint: $(MODULEFILES) .lintinit
tflint --config=$(TFLINTRC)
@touch .lint

.lintinit: $(TFLINTRC)
tflint --init --config=$(TFLINTRC) --module
@touch .lintinit

README.md: $(MODULEFILES)
terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md

.fmt: $(MODULEFILES)
terraform fmt -check
@touch .fmt

.PHONY: init
init: .init

.init: versions.tf .dependencies
terraform init -backend=false
@touch .init

.validate: .init $(MODULEFILES) $(wildcard *.tf.example)
echo | cat - $(wildcard *.tf.example) > test.tf
if AWS_DEFAULT_REGION=us-east-1 terraform validate; then \
rm test.tf; \
touch .validate; \
else \
rm test.tf; \
false; \
fi

.dependencies: *.tf
@grep -ohE \
"\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \
sed "s/['\"]//" | sort | uniq | \
tee /tmp/initdeps | \
diff -q .dependencies - >/dev/null 2>&1 || \
mv /tmp/initdeps .dependencies

.PHONY: clean
clean:
rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "arn" {
description = "The ARN of the created role"
value = module.cloudwatch_adapter_service_account_role.instance.arn
}

output "service_account_role_arn" {
description = "ARN of the AWS IAM role created for service accounts"
value = module.cloudwatch_adapter_service_account_role.instance.arn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "aws_namespace" {
type = list(string)
default = []
description = "Prefix to be applied to created AWS resources"
}

variable "aws_tags" {
type = map(string)
description = "Tags to be applied to created AWS resources"
default = {}
}

variable "k8s_namespace" {
type = string
description = "Kubernetes namespace in which resources should be created"
}

variable "oidc_issuer" {
type = string
description = "OIDC issuer of the Kubernetes cluster"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 0.14.8"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
6 changes: 6 additions & 0 deletions aws/platform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ variable "certificate_issuer" {
default = null
}

variable "cloudwatch_adapter_values" {
description = "Overrides to pass to the Helm chart"
type = list(string)
default = []
}

variable "cluster_autoscaler_values" {
description = "Overrides to pass to the Helm chart"
type = list(string)
Expand Down
2 changes: 2 additions & 0 deletions platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ practices.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_cert_manager"></a> [cert\_manager](#module\_cert\_manager) | ./modules/cert-manager | n/a |
| <a name="module_cloudwatch_adapter"></a> [cloudwatch\_adapter](#module\_cloudwatch\_adapter) | ./modules/cloudwatch-adapter | n/a |
| <a name="module_cluster_autoscaler"></a> [cluster\_autoscaler](#module\_cluster\_autoscaler) | ./modules/cluster-autoscaler | n/a |
| <a name="module_external_dns"></a> [external\_dns](#module\_external\_dns) | ./modules/external-dns | n/a |
| <a name="module_federated_prometheus"></a> [federated\_prometheus](#module\_federated\_prometheus) | ./modules/prometheus-instance | n/a |
Expand Down Expand Up @@ -71,6 +72,7 @@ practices.
| <a name="input_cert_manager_values"></a> [cert\_manager\_values](#input\_cert\_manager\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_cert_manager_version"></a> [cert\_manager\_version](#input\_cert\_manager\_version) | Version of cert-manager to install | `string` | `null` | no |
| <a name="input_certificate_issuer"></a> [certificate\_issuer](#input\_certificate\_issuer) | YAML spec for certificate issuer; defaults to self-signed | `string` | `null` | no |
| <a name="input_cloudwatch_adapter_values"></a> [cloudwatch\_adapter\_values](#input\_cloudwatch\_adapter\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_cluster_autoscaler_values"></a> [cluster\_autoscaler\_values](#input\_cluster\_autoscaler\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_cluster_autoscaler_version"></a> [cluster\_autoscaler\_version](#input\_cluster\_autoscaler\_version) | Version of cluster-autoscaler to install | `string` | `null` | no |
| <a name="input_domain_names"></a> [domain\_names](#input\_domain\_names) | Domains which are allowed in this cluster | `list(string)` | `[]` | no |
Expand Down
9 changes: 9 additions & 0 deletions platform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ module "cert_manager" {
k8s_namespace = local.flightdeck_namespace
}

module "cloudwatch_adapter" {
source = "./modules/cloudwatch-adapter"

chart_values = var.cloudwatch_adapter_values
k8s_namespace = local.flightdeck_namespace

depends_on = [ module.module.prometheus_adapter ]
}

module "cluster_autoscaler" {
source = "./modules/cluster-autoscaler"

Expand Down
28 changes: 28 additions & 0 deletions platform/modules/cloudwatch-adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.8 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | ~> 2.4 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_helm"></a> [helm](#provider\_helm) | ~> 2.4 |

## Resources

| Name | Type |
|------|------|
| [helm_release.cloudwatch_adapter](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_chart_values"></a> [chart\_values](#input\_chart\_values) | Overrides to pass to the Helm chart | `list(string)` | `[]` | no |
| <a name="input_k8s_namespace"></a> [k8s\_namespace](#input\_k8s\_namespace) | Kubernetes namespace in which secrets should be created | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Name for the Helm release | `string` | `"cloudwatch-adapter"` | no |
<!-- END_TF_DOCS -->
11 changes: 11 additions & 0 deletions platform/modules/cloudwatch-adapter/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: cloudwatch-adapter
description: Configuration for cloudwatch adapter to fetch AWS Cloudwatch metrics in kubernetes

type: application

version: 0.1.0

appVersion: 1.0.0

# Downloaded from https://artifacthub.io/packages/helm/deliveryhero/k8s-cloudwatch-adapter
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "k8s-cloudwatch-adapter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "k8s-cloudwatch-adapter.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "k8s-cloudwatch-adapter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "k8s-cloudwatch-adapter.labels" -}}
app.kubernetes.io/name: {{ include "k8s-cloudwatch-adapter.name" . }}
helm.sh/chart: {{ include "k8s-cloudwatch-adapter.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels }}
{{- end }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "k8s-cloudwatch-adapter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "k8s-cloudwatch-adapter.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

Loading