Skip to content
Draft
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: 3 additions & 0 deletions modules/meshstack/noop/buildingblock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Use it to:
| `sensitive_yaml` | `CODE` | `STATIC` (sensitive) | Encrypted YAML/JSON value, decrypted at runtime |
| `static` | `STRING` | `STATIC` | A platform-engineer-defined string constant |
| `static_code` | `CODE` | `STATIC` | A platform-engineer-defined map |
| `tag_value` | `CODE` | `TAG` | Value of a meshStack tag, read from the target object rather than typed in by a user |
| `flag` | `BOOLEAN` | `USER_INPUT` | Boolean flag chosen by the user |
| `num` | `INTEGER` | `USER_INPUT` | Integer chosen by the user |
| `text` | `STRING` | `USER_INPUT` | Free-text string from the user |
Expand Down Expand Up @@ -78,6 +79,7 @@ No modules.
| <a name="input_single_select"></a> [single\_select](#input\_single\_select) | n/a | `string` | n/a | yes |
| <a name="input_static"></a> [static](#input\_static) | n/a | `string` | n/a | yes |
| <a name="input_static_code"></a> [static\_code](#input\_static\_code) | n/a | `map(string)` | n/a | yes |
| <a name="input_tag_value"></a> [tag\_value](#input\_tag\_value) | n/a | `list(string)` | n/a | yes |
| <a name="input_text"></a> [text](#input\_text) | n/a | `string` | n/a | yes |
| <a name="input_user_permissions"></a> [user\_permissions](#input\_user\_permissions) | n/a | <pre>list(object({<br/> meshIdentifier = string<br/> username = string<br/> firstName = string<br/> lastName = string<br/> email = string<br/> euid = string<br/> roles = list(string)<br/> }))</pre> | n/a | yes |
| <a name="input_user_permissions_json"></a> [user\_permissions\_json](#input\_user\_permissions\_json) | n/a | `string` | n/a | yes |
Expand All @@ -102,6 +104,7 @@ No modules.
| <a name="output_static"></a> [static](#output\_static) | n/a |
| <a name="output_static_code"></a> [static\_code](#output\_static\_code) | n/a |
| <a name="output_summary"></a> [summary](#output\_summary) | n/a |
| <a name="output_tag_value"></a> [tag\_value](#output\_tag\_value) | n/a |
| <a name="output_text"></a> [text](#output\_text) | n/a |
| <a name="output_user_permissions"></a> [user\_permissions](#output\_user\_permissions) | n/a |
| <a name="output_user_permissions_json"></a> [user\_permissions\_json](#output\_user\_permissions\_json) | n/a |
Expand Down
5 changes: 5 additions & 0 deletions modules/meshstack/noop/buildingblock/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ output "static_code" {
value = var.static_code
}

output "tag_value" {
value = var.tag_value
}

output "flag" {
value = var.flag
}
Expand Down Expand Up @@ -113,6 +117,7 @@ output "debug_input_variables_json" {
multi_select_json = var.multi_select_json
static = var.static
static_code = var.static_code
tag_value = var.tag_value
user_permissions = var.user_permissions
user_permissions_json = var.user_permissions_json
})
Expand Down
6 changes: 6 additions & 0 deletions modules/meshstack/noop/buildingblock/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ variable "static_code" {
type = map(string)
}

variable "tag_value" {
# meshStack sends a TAG input as a JSON array of strings; a tag with no value resolves to null.
type = list(string)
nullable = true
}

variable "flag" {
type = bool
}
Expand Down
30 changes: 30 additions & 0 deletions modules/meshstack/noop/e2e/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ variable "test_context" {
nullable = false
}

# A tag input reads its value from an existing meshStack tag, so the e2e test provisions its own
# tag definition and sets it on the test workspace to exercise the input end-to-end. It cannot be
# destroyed while the building block definition below reads it, so referencing its `spec.key` from
# the module's `tag_key` input (and the workspace tag depending on the definition) gets destroy
# order right on its own.
resource "meshstack_tag_definition" "noop_e2e" {
spec = {
target_kind = "meshWorkspace"
key = "noop-e2e-tag-${var.test_context.name_suffix}"
display_name = "NoOp E2E Tag"
value_type = { string = {} }
}
}

resource "meshstack_workspace_tag" "noop_e2e" {
metadata = {
workspace_identifier = var.test_context.workspace
key = meshstack_tag_definition.noop_e2e.spec.key
}
spec = {
values = ["e2e-tag-value"]
}
}

module "noop" {
source = "../"
meshstack = {
Expand All @@ -18,9 +42,14 @@ module "noop" {
git_ref = var.test_context.hub_git_ref
bbd_draft = true
}
tag_object = "WORKSPACE"
tag_key = meshstack_tag_definition.noop_e2e.spec.key
}

resource "meshstack_building_block" "this" {
# ensures the tag has a value before the building block run reads it
depends_on = [meshstack_workspace_tag.noop_e2e]

wait_for_completion = true
spec = {
building_block_definition_version_ref = module.noop.building_block_definition.version_ref
Expand All @@ -40,6 +69,7 @@ resource "meshstack_building_block" "this" {
single_select = { value = jsonencode("single1") }
multi_select = { value = jsonencode(["multi1", "multi2"]) }
multi_select_json = { value = jsonencode(["multi2", "multi1"]) }
# tag_value = <nothing> -> TAG-assigned inputs are read by meshStack from the workspace tag, not supplied here.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"static_code": {
"some":"code"
},
"tag_value": ["e2e-tag-value"],
"text":"Hello, World!"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ run "building_block_noop_hub" {
error_message = "noop hub building block expected output resource_url to be 'https://hub.meshcloud.io/modules/meshstack/noop', got ${jsondecode(meshstack_building_block.this.status.outputs["resource_url"].value)}"
}

assert {
# tag_value is sourced from the meshstack_workspace_tag set up in e2e/main.tf, not from the
# building block's own inputs.
condition = jsondecode(meshstack_building_block.this.status.outputs["tag_value"].value) == ["e2e-tag-value"]
error_message = "noop hub building block expected output tag_value to be [\"e2e-tag-value\"], got ${jsondecode(meshstack_building_block.this.status.outputs["tag_value"].value)}"
}

assert {
condition = (
jsondecode(meshstack_building_block.this.status.outputs["summary"].value)
Expand Down
31 changes: 30 additions & 1 deletion modules/meshstack/noop/meshstack_integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ variable "runner_ref" {
description = "Optional reference to a meshStack building block runner. When set, building block runs are dispatched to this custom runner. Obtain the value from the backplane module's `runner_ref` output."
}

variable "tag_object" {
type = string
default = "WORKSPACE"
description = "The meshStack object kind the `tag_value` input reads its value from. A WORKSPACE_LEVEL building block definition (like this one) can only read WORKSPACE tags; TENANT_LEVEL definitions can also read PROJECT, PAYMENT_METHOD, or LANDING_ZONE."
}

variable "tag_key" {
type = string
default = "business-unit"
description = "Key of an existing meshStack tag definition (target_kind meshWorkspace) that the `tag_value` input reads its value from. The tag definition must already exist on the target meshStack instance."
}

variable "meshstack" {
type = object({
owning_workspace_identifier = string
Expand Down Expand Up @@ -177,6 +189,12 @@ resource "meshstack_building_block_definition" "this" {
display_name = "Static Code"
type = "CODE"
}
tag_value = {
assignment_type = "TAG"
argument = jsonencode("${var.tag_object}.${var.tag_key}")
display_name = "Tag Value"
type = "CODE"
}
text = {
assignment_type = "USER_INPUT"
default_value = jsonencode("")
Expand Down Expand Up @@ -220,6 +238,17 @@ resource "meshstack_building_block_definition" "this" {
display_name = "Static Code"
type = "CODE"
}
# We need to wait for TF provider release to make this work
# tag_value = {
# assignment_type = "NONE"
# display_name = "Tag Value"
# type = "CODE"
# }
tag_value = {
assignment_type = "NONE"
display_name = "Tag Value"
type = "CODE"
}
resource_url = {
assignment_type = "RESOURCE_URL"
display_name = "Resource URL"
Expand Down Expand Up @@ -250,7 +279,7 @@ terraform {
required_providers {
meshstack = {
source = "meshcloud/meshstack"
version = ">= 0.21.0"
version = ">= 0.25.2"
}
}
}
Loading