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

feat: adds the runtime_overrides variable + tests #44

Merged
merged 15 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: adds tests for validating schema
Gowiem committed Jan 30, 2025
commit 486251bd523115c7187defffdfd7f42855b17498
14 changes: 14 additions & 0 deletions tests/schema-validation.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Confirm our StackConfig files in fixtures follow the schema.
# If this test fails, check the schema!
run "test_stack_configs_schema_validation" {
command = plan

module {
source = "./tests/schema-validator"
}

assert {
condition = length(data.jsonschema_validator.stack_configs) == 5
error_message = "The fixture Stack Configs did not validate against the schema: ${jsonencode(data.jsonschema_validator.stack_configs)}"
}
}
41 changes: 41 additions & 0 deletions tests/schema-validator/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
locals {
# Getting these file sets is a bit of a hack because the paths are all sorts of gunked up.
# We fix this below with the normalize_paths and stack_config_contents locals, but it's goofy.
multi_instance_stack_configs = fileset("${path.root}/../**/stacks", "*.yaml")
single_instance_stack_configs = fileset("${path.root}/../**", "stack.yaml")

stack_configs = toset(concat(
tolist(local.multi_instance_stack_configs),
tolist(local.single_instance_stack_configs)))

normalize_paths = [
for stack_config in local.stack_configs :
replace(stack_config, "../", "")
]

stack_config_contents = {
for stack_config in local.normalize_paths :
stack_config => file("./tests/${stack_config}")
}
}

data "jsonschema_validator" "stack_configs" {
for_each = local.stack_config_contents

document = jsonencode(yamldecode(each.value))
schema = "${path.module}/../../stack-config.schema.json"
}

output "validated_stack_configs" {
value = data.jsonschema_validator.stack_configs
}

terraform {
required_version = ">= 1.7"
required_providers {
jsonschema = {
source = "bpedman/jsonschema"
version = ">= 0.2.1"
}
}
}