Skip to content

Commit

Permalink
Iterate on design ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcurtis committed Oct 26, 2024
1 parent e8d8c77 commit 25ebcbb
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 14 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.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
- id: terraform_docs

- repo: https://github.com/bridgecrewio/checkov.git
rev: 3.2.267
rev: 3.2.269
hooks:
- id: checkov
verbose: true
Expand Down
15 changes: 7 additions & 8 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ locals {

# Examples:
# main-sandbox -> region = null, zone = null, environment = sandbox
# us-west1-sandbox -> region = us-west1, zone = null, environment = sandbox
# us-west1-foo-sandbox -> region = us-west1, zone = null, environment = sandbox
# us-west1-a-sandbox -> region = us-west1, zone = a, environment = sandbox
# us-west1-a-foo-sandbox -> region = us-west1, zone = a, environment = sandbox
# us-east1-sandbox -> region = us-east1, zone = null, environment = sandbox
# us-east1-foo-sandbox -> region = us-east1, zone = null, environment = sandbox
# us-east1-a-sandbox -> region = us-east1, zone = a, environment = sandbox
# us-east1-a-foo-sandbox -> region = us-east1, zone = a, environment = sandbox

environment_regex = "-(non-production|sandbox|production)$"
region_regex = "^(us-[a-z]+\\d+)"
Expand All @@ -28,7 +28,7 @@ locals {

labels = {

# Datadog expects the label env for unified service tagging
# Datadog expects the label env for unified service tagging otherwise we'd use the full name of environment.

env = local.environment
cost-center = var.cost_center
Expand All @@ -37,14 +37,14 @@ locals {
region = local.region
repository = var.repository
team = var.team
zone = local.zone != null ? "${local.region}-${local.zone}" : local.region
zone = local.zone != null ? "${local.region}-${local.zone}" : null
}

parsed_workspace = (
local.workspace == "default" ?
{

# We use mock providers when testing Terraform child modules, these values align with the test naming conventions
# We use mock providers when testing Terraform child modules, these values align with the test naming conventions.

environment = "mock-environment"
region = "mock-region"
Expand All @@ -59,7 +59,6 @@ locals {

region = local.parsed_workspace.region


workspace = var.workspace != null ? var.workspace : terraform.workspace
zone = local.parsed_workspace.zone
}
Empty file removed main.tf
Empty file.
88 changes: 85 additions & 3 deletions tests/default.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ run "main_sandbox" {
}
}

run "us_east1_sandbox" {
command = apply

module {
source = "./tests/fixtures/default"
}

variables {
workspace = "us-east1-sandbox"
}

assert {
condition = output.environment == "sandbox"
error_message = "Expected sandbox for us-east1-sandbox workspace"
}

assert {
condition = output.region == "us-east1"
error_message = "Expected us-east1 for us-east1-sandbox workspace"
}

assert {
condition = output.zone == null
error_message = "Expected null for us-east1-sandbox workspace"
}
}

run "us_east1_a_sandbox" {
command = apply

Expand Down Expand Up @@ -109,7 +136,7 @@ run "us_east1_a_test_sandbox" {
}
}

run "main_non-production" {
run "main_non_production" {
command = apply

module {
Expand All @@ -136,7 +163,34 @@ run "main_non-production" {
}
}

run "us_east1_a_non-production" {
run "us_east1_non_production" {
command = apply

module {
source = "./tests/fixtures/default"
}

variables {
workspace = "us-east1-non-production"
}

assert {
condition = output.environment == "non-production"
error_message = "Expected non-production for us-east1-non-production workspace"
}

assert {
condition = output.region == "us-east1"
error_message = "Expected us-east1 for us-east1-non-production workspace"
}

assert {
condition = output.zone == null
error_message = "Expected a for us-east1-non-production workspace"
}
}

run "us_east1_a_non_production" {
command = apply

module {
Expand All @@ -163,7 +217,7 @@ run "us_east1_a_non-production" {
}
}

run "us_east1_a_test_non-production" {
run "us_east1_a_test_non_production" {
command = apply

module {
Expand Down Expand Up @@ -217,6 +271,34 @@ run "main_production" {
}
}

run "us_east1_production" {
command = apply

module {
source = "./tests/fixtures/default"
}

variables {
workspace = "us-east1-production"
}

assert {
condition = output.environment == "production"
error_message = "Expected production for us-east1-production workspace"
}

assert {
condition = output.region == "us-east1"
error_message = "Expected us-east1 for us-east1-production workspace"
}

assert {
condition = output.zone == null
error_message = "Expected a for us-east1-production workspace"
}
}


run "us_east1_a_production" {
command = apply

Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/default/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Terraform Output Values
# https://www.terraform.io/language/values/outputs

output "env" {
value = module.core_workspace.env
}

output "environment" {
value = module.core_workspace.environment
}
Expand Down

0 comments on commit 25ebcbb

Please sign in to comment.