From 205dca02c952e06913f54afa14fa5e159e7e526c Mon Sep 17 00:00:00 2001 From: Anshul Sao Date: Mon, 22 Jun 2026 11:35:45 +0530 Subject: [PATCH 1/2] =?UTF-8?q?feat(datastore/mysql):=20add=20reference=20?= =?UTF-8?q?flavour=20=E2=80=94=20passthrough=20of=20an=20existing=20mysql?= =?UTF-8?q?=20datastore's=20outputs=20(no=20resources)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01PKZUrLtUbJS5GuEyRA8Vd5 --- .../datastore/mysql/reference/1.0/facets.yaml | 60 +++++++++++++++++++ modules/datastore/mysql/reference/1.0/main.tf | 10 ++++ .../datastore/mysql/reference/1.0/outputs.tf | 58 ++++++++++++++++++ .../mysql/reference/1.0/variables.tf | 56 +++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 modules/datastore/mysql/reference/1.0/facets.yaml create mode 100644 modules/datastore/mysql/reference/1.0/main.tf create mode 100644 modules/datastore/mysql/reference/1.0/outputs.tf create mode 100644 modules/datastore/mysql/reference/1.0/variables.tf diff --git a/modules/datastore/mysql/reference/1.0/facets.yaml b/modules/datastore/mysql/reference/1.0/facets.yaml new file mode 100644 index 00000000..3af86818 --- /dev/null +++ b/modules/datastore/mysql/reference/1.0/facets.yaml @@ -0,0 +1,60 @@ +intent: mysql +flavor: reference +version: '1.0' +clouds: +- aws +- gcp +- azure +description: Reference (passthrough) to an existing MySQL datastore — re-exposes another + MySQL resource's outputs without provisioning any cloud resource. Useful for staging + database consolidation where several logical databases share one physical instance. +intentDetails: + type: Datastores + description: Reference an existing MySQL datastore and re-expose its connection details + displayName: MySQL + iconUrl: https://raw.githubusercontent.com/Facets-cloud/facets-modules-redesign/main/icons/mysql.svg +spec: + title: MySQL Reference + description: Re-expose the outputs of an existing MySQL datastore. Creates no cloud + resources — it points at another MySQL resource (the source) and optionally + overrides the logical database name in the connection string. + type: object + x-ui-order: + - source + - database_name + properties: + source: + type: object + title: Source MySQL Datastore + description: The existing MySQL datastore whose outputs should be re-exposed. + Resolves to the full outputs (attributes + interfaces) of the selected + resource. + x-ui-output-type: '@facets/mysql' + database_name: + type: string + title: Logical Database Name + description: Optional logical database to expose on the shared physical + instance. When set, the re-emitted connection_string targets this database + instead of the source's database. + pattern: ^[a-zA-Z][a-zA-Z0-9_]*$ + minLength: 1 + maxLength: 64 + required: + - source +outputs: + default: + type: '@facets/mysql' + title: MySQL Reference Instance +iac: + validated_files: + - main.tf + - variables.tf + - outputs.tf +sample: + kind: mysql + flavor: reference + version: '1.0' + disabled: true + spec: + source: {} + database_name: reporting diff --git a/modules/datastore/mysql/reference/1.0/main.tf b/modules/datastore/mysql/reference/1.0/main.tf new file mode 100644 index 00000000..321877e8 --- /dev/null +++ b/modules/datastore/mysql/reference/1.0/main.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.0" +} + +# This is a reference / passthrough flavour. It provisions NO cloud resources and +# requires NO providers. It re-exposes the outputs of an existing MySQL datastore +# (var.instance.spec.source) so that consumers can wire to a logical database that +# shares a physical instance (e.g. staging database consolidation). +# +# All output wiring lives in outputs.tf. diff --git a/modules/datastore/mysql/reference/1.0/outputs.tf b/modules/datastore/mysql/reference/1.0/outputs.tf new file mode 100644 index 00000000..17292776 --- /dev/null +++ b/modules/datastore/mysql/reference/1.0/outputs.tf @@ -0,0 +1,58 @@ +locals { + source = var.instance.spec.source + source_ifc = lookup(local.source, "interfaces", {}) + + source_reader = lookup(local.source_ifc, "reader", {}) + source_writer = lookup(local.source_ifc, "writer", {}) + + # Optional logical database override. When set, the connection_string is rebuilt + # to target this database on the same physical host/port; otherwise the source's + # connection_string and database are re-emitted unchanged. + override_database = lookup(var.instance.spec, "database_name", null) + + reader_host = lookup(local.source_reader, "host", null) + reader_port = lookup(local.source_reader, "port", null) + writer_host = lookup(local.source_writer, "host", null) + writer_port = lookup(local.source_writer, "port", null) + + reader_database = local.override_database != null ? local.override_database : lookup(local.source_reader, "database", null) + writer_database = local.override_database != null ? local.override_database : lookup(local.source_writer, "database", null) + + reader_connection_string = local.override_database != null ? format( + "mysql://%s:%s/%s", + local.reader_host, + local.reader_port, + local.override_database + ) : lookup(local.source_reader, "connection_string", null) + + writer_connection_string = local.override_database != null ? format( + "mysql://%s:%s/%s", + local.writer_host, + local.writer_port, + local.override_database + ) : lookup(local.source_writer, "connection_string", null) + + # Re-emit the @facets/mysql contract from the source. + output_attributes = lookup(local.source, "attributes", {}) + + output_interfaces = { + reader = { + host = local.reader_host + port = local.reader_port + username = lookup(local.source_reader, "username", null) + password = lookup(local.source_reader, "password", null) + database = local.reader_database + connection_string = local.reader_connection_string + secrets = lookup(local.source_reader, "secrets", ["password", "connection_string"]) + } + writer = { + host = local.writer_host + port = local.writer_port + username = lookup(local.source_writer, "username", null) + password = lookup(local.source_writer, "password", null) + database = local.writer_database + connection_string = local.writer_connection_string + secrets = lookup(local.source_writer, "secrets", ["password", "connection_string"]) + } + } +} diff --git a/modules/datastore/mysql/reference/1.0/variables.tf b/modules/datastore/mysql/reference/1.0/variables.tf new file mode 100644 index 00000000..4c33ecc2 --- /dev/null +++ b/modules/datastore/mysql/reference/1.0/variables.tf @@ -0,0 +1,56 @@ +variable "instance" { + description = "Reference (passthrough) to an existing MySQL datastore — re-exposes another MySQL resource's outputs without provisioning any cloud resource." + type = object({ + kind = string + flavor = string + version = string + spec = object({ + # source resolves (via x-ui-output-type: @facets/mysql) to the FULL outputs + # of the selected MySQL resource: its attributes + interfaces (reader/writer). + source = object({ + attributes = optional(any, {}) + interfaces = optional(object({ + reader = optional(object({ + host = optional(string) + port = optional(number) + username = optional(string) + password = optional(string) + database = optional(string) + connection_string = optional(string) + secrets = optional(list(string), []) + }), {}) + writer = optional(object({ + host = optional(string) + port = optional(number) + username = optional(string) + password = optional(string) + database = optional(string) + connection_string = optional(string) + secrets = optional(list(string), []) + }), {}) + }), {}) + }) + database_name = optional(string) + }) + }) +} + +variable "instance_name" { + description = "The architectural name for the resource as added in the Facets blueprint designer." + type = string +} + +variable "environment" { + description = "An object containing details about the environment." + type = object({ + name = string + unique_name = string + cloud_tags = map(string) + }) +} + +variable "inputs" { + description = "A map of inputs requested by the module developer. This passthrough module requires none." + type = object({}) + default = {} +} From 73da3365a3d5586d59ffc6001c38d07b3aaa75d2 Mon Sep 17 00:00:00 2001 From: Anshul Sao Date: Mon, 22 Jun 2026 12:08:45 +0530 Subject: [PATCH 2/2] refactor(datastore/mysql): rename reference flavour to logical 'reference' clashed with Facets' cross-blueprint reference concept. 'logical' = a logical database hosted on a shared physical instance. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01PKZUrLtUbJS5GuEyRA8Vd5 --- .../{reference => logical}/1.0/facets.yaml | 23 ++++++++++--------- .../mysql/{reference => logical}/1.0/main.tf | 0 .../{reference => logical}/1.0/outputs.tf | 0 .../{reference => logical}/1.0/variables.tf | 0 4 files changed, 12 insertions(+), 11 deletions(-) rename modules/datastore/mysql/{reference => logical}/1.0/facets.yaml (61%) rename modules/datastore/mysql/{reference => logical}/1.0/main.tf (100%) rename modules/datastore/mysql/{reference => logical}/1.0/outputs.tf (100%) rename modules/datastore/mysql/{reference => logical}/1.0/variables.tf (100%) diff --git a/modules/datastore/mysql/reference/1.0/facets.yaml b/modules/datastore/mysql/logical/1.0/facets.yaml similarity index 61% rename from modules/datastore/mysql/reference/1.0/facets.yaml rename to modules/datastore/mysql/logical/1.0/facets.yaml index 3af86818..8341857c 100644 --- a/modules/datastore/mysql/reference/1.0/facets.yaml +++ b/modules/datastore/mysql/logical/1.0/facets.yaml @@ -1,23 +1,24 @@ intent: mysql -flavor: reference +flavor: logical version: '1.0' clouds: - aws - gcp - azure -description: Reference (passthrough) to an existing MySQL datastore — re-exposes another - MySQL resource's outputs without provisioning any cloud resource. Useful for staging - database consolidation where several logical databases share one physical instance. +description: Logical — a logical database hosted on an existing/shared MySQL instance; + re-exposes its connection outputs (no resources created). Useful for staging database + consolidation where several logical databases share one physical instance. intentDetails: type: Datastores - description: Reference an existing MySQL datastore and re-expose its connection details + description: A logical database on an existing/shared MySQL instance — re-exposes its connection outputs displayName: MySQL iconUrl: https://raw.githubusercontent.com/Facets-cloud/facets-modules-redesign/main/icons/mysql.svg spec: - title: MySQL Reference - description: Re-expose the outputs of an existing MySQL datastore. Creates no cloud - resources — it points at another MySQL resource (the source) and optionally - overrides the logical database name in the connection string. + title: MySQL Logical Database + description: Logical — a logical database hosted on an existing/shared MySQL + instance; re-exposes its connection outputs (no resources created). Points at + another MySQL resource (the source) and optionally overrides the logical database + name in the connection string. type: object x-ui-order: - source @@ -44,7 +45,7 @@ spec: outputs: default: type: '@facets/mysql' - title: MySQL Reference Instance + title: MySQL Logical Database iac: validated_files: - main.tf @@ -52,7 +53,7 @@ iac: - outputs.tf sample: kind: mysql - flavor: reference + flavor: logical version: '1.0' disabled: true spec: diff --git a/modules/datastore/mysql/reference/1.0/main.tf b/modules/datastore/mysql/logical/1.0/main.tf similarity index 100% rename from modules/datastore/mysql/reference/1.0/main.tf rename to modules/datastore/mysql/logical/1.0/main.tf diff --git a/modules/datastore/mysql/reference/1.0/outputs.tf b/modules/datastore/mysql/logical/1.0/outputs.tf similarity index 100% rename from modules/datastore/mysql/reference/1.0/outputs.tf rename to modules/datastore/mysql/logical/1.0/outputs.tf diff --git a/modules/datastore/mysql/reference/1.0/variables.tf b/modules/datastore/mysql/logical/1.0/variables.tf similarity index 100% rename from modules/datastore/mysql/reference/1.0/variables.tf rename to modules/datastore/mysql/logical/1.0/variables.tf