Merge Files and Write

Action ID: hcl:merge:files:write
NPM Package:

@seatgeek/backstage-plugin-scaffolder-backend-module-hcl

Description

Merges multiple files and writes the combined output to a specified destination.

Input Schema

PropertyTypeDescriptionRequired
optionsany-
outputPathstringThe path to write the merged HCL content to
aSourcePathstringThe path to the HCL file to be merged
bSourcePathstringThe path to the HCL file to be merged

Output Schema

No output schema defined for this action.

Usage Examples

Merge environment-specific Terraform HCL files before publishing to GitHub

Runs hcl:merge:files:write in an environment folder after fetching template files. Use this when your template generates multiple HCL fragments for a Terraform environment that need to be merged before publishing. This example shows the action in a typical flow with fetch:template, publish:github, and [catalog:register](/backstage/scaffolder-actions/catalo g-register).

Copy
steps:
  - id: fetchBase
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        component_id: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        environment: ${{ parameters.environment }}

  - id: mergeHclEnv
    action: hcl:merge:files:write
    workingDirectory: terraform/environments/${{ parameters.environment }}

  - id: publishRepo
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=${{ parameters.name }}
      defaultBranch: main
      repoVisibility: private
      protectDefaultBranch: true

  - id: register
    action: catalog:register
    input:
      repoContentsUrl: ${{ steps.publishRepo.output.repoContentsUrl }}
      catalogInfoPath: /catalog-info.yaml

Conditionally merge HCL files for a module in a monorepo

Only runs hcl:merge:files:write when a parameter is enabled, targeting a specific module folder. Use this to optionally merge HCL inputs for certain modules (for example networking) before publishing with publish:github.

Copy
steps:
  - id: fetchTemplate
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        component_id: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        includeNetworking: ${{ parameters.includeNetworking }}

  - id: mergeHclModule
    action: hcl:merge:files:write
    if: ${{ parameters.includeNetworking }}
    workingDirectory: infrastructure/modules/network

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.owner }}&repo=infra-${{ parameters.name }}
      defaultBranch: main
      repoVisibility: internal
      gitCommitMessage: "scaffold: initial infrastructure with optional networking module"