Skip to content

Commit

Permalink
Refactor tests and add shared helpers (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcurtis authored Nov 15, 2024
1 parent 2bfe6ca commit 619e5ea
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 138 deletions.
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
6 changes: 4 additions & 2 deletions regional/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ No requirements.

| Name | Version |
|------|---------|
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.16.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.16.1 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.33.0 |

## Modules

No modules.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_helpers"></a> [helpers](#module\_helpers) | github.com/osinfra-io/terraform-core-helpers//child | v0.1.2 |

## Resources

Expand Down
21 changes: 11 additions & 10 deletions regional/helm/gatekeeper.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
podLabels:
tags.datadoghq.com/service: gatekeeper
audit:
disableCertRotation: true
podLabels:
tags.datadoghq.com/service: gatekeeper-audit

controllerManager:
disableCertRotation: true
podLabels:
tags.datadoghq.com/service: gatekeeper-controller-manager

audit:
disableCertRotation: true
podLabels:
tags.datadoghq.com/service: gatekeeper-audit
externalCertInjection:
enabled: true

podLabels:
tags.datadoghq.com/service: gatekeeper

validatingWebhookAnnotations:
cert-manager.io/inject-ca-from: gatekeeper-system/gatekeeper-webhook-server-cert
mutatingWebhookAnnotations:
cert-manager.io/inject-ca-from: gatekeeper-system/gatekeeper-webhook-server-cert

externalCertInjection:
enabled: true
validatingWebhookAnnotations:
cert-manager.io/inject-ca-from: gatekeeper-system/gatekeeper-webhook-server-cert
1 change: 1 addition & 0 deletions regional/helpers.tf
16 changes: 1 addition & 15 deletions regional/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@
# https://www.terraform.io/docs/language/values/locals.html

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

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

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

helm_values = {
"audit.resources.limits.cpu" = var.audit_resources_limits_cpu
"audit.resources.limits.memory" = var.audit_resources_limits_memory
Expand All @@ -28,7 +14,7 @@ locals {
"image.crdRepository" = "${var.artifact_registry}/openpolicyagent/gatekeeper-crds"
"image.repository" = "${var.artifact_registry}/openpolicyagent/gatekeeper"
"image.release" = var.gatekeeper_version
"podLabels.tags\\.datadoghq\\.com/env" = local.environment
"podLabels.tags\\.datadoghq\\.com/env" = module.helpers.environment
"podLabels.tags\\.datadoghq\\.com/version" = var.gatekeeper_version
"postInstall.labelNamespace.image.repository" = "${var.artifact_registry}/openpolicyagent/gatekeeper-crds"
"postInstall.labelNamespace.image.tag" = var.gatekeeper_version
Expand Down
2 changes: 0 additions & 2 deletions regional/outputs.tf

This file was deleted.

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"
}
6 changes: 0 additions & 6 deletions tests/fixtures/default/regional/locals.tf

This file was deleted.

45 changes: 0 additions & 45 deletions tests/fixtures/default/regional/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,6 @@ terraform {
}
}

# Helm Provider
# https://registry.terraform.io/providers/hashicorp/helm/latest

provider "helm" {
kubernetes {

cluster_ca_certificate = base64decode(
local.regional.cluster_ca_certificate
)

host = local.regional.cluster_endpoint
token = data.google_client_config.current.access_token
}
}

# Kubernetes Provider
# https://registry.terraform.io/providers/hashicorp/kubernetes/latest

provider "kubernetes" {
cluster_ca_certificate = base64decode(
local.regional.cluster_ca_certificate
)

host = "https://${local.regional.cluster_endpoint}"
token = data.google_client_config.current.access_token
}

# Google Client Config Data Source
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config

data "google_client_config" "current" {
}

# Remote State Data Source
# https://www.terraform.io/language/state/remote-state-data

data "terraform_remote_state" "regional" {
backend = "gcs"
workspace = "mock-workspace"

config = {
bucket = "mock-bucket"
}
}

module "test" {
source = "../../../../regional"

Expand Down
6 changes: 0 additions & 6 deletions tests/fixtures/default/regional/manifests/locals.tf

This file was deleted.

45 changes: 0 additions & 45 deletions tests/fixtures/default/regional/manifests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,6 @@ terraform {
}
}

# Helm Provider
# https://registry.terraform.io/providers/hashicorp/helm/latest

provider "helm" {
kubernetes {

cluster_ca_certificate = base64decode(
local.regional.cluster_ca_certificate
)

host = local.regional.cluster_endpoint
token = data.google_client_config.current.access_token
}
}

# Kubernetes Provider
# https://registry.terraform.io/providers/hashicorp/kubernetes/latest

provider "kubernetes" {
cluster_ca_certificate = base64decode(
local.regional.cluster_ca_certificate
)

host = "https://${local.regional.cluster_endpoint}"
token = data.google_client_config.current.access_token
}

# Google Client Config Data Source
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config

data "google_client_config" "current" {
}

# Remote State Data Source
# https://www.terraform.io/language/state/remote-state-data

data "terraform_remote_state" "regional" {
backend = "gcs"
workspace = "mock-workspace"

config = {
bucket = "mock-bucket"
}
}

module "test" {
source = "../../../../../regional/manifests"
}

0 comments on commit 619e5ea

Please sign in to comment.