Skip to content
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
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ resource "spacelift_drift_detection" "default" {

lifecycle {
precondition {
condition = alltrue([for schedule in try(local.stack_configs[each.key].drift_detection_schedule, var.drift_detection_schedule) : can(regex("^([0-9,\\-\\*]+\\s+){4}[0-9,\\-\\*]+$", schedule))])
condition = alltrue([for schedule in try(local.stack_configs[each.key].drift_detection_schedule, var.drift_detection_schedule) : can(regex("^([0-9,\\-*/]+\\s+){4}[0-9,\\-*/]+$", schedule))])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a test to check that this works as expected with the / so we know this works as expected! Mind adding it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oycyc let's get this merged without this test, but let's follow up with one!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, put thi s on my todo list

error_message = "Invalid cron schedule format for drift detection"
}
}
Expand Down
32 changes: 16 additions & 16 deletions tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
variables {
root_modules_path = "./tests/fixtures/multi-instance"
root_modules_path = "./tests/fixtures/multi-instance"
common_config_file = "common.yaml"
github_enterprise = {
namespace = "masterpointio"
}
repository = "terraform-spacelift-automation"
repository = "terraform-spacelift-automation"
all_root_modules_enabled = true
aws_integration_enabled = false
aws_integration_enabled = false
before_init = [
"echo 'Hello'"
]
Expand All @@ -20,7 +20,7 @@ run "test_labels_are_created_correctly" {
command = plan

assert {
condition = contains(local.labels["root-module-a-test"], "nobackend")
condition = contains(local.labels["root-module-a-test"], "nobackend")
error_message = "Global labels were not created correctly: ${jsonencode(local.labels)}"
}
}
Expand All @@ -30,7 +30,7 @@ run "test_root_module_fileset_collects_all_root_modules" {
command = plan

assert {
condition = contains(local._all_root_modules, "root-module-a")
condition = contains(local._all_root_modules, "root-module-a")
error_message = "Root module fileset was not created correctly: ${jsonencode(local._all_root_modules)}"
}
}
Expand All @@ -40,7 +40,7 @@ run "test_common_labels_are_appended_to_stack_labels" {
command = plan

assert {
condition = contains(local.configs["root-module-a-test"].stack_settings.labels, "common_label") && contains(local.configs["root-module-a-test"].stack_settings.labels, "test_label")
condition = contains(local.configs["root-module-a-test"].stack_settings.labels, "common_label") && contains(local.configs["root-module-a-test"].stack_settings.labels, "test_label")
error_message = "Common labels were not merged correctly: ${jsonencode(local.configs)}"
}
}
Expand All @@ -50,7 +50,7 @@ run "test_stacks_include_expected" {
command = plan

assert {
condition = contains(local.stacks, "root-module-a-test")
condition = contains(local.stacks, "root-module-a-test")
error_message = "Stack names were not created correctly: ${jsonencode(local.stacks)}"
}
}
Expand All @@ -70,7 +70,7 @@ run "test_folder_labels_are_correct_format" {
command = plan

assert {
condition = contains(local._folder_labels["root-module-a-test"], "folder:root-module-a/test")
condition = contains(local._folder_labels["root-module-a-test"], "folder:root-module-a/test")
error_message = "Folder label was not created correctly for root-module-a: ${jsonencode(local._folder_labels)}"
}
}
Expand All @@ -80,7 +80,7 @@ run "test_workspace_when_default_tf_workspace_enabled_is_false" {
command = plan

assert {
condition = local.configs["root-module-a-test"].terraform_workspace == "test"
condition = local.configs["root-module-a-test"].terraform_workspace == "test"
error_message = "Terraform workspace was not set correctly when default_tf_workspace_enabled is false: ${jsonencode(local.configs)}"
}
}
Expand All @@ -90,7 +90,7 @@ run "test_workspace_when_default_tf_workspace_enabled" {
command = plan

assert {
condition = local.configs["root-module-a-default-example"].terraform_workspace == "default"
condition = local.configs["root-module-a-default-example"].terraform_workspace == "default"
error_message = "Default Terraform workspace was not used correctly: ${jsonencode(local.configs)}"
}
}
Expand All @@ -100,7 +100,7 @@ run "test_administrative_label_is_added_to_stack" {
command = plan

assert {
condition = contains(local.labels["root-module-a-default-example"], "administrative")
condition = contains(local.labels["root-module-a-default-example"], "administrative")
error_message = "Administrative label was not added to the stack: ${jsonencode(local.labels)}"
}
}
Expand All @@ -110,7 +110,7 @@ run "test_administrative_label_is_not_added_to_stack_when_not_administrative" {
command = plan

assert {
condition = !contains(local.labels["root-module-a-test"], "administrative")
condition = !contains(local.labels["root-module-a-test"], "administrative")
error_message = "Administrative label was added to the stack when it should not have been: ${jsonencode(local.labels)}"
}
}
Expand All @@ -120,7 +120,7 @@ run "test_depends_on_label_is_added_to_stack" {
command = plan

assert {
condition = contains(local.labels["root-module-a-test"], "depends-on:spacelift-automation-default")
condition = contains(local.labels["root-module-a-test"], "depends-on:spacelift-automation-default")
error_message = "Depends-on label was not added to the stack: ${jsonencode(local.labels)}"
}
}
Expand All @@ -130,7 +130,7 @@ run "test_before_init_excludes_the_expected_tfvars_copy_command_when_tfvars_are_
command = plan

assert {
condition = !contains(local.before_init["root-module-a-default-example"], "cp tfvars/default-example.tfvars spacelift.auto.tfvars")
condition = !contains(local.before_init["root-module-a-default-example"], "cp tfvars/default-example.tfvars spacelift.auto.tfvars")
error_message = "Before_init was not created correctly: ${jsonencode(local.before_init)}"
}
}
Expand All @@ -140,7 +140,7 @@ run "test_before_init_includes_the_expected_tfvars_copy_command" {
command = plan

assert {
condition = contains(local.before_init["root-module-a-test"], "cp tfvars/test.tfvars spacelift.auto.tfvars")
condition = contains(local.before_init["root-module-a-test"], "cp tfvars/test.tfvars spacelift.auto.tfvars")
error_message = "Before_init was not created correctly: ${jsonencode(local.before_init)}"
}
}
Expand All @@ -150,7 +150,7 @@ run "test_before_init_includes_the_default_before_init_and_stack_before_init" {
command = plan

assert {
condition = contains(local.before_init["root-module-a-default-example"], "echo 'Hello'") && contains(local.before_init["root-module-a-default-example"], "echo 'World'")
condition = contains(local.before_init["root-module-a-default-example"], "echo 'Hello'") && contains(local.before_init["root-module-a-default-example"], "echo 'World'")
error_message = "Before_init was not created correctly: ${jsonencode(local.before_init)}"
}
}
Expand Down
30 changes: 15 additions & 15 deletions tests/single-instance.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ variables {
github_enterprise = {
namespace = "masterpointio"
}
repository = "terraform-spacelift-automation"
repository = "terraform-spacelift-automation"
all_root_modules_enabled = true
aws_integration_enabled = false
aws_integration_enabled = false
before_init = [
"echo 'Hello'"
]
Expand All @@ -18,7 +18,7 @@ run "test_single_instance_root_module_fileset_collects_all_root_modules" {
command = plan

assert {
condition = contains(local._all_root_modules, "root-module-a")
condition = contains(local._all_root_modules, "root-module-a")
error_message = "Root module fileset was not created correctly: ${jsonencode(local._all_root_modules)}"
}
}
Expand All @@ -28,7 +28,7 @@ run "test_single_instance_stacks_include_expected" {
command = plan

assert {
condition = contains(local.stacks, "root-module-a")
condition = contains(local.stacks, "root-module-a")
error_message = "Stack names were not created correctly: ${jsonencode(local.stacks)}"
}
}
Expand All @@ -37,7 +37,7 @@ run "test_single_instance_stacks_only_include_default_stack" {
command = plan

assert {
condition = length(local._root_module_yaml_decoded["root-module-a"]) == 1 && local._root_module_yaml_decoded["root-module-a"]["default"] != null
condition = length(local._root_module_yaml_decoded["root-module-a"]) == 1 && local._root_module_yaml_decoded["root-module-a"]["default"] != null
error_message = "_root_module_yaml_decoded is not a single instance: ${jsonencode(local._root_module_yaml_decoded)}"
}
}
Expand All @@ -46,7 +46,7 @@ run "test_single_instance_stack_configs_stack_name_is_correct" {
command = plan

assert {
condition = length(local._root_module_stack_configs) == 2 && local._root_module_stack_configs["root-module-a"] != null && local._root_module_stack_configs["root-module-b"] != null
condition = length(local._root_module_stack_configs) == 2 && local._root_module_stack_configs["root-module-a"] != null && local._root_module_stack_configs["root-module-b"] != null
error_message = "_root_module_stack_configs is not expected structure: ${jsonencode(local._root_module_stack_configs)}"
}
}
Expand All @@ -55,7 +55,7 @@ run "test_single_instance_stack_configs_use_default_tf_workspace" {
command = plan

assert {
condition = local._root_module_stack_configs["root-module-a"].terraform_workspace == "default"
condition = local._root_module_stack_configs["root-module-a"].terraform_workspace == "default"
error_message = "terraform_workspace is not set to default: ${jsonencode(local._root_module_stack_configs)}"
}
}
Expand All @@ -64,7 +64,7 @@ run "test_single_instance_stack_configs_project_root_is_correct" {
command = plan

assert {
condition = local._root_module_stack_configs["root-module-a"].project_root == "${var.root_modules_path}/root-module-a"
condition = local._root_module_stack_configs["root-module-a"].project_root == "${var.root_modules_path}/root-module-a"
error_message = "project_root is not correct for root-module-a: ${jsonencode(local._root_module_stack_configs)}"
}
}
Expand All @@ -74,7 +74,7 @@ run "test_single_instance_stack_configs_custom_project_root_is_used_when_specifi

assert {
# `tests/fixtures/single-instance/root-module-b/stack.yaml` specifies `project_root` as "" to indicate root directory of project as source.
condition = local._root_module_stack_configs["root-module-b"].project_root == ""
condition = local._root_module_stack_configs["root-module-b"].project_root == ""
error_message = "Custom project_root not used: ${jsonencode(local._root_module_stack_configs)}"
}
}
Expand All @@ -84,7 +84,7 @@ run "test_single_instance_administrative_label_is_not_added_to_stack_when_not_ad
command = plan

assert {
condition = !contains(local.labels["root-module-a"], "administrative")
condition = !contains(local.labels["root-module-a"], "administrative")
error_message = "Administrative label was added to the stack when it should not have been: ${jsonencode(local.labels)}"
}
}
Expand All @@ -94,7 +94,7 @@ run "test_single_instance_depends_on_label_is_added_to_stack" {
command = plan

assert {
condition = contains(local.labels["root-module-a"], "depends-on:spacelift-automation-default")
condition = contains(local.labels["root-module-a"], "depends-on:spacelift-automation-default")
error_message = "Depends-on label was not added to the stack: ${jsonencode(local.labels)}"
}
}
Expand All @@ -104,7 +104,7 @@ run "test_single_instance_folder_label_is_added_to_stack_and_doesnt_include_work
command = plan

assert {
condition = contains(local.labels["root-module-a"], "folder:root-module-a")
condition = contains(local.labels["root-module-a"], "folder:root-module-a")
error_message = "Folder label was not added to the stack: ${jsonencode(local.labels)}"
}
}
Expand All @@ -114,7 +114,7 @@ run "test_single_instance_stack_yaml_labels_are_included_in_stack_labels" {
command = plan

assert {
condition = contains(local.labels["root-module-a"], "stack_label")
condition = contains(local.labels["root-module-a"], "stack_label")
error_message = "Stack.yaml labels were not included in the stack labels: ${jsonencode(local.labels)}"
}
}
Expand All @@ -124,7 +124,7 @@ run "test_single_instance_before_init_steps_are_added_to_stack" {
command = plan

assert {
condition = contains(local.before_init["root-module-a"], "echo 'Hello'") && contains(local.before_init["root-module-a"], "echo 'World'")
condition = contains(local.before_init["root-module-a"], "echo 'Hello'") && contains(local.before_init["root-module-a"], "echo 'World'")
error_message = "Before_init steps were not added to the stack: ${jsonencode(local.before_init)}"
}
}
Expand All @@ -134,7 +134,7 @@ run "test_single_instance_before_init_tfvar_cp_command_is_not_added_to_stack" {
command = plan

assert {
condition = !contains(local.before_init["root-module-a"], "cp tfvars/")
condition = !contains(local.before_init["root-module-a"], "cp tfvars/")
error_message = "Before_init tfvar cp command was added to the stack: ${jsonencode(local.before_init)}"
}
}