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

Refactor tests and add shared helpers #15

Merged
merged 6 commits into from
Nov 15, 2024
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
4 changes: 2 additions & 2 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ changelog:
labels:
- dependencies

- title: 🔩 Dependencies
- title: 🔩 Dependencies
labels:
- dependencies

# This file is managed by the osinfra-io/github-organization-management repository and should not be edited directly.
# This file is managed by the osinfra-io/github-organization-management repository and should not be edited directly.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ crash.log
# be included in version control.
local.tfvars

# Provider.tf is used for local development of modules and shouldn't be added to repos.
provider.tf

# Ignore override files as they are usually used to override ressources locally
override.tf
override.tf.json
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-symlinks

- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.96.1
rev: v1.96.2
hooks:
- id: terraform_fmt

Expand All @@ -29,9 +29,11 @@ repos:
- id: terraform_docs

- repo: https://github.com/bridgecrewio/checkov.git
rev: 3.2.257
rev: 3.2.296
hooks:
- id: checkov
verbose: true
args:
- --skip-check
- "CKV_TF_1"
- --quiet
1 change: 1 addition & 0 deletions regional/helpers.tf
34 changes: 2 additions & 32 deletions regional/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@
# https://www.terraform.io/docs/language/values/locals.html

locals {
cluster_name = local.zone != null ? "${var.cluster_prefix}-${local.region}-${local.zone}-${local.env}" : "${var.cluster_prefix}-${local.region}-${local.env}"
env = lookup(local.env_map, local.environment, "none")

env_map = {
"non-production" = "nonprod"
"production" = "prod"
"sandbox" = "sb"
}

environment = (
terraform.workspace == "default" ?
"mock-environment" :
regex(".*-(?P<environment>[^-]+)$", terraform.workspace)["environment"]
)
cluster_name = module.helpers.zone != null ? "${var.cluster_prefix}-${module.helpers.region}-${module.helpers.zone}-${module.helpers.env}" : "${var.cluster_prefix}-${module.helpers.region}-${module.helpers.env}"

helm_sensitive_values = {
"apiKey" = var.api_key
Expand All @@ -25,29 +12,12 @@ locals {
helm_values = {
"clusterName" = local.cluster_name
"datadogMonitor.enabled" = true
"podLabels.tags\\.datadoghq\\.com/env" = local.environment
"podLabels.tags\\.datadoghq\\.com/env" = module.helpers.environment
"podLabels.tags\\.datadoghq\\.com/version" = var.operator_version
"resources.limits.cpu" = var.limits_cpu
"resources.limits.memory" = var.limits_memory
"resources.requests.cpu" = var.requests_cpu
"resources.requests.memory" = var.requests_memory
"watchNamespaces" = join(",", var.watch_namespaces)
}

region = (
terraform.workspace == "default" ?
"mock-region" :
regex("^(?P<region>[^-]+-[^-]+)", terraform.workspace)["region"]
)


zone = (
terraform.workspace == "default" ?
"mock-zone" :
(
regex("^(?P<region>[^-]+-[^-]+)(?:-(?P<zone>[^-]+))?-.*$", terraform.workspace)["zone"] != "" ?
regex("^(?P<region>[^-]+-[^-]+)(?:-(?P<zone>[^-]+))?-.*$", terraform.workspace)["zone"] :
null
)
)
}
1 change: 1 addition & 0 deletions regional/manifests/helpers.tf
40 changes: 7 additions & 33 deletions regional/manifests/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@
# https://www.terraform.io/docs/language/values/locals.html

locals {
cluster_name = local.zone != null ? "${var.cluster_prefix}-${local.region}-${local.zone}-${local.env}" : "${var.cluster_prefix}-${local.region}-${local.env}"

env = lookup(local.env_map, local.environment, "none")

env_map = {
"non-production" = "nonprod"
"production" = "prod"
"sandbox" = "sb"
}

environment = (
terraform.workspace == "default" ?
"mock-environment" :
(regex(".*-(?P<environment>[^-]+)$", terraform.workspace)["environment"])
)
cluster_name = module.helpers.zone != null ? "${var.cluster_prefix}-${module.helpers.region}-${module.helpers.zone}-${module.helpers.env}" : "${var.cluster_prefix}-${module.helpers.region}-${module.helpers.env}"

kubernetes_monitor_templates = {
"crash-loop-backoff" = {
Expand Down Expand Up @@ -188,18 +174,12 @@ locals {
name = "DD_CONTAINER_EXCLUDE"
value = "kube_namespace:^gke-managed-cim$ kube_namespace:^gke-managed-system kube_namespace:^gke-mcs$ kube_namespace:^gmp-system$ kube_namespace:^kube-node-lease$ kube_namespace:^kube-public$ kube_namespace:^kube-system$ ${var.node_agent_env_dd_container_exclude}"
},
# {
# name = "DD_IGNORE_AUTOCONF"
# value = "cilium ${var.node_agent_env_dd_ignore_auto_conf}"
# }
{
name = "DD_IGNORE_AUTOCONF"
value = "cilium ${var.node_agent_env_dd_ignore_auto_conf}"
}
]

region = (
terraform.workspace == "default" ?
"mock-region" :
(regex("^(?P<region>[^-]+-[^-]+)", terraform.workspace)["region"])
)

trace_agent_env_vars = [

# Ignoring Unwanted Resources in APM
Expand All @@ -213,15 +193,9 @@ locals {

tags = [
"cluster:${local.cluster_name}",
"env:${local.environment}",
"env:${module.helpers.environment}",
"generated:kubernetes",
"region:${local.region}",
"region:${module.helpers.region}",
"team:${var.team}"
]

zone = (
terraform.workspace == "default" ?
"mock-zone" :
(regex("^(?P<region>[^-]+-[^-]+)-(?P<zone>[^-]+)", terraform.workspace)["zone"])
)
}
4 changes: 2 additions & 2 deletions regional/manifests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ resource "kubernetes_manifest" "agent" {
env = var.cluster_agent_env_vars

labels = {
"tags.datadoghq.com/env" = local.environment
"tags.datadoghq.com/env" = module.helpers.environment
"tags.datadoghq.com/service" = "datadog-cluster-agent"
"tags.datadoghq.com/version" = var.node_agent_tag
}
Expand Down Expand Up @@ -162,7 +162,7 @@ resource "kubernetes_manifest" "agent" {
}

labels = {
"tags.datadoghq.com/env" = local.environment
"tags.datadoghq.com/env" = module.helpers.environment
"tags.datadoghq.com/service" = "datadog-agent"
"tags.datadoghq.com/version" = var.node_agent_tag
}
Expand Down
2 changes: 1 addition & 1 deletion regional/manifests/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ variable "node_agent_requests_memory" {
variable "node_agent_tag" {
description = "Tag for the Datadog node agent image"
type = string
default = "7.57.2"
default = "7.58.1"
}

variable "node_agent_tolerations" {
Expand Down
2 changes: 1 addition & 1 deletion regional/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ variable "limits_memory" {
variable "operator_version" {
description = "The version of the Datadog Operator to install"
type = string
default = "2.1.0"
default = "2.2.0"
}

variable "requests_cpu" {
Expand Down
6 changes: 6 additions & 0 deletions shared/helpers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Terraform Core Child Module Helpers (osinfra.io)
# https://github.com/osinfra-io/terraform-core-helpers

module "helpers" {
source = "github.com/osinfra-io/terraform-core-helpers//child?ref=v0.1.2"
}