export_architecture
Export an architecture specification to Terraform, CloudFormation, Mermaid, D2, or other formats. Get ready-to-write IaC code, diagrams, or audit artifacts from your ArchSpec.
Instructions
Export an architecture spec to Terraform, CloudFormation, Mermaid, D2, or other formats.
Returns {'format': str, 'content': str} where content is the
ready-to-write payload. Terraform/CFN outputs use variables for sensitive
values (no hardcoded credentials), include provider blocks with region
configuration, and generate data sources for VPC/subnet discovery.
When to use: You have a finalized ArchSpec and need IaC code, a diagram,
or an audit artifact. For multi-format export, call once per format.
Behavior: Pure computation — no LLM, no network. Does not write files or deploy; the caller is responsible for persisting or applying the returned content.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spec_json | Yes | ArchSpec to export. Components are translated to provider-native resources; connections become security-group / firewall / IAM rules. | |
| format | No | Target output format. Values: 'terraform' (HCL with provider blocks, 24 AWS / 11 GCP / 10 Azure resource types), 'cloudformation' (YAML template with Parameters/Outputs), 'mermaid' (tier-grouped flowchart), 'd2' (D2 diagram), 'sbom' (CycloneDX 1.5 service bill of materials), 'aibom' (OWASP AI bill of materials), 'compliance' (audit-ready markdown report). | terraform |
Implementation Reference
- The main handler function 'export_architecture' that accepts an ArchSpec dict and format string, validates the spec, calls export_spec(), and returns the result.
@mcp.tool() def export_architecture( spec_json: Annotated[ dict, Field( description=( "ArchSpec to export. Components are translated to provider-native " "resources; connections become security-group / firewall / IAM rules." ), ), ], format: Annotated[ str, Field( description=( "Target output format. " "Values: 'terraform' (HCL with provider blocks, 24 AWS / 11 GCP / 10 " "Azure resource types), 'cloudformation' (YAML template with " "Parameters/Outputs), 'mermaid' (tier-grouped flowchart), " "'d2' (D2 diagram), 'sbom' (CycloneDX 1.5 service bill of materials), " "'aibom' (OWASP AI bill of materials), 'compliance' (audit-ready " "markdown report)." ), examples=["terraform", "cloudformation", "mermaid", "d2", "sbom"], ), ] = "terraform", ) -> dict: """Export an architecture spec to Terraform, CloudFormation, Mermaid, D2, or other formats. Returns `{'format': str, 'content': str}` where `content` is the ready-to-write payload. Terraform/CFN outputs use variables for sensitive values (no hardcoded credentials), include provider blocks with region configuration, and generate data sources for VPC/subnet discovery. When to use: You have a finalized ArchSpec and need IaC code, a diagram, or an audit artifact. For multi-format export, call once per `format`. Behavior: Pure computation — no LLM, no network. Does not write files or deploy; the caller is responsible for persisting or applying the returned content. """ from cloudwright.exporter import export_spec from cloudwright.spec import ArchSpec spec = ArchSpec.model_validate(spec_json) content = export_spec(spec, fmt=format) return {"format": format, "content": content} - Pydantic input schema for 'export_architecture': spec_json (dict) and format (str with default 'terraform' and examples).
def export_architecture( spec_json: Annotated[ dict, Field( description=( "ArchSpec to export. Components are translated to provider-native " "resources; connections become security-group / firewall / IAM rules." ), ), ], format: Annotated[ str, Field( description=( "Target output format. " "Values: 'terraform' (HCL with provider blocks, 24 AWS / 11 GCP / 10 " "Azure resource types), 'cloudformation' (YAML template with " "Parameters/Outputs), 'mermaid' (tier-grouped flowchart), " "'d2' (D2 diagram), 'sbom' (CycloneDX 1.5 service bill of materials), " "'aibom' (OWASP AI bill of materials), 'compliance' (audit-ready " "markdown report)." ), examples=["terraform", "cloudformation", "mermaid", "d2", "sbom"], ), ] = "terraform", ) -> dict: - packages/mcp/cloudwright_mcp/server.py:9-16 (registration)Registration: the 'export' module is mapped in _GROUPS dict and registered via module.register(mcp) in create_server.
_GROUPS = { "design": design, "cost": cost, "validate": validate, "analyze": analyze, "export": export, "session": session, } - Helper imports: ArchSpec.model_validate() for validation and export_spec() for the core export logic, imported from cloudwright.spec and cloudwright.exporter respectively.
from cloudwright.exporter import export_spec from cloudwright.spec import ArchSpec spec = ArchSpec.model_validate(spec_json) content = export_spec(spec, fmt=format) return {"format": format, "content": content}