refactor: consolidate meshObject reference handling behind a single meshRef helper#235
Open
grubmeshi wants to merge 1 commit into
Open
refactor: consolidate meshObject reference handling behind a single meshRef helper#235grubmeshi wants to merge 1 commit into
grubmeshi wants to merge 1 commit into
Conversation
📊 Test Coverage
Uncovered functions (combined run)Combined with |
…eshRef helper Collapse the near-duplicate reference-schema helpers into one builder so every meshObject reference is constructed the same way. - `meshRefByUuid` / `meshRefByName` constructors take a `meshRefOptions` struct with two behaviour flags (`Output`, `OptionalComputed`); the zero value is a required input. This replaces the earlier `meshRef(kind, refId, desc, ...opts)` signature and the `asOutput()` / `required()` / `optionalComputed()` / `requiredId()` functional options. - Input identifiers stay Optional+Computed with an `AlsoRequires` guard rather than Required: a ref used as a set element collapses to a wholly-unknown element at plan (sets hash by whole value), which a Required nested attribute rejects with "Missing Configuration for Required Attribute". The guard enforces presence while tolerating the unknown; identifiers may also be resolved after apply (computed `.ref`, random suffix). - `refOutputKind` plan modifier keeps an output ref's `kind` known at plan time (it is always the single constant value); only the identifier is computed. - Give `building_block_definition_version_ref` a computed `kind` across all schema sites and the definition's version outputs, so the last outlier ref carries a kind like every other meshObject reference. Docs regenerated; CHANGELOG updated under the pending v0.23.3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
grubmeshi
force-pushed
the
feature/consolidate-ref-handling
branch
from
July 16, 2026 20:21
34cf6da to
74df186
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Terraform provider’s meshObject reference schema handling to consistently generate { kind, <uuid|name> } reference blocks via a single helper (meshRefByUuid / meshRefByName), and aligns the last outlier reference (building_block_definition_version_ref) by adding a kind discriminator throughout resources, data sources, and docs.
Changes:
- Consolidated reference attribute schema construction behind
meshRefByUuid/meshRefByNamewith a smallmeshRefOptionsconfig surface (including a resource-only plan modifier to keep outputkindknown at plan time). - Added
kindtobuilding_block_definition_version_ref(and propagated it through building block resources/data sources and building block definition version outputs). - Updated acceptance/unit tests and regenerated docs to reflect the unified reference semantics and new
kindfields.
Reviewed changes
Copilot reviewed 46 out of 46 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/provider/workspace_resource.go | Switches workspace ref output to the unified meshRefByName helper. |
| internal/provider/workspace_resource_test.go | Adds plan checks asserting ref.kind known and ref.name unknown on create. |
| internal/provider/workspace_data_source.go | Switches workspace data source ref output to meshRefByName. |
| internal/provider/tenants_v4_data_source.go | Uses meshRefByUuid for tenant ref output within list items. |
| internal/provider/tenant_v4_resource.go | Uses meshRefByUuid for tenant resource ref output. |
| internal/provider/schema_utils.go | Introduces meshRefOptions, meshRefByUuid/meshRefByName, and refOutputKind plan modifier; removes legacy ref helpers. |
| internal/provider/platform_type_data_source.go | Uses meshRefByName for platform type ref output. |
| internal/provider/platform_resource.go | Uses meshRefByUuid for platform resource ref output. |
| internal/provider/platform_resource_schema_kubernetes.go | Updates project_role_ref schema to unified meshRefByName helper. |
| internal/provider/platform_resource_schema_gcp.go | Updates project_role_ref schema to unified meshRefByName helper. |
| internal/provider/platform_resource_schema_azure.go | Updates project_role_ref schema to unified meshRefByName helper. |
| internal/provider/platform_resource_schema_aws.go | Updates project_role_ref schema to unified meshRefByName helper (multiple sites). |
| internal/provider/platform_data_source.go | Converts multiple output refs (ref, location_ref, platform_type_ref, project_role_ref) to meshRefByUuid/meshRefByName. |
| internal/provider/landingzone_resource.go | Reuses meshRefByUuid attributes/validators for building block definition refs; updates project_role_ref schemas. |
| internal/provider/landingzone_data_source.go | Converts platform_ref output to meshRefByUuid. |
| internal/provider/integrations_data_source.go | Converts integration runner output refs to meshRefByUuid. |
| internal/provider/integration_resource_schema.go | Converts optional-computed runner refs and integration ref output to meshRefByUuid. |
| internal/provider/building_blocks_data_source.go | Adds kind to version ref list item model/schema and sets it during Read. |
| internal/provider/building_block_v2_resource.go | Adds kind attribute to version ref schema; forces discriminator during Create/State set. |
| internal/provider/building_block_v2_data_source.go | Adds computed kind field to version ref output and sets it during Read. |
| internal/provider/building_block_runner_resource.go | Converts runner ref output to meshRefByUuid. |
| internal/provider/building_block_resource.go | Adds kind attribute to version ref schema; forces discriminator during DTO mapping. |
| internal/provider/building_block_definitions_data_source.go | Converts definition ref output to meshRefByUuid. |
| internal/provider/building_block_definition_resource_test.go | Extends known-value assertions to include kind on version refs. |
| internal/provider/building_block_definition_resource_schema.go | Adds kind to version outputs; converts dependency refs and other refs to meshRefByUuid. |
| internal/provider/building_block_definition_resource_model.go | Adds kind field to version ref model and populates it when mapping client DTOs. |
| docs/resources/workspace.md | Updates generated docs for workspace ref wording. |
| docs/resources/tenant_v4.md | Updates generated docs for tenant ref UUID wording. |
| docs/resources/platform.md | Updates generated docs to reflect unified ref semantics in nested schemas and outputs. |
| docs/resources/landingzone.md | Updates generated docs to reflect unified ref semantics in nested schemas. |
| docs/resources/integration.md | Updates generated docs for runner refs and integration ref UUID wording. |
| docs/resources/building_block.md | Documents added kind on version ref. |
| docs/resources/building_block_v2.md | Documents added kind on version ref. |
| docs/resources/building_block_runner.md | Updates generated docs for runner ref UUID wording. |
| docs/resources/building_block_definition.md | Documents added kind on version outputs and updates ref wording. |
| docs/data-sources/workspace.md | Updates generated docs for workspace ref wording. |
| docs/data-sources/tenants.md | Updates generated docs for tenant ref wording. |
| docs/data-sources/platform.md | Updates generated docs for refs and nested role mappings. |
| docs/data-sources/platform_type.md | Updates generated docs for platform type ref wording. |
| docs/data-sources/landingzone.md | Updates generated docs for platform/role mapping refs. |
| docs/data-sources/integrations.md | Updates generated docs for runner refs. |
| docs/data-sources/building_blocks.md | Documents added kind on version ref entries. |
| docs/data-sources/building_block_v2.md | Documents added kind on version ref output. |
| docs/data-sources/building_block_definitions.md | Updates generated docs for building block definition ref wording. |
| client/building_block_v2.go | Adds Kind to the client DTO for building block definition version refs. |
| CHANGELOG.md | Adds feature/fix entries describing the new kind field and ref behavior improvements. |
Comment on lines
68
to
+72
| MarkdownDescription: "UUID of the building block definition.", | ||
| Computed: true, | ||
| }, | ||
| "kind": schema.StringAttribute{ | ||
| MarkdownDescription: "meshObject type, always `" + client.MeshObjectKind.BuildingBlockDefinitionVersion + "`.", |
Comment on lines
+66
to
67
| - `kind` (String) meshObject type, always `meshBuildingBlockDefinitionVersion`. | ||
| - `uuid` (String) UUID of the building block definition. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consolidates the provider's reference-schema handling so every meshObject reference is built the same way, and brings the last outlier (
building_block_definition_version_ref) in line by giving it akind.What changed
meshRefByUuid/meshRefByNametake ameshRefOptionsstruct with just two behaviour flags —OutputandOptionalComputed; the zero value is a required input. This replaces the previousmeshRef(kind, refId, desc, ...opts)signature and itsasOutput()/required()/optionalComputed()/requiredId()functional options. Every call site is repointed.Optional+Computedwith anAlsoRequiresguard rather thanRequired. A plainRequiredcannot be used: a ref placed in a set (e.g.mandatory_building_block_refs) collapses to a wholly-unknown element at plan — Terraform hashes set elements by whole value — andRequiredthen fails with "Missing Configuration for Required Attribute". The guard enforces presence while tolerating an identifier that resolves after apply (a computed.ref, a random suffix, …). This is documented inline inschema_utils.go.kindknown at plan time. A newrefOutputKindplan modifier fills a still-unknown output block with its constantkindand an unknown identifier, instead of planning the whole object as "known after apply". Verified by aPreApplyplan check inTestAccWorkspace. Data sources have no plan-modifier hook, so this is resource-only; data-source refs resolvekindat their plan-time read.building_block_definition_version_refgains akind(computed, alwaysmeshBuildingBlockDefinitionVersion) across all schema sites and the definition'sversion_latest/version_latest_release/versionsoutputs, so the version ref carries a kind like every other reference. The client struct gains aKindfield; Read/Create force the fixed discriminator so it round-trips even if the backend omits it.Deliberately left bespoke
target_ref(discriminated uuid-or-name) andbuilding_block_definition_version_ref(extracontent_hashon the v3 path) carry extra fields, so they stay bespoke — the latter now simply also carries a kind.User-facing impact (see CHANGELOG under pending v0.23.3)
building_block_definition_version_refnow carrieskind(FEATURES).meshstack_platform/meshstack_landingzone:project_role_refin role mappings now has an optionalkind(defaulting) instead of read-only and no longer requires a known-literal identifier, so a referenced resource's computedrefcan be assigned (FIXES) — the same handling other refs already had.Validation
go build,task lint(0 issues),task generate(docs regenerated), unit tests (./client/,./internal/provider/mock mode) all pass.origin/main.🤖 Generated with Claude Code