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(labels): adds a variable to support labels on a root module level #39

Merged
merged 1 commit into from
Jan 9, 2025
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,13 @@ This is to support easy local and outside-spacelift operations. Keeping variable
| <a name="input_enabled_root_modules"></a> [enabled_root_modules](#input_enabled_root_modules) | List of root modules where to look for stack config files.<br/>Ignored when all_root_modules_enabled is true.<br/>Example: ["spacelift-automation", "k8s-cluster"] | `list(string)` | `[]` | no |
| <a name="input_github_action_deploy"></a> [github_action_deploy](#input_github_action_deploy) | Indicates whether GitHub users can deploy from the Checks API. | `bool` | `true` | no |
| <a name="input_github_enterprise"></a> [github_enterprise](#input_github_enterprise) | The GitHub VCS settings | <pre>object({<br/> namespace = string<br/> id = optional(string)<br/> })</pre> | `null` | no |
| <a name="input_labels"></a> [labels](#input_labels) | List of labels to apply to the stacks. | `list(string)` | `[]` | no |
| <a name="input_manage_state"></a> [manage_state](#input_manage_state) | Determines if Spacelift should manage state for this stack. | `bool` | `false` | no |
| <a name="input_protect_from_deletion"></a> [protect_from_deletion](#input_protect_from_deletion) | Protect this stack from accidental deletion. If set, attempts to delete this stack will fail. | `bool` | `false` | no |
| <a name="input_repository"></a> [repository](#input_repository) | The name of your infrastructure repo | `string` | n/a | yes |
| <a name="input_root_module_structure"></a> [root_module_structure](#input_root_module_structure) | The root module structure of the Stacks that you're reading in. See README for full details.<br/><br/>MultiInstance - You're using Workspaces or Dynamic Backend configuration to create multiple instances of the same root module code.<br/>SingleInstance - You're using copies of a root module and your directory structure to create multiple instances of the same Terraform code. | `string` | `"MultiInstance"` | no |
| <a name="input_root_modules_path"></a> [root_modules_path](#input_root_modules_path) | The path, relative to the root of the repository, where the root module can be found. | `string` | `"root-modules"` | no |
| <a name="input_runner_image"></a> [runner_image](#input_runner_image) | URL of the Docker image used to process Runs. Defaults to `null` which is Spacelift's standard (Alpine) runner image. | `string` | `"null"` | no |
| <a name="input_runner_image"></a> [runner_image](#input_runner_image) | URL of the Docker image used to process Runs. Defaults to `null` which is Spacelift's standard (Alpine) runner image. | `string` | `null` | no |
| <a name="input_space_id"></a> [space_id](#input_space_id) | Place the created stacks in the specified space_id. | `string` | `"root"` | no |
| <a name="input_terraform_smart_sanitization"></a> [terraform_smart_sanitization](#input_terraform_smart_sanitization) | Indicates whether runs on this will use terraform's sensitive value system to sanitize<br/>the outputs of Terraform state and plans in spacelift instead of sanitizing all fields. | `bool` | `false` | no |
| <a name="input_terraform_version"></a> [terraform_version](#input_terraform_version) | Terraform version to use. | `string` | `"1.7.2"` | no |
Expand Down
2 changes: 2 additions & 0 deletions examples/complete/components/spacelift-automation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ module "automation" {

aws_integration_id = var.aws_integration_id
aws_integration_enabled = true

labels = var.labels
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ repository = "terraform-spacelift-automation"
root_modules_path = "../../../../examples/complete/components"
all_root_modules_enabled = true
aws_integration_id = "01JEC7ZACVKHTSVY4NF8QNZVVB"
labels = ["nobackend"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ variable "github_enterprise" {
description = "The GitHub VCS settings"
}

variable "labels" {
type = list(string)
description = "List of labels to apply to the stacks."
default = []
}

variable "repository" {
type = string
description = "The name of your infrastructure repo"
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ locals {
lookup(local._folder_labels, stack, []),
lookup(local._dependency_labels, stack, []),
try(local.stack_configs[stack].labels, []),
var.labels,
]))
}

Expand Down
13 changes: 13 additions & 0 deletions tests/main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ variables {
before_init = [
"echo 'Hello'"
]
labels = [
"nobackend"
]
}

#Test that the global labels are created correctly
run "test_labels_are_created_correctly" {
command = plan

assert {
condition = contains(local.labels["root-module-a-test"], "nobackend")
error_message = "Global labels were not created correctly: ${jsonencode(local.labels)}"
}
}

# Test that the root module fileset is created correctly
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ variable "github_action_deploy" {
default = true
}

variable "labels" {
type = list(string)
description = "List of labels to apply to the stacks."
default = []
}

variable "manage_state" {
type = bool
description = "Determines if Spacelift should manage state for this stack."
Expand Down
Loading