HCL Configuration Merge

Action ID: hcl:merge
NPM Package:

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

Description

Merges HCL configuration files to consolidate settings and resources efficiently.

Input Schema

PropertyTypeDescriptionRequired
optionsany-
aSourceContentstringThe HCL content to be merged
bSourceContentstringThe HCL content to be merged

Output Schema

PropertyTypeDescriptionRequired
hclstring-

Usage Examples

Merge environment variables into terraform.tfvars

Merge environment-specific variables into an existing terraform.tfvars file during scaffolding. This fits after fetching a base template with fetch:template and before publishing with github:publish.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/example-org/terraform-service-template/archive/main.zip
      targetPath: .

  - id: merge-tfvars
    action: hcl:merge
    input:
      path: infra/environments/${{ parameters.env }}/terraform.tfvars
      content: |
        region         = "${{ parameters.region }}"
        instance_type  = "${{ parameters.instanceType }}"
        enable_logging = ${{ parameters.enableLogging }}
        tags = {
          service = "${{ parameters.serviceName }}"
          owner   = "${{ user.entity.metadata.name }}"
          env     = "${{ parameters.env }}"
        }

  - id: publish
    action: github:publish
    input:
      repoUrl: github.com?owner=example-org&repo=${{ parameters.repoName }}
      defaultBranch: main

Update Terraform backend configuration in backend.tf

Add or update a Terraform S3 backend block based on template parameters. Use this when standardizing remote state across environments before publishing with github:publish.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/example-org/terraform-infra-skeleton/archive/main.zip
      targetPath: .

  - id: merge-backend
    action: hcl:merge
    input:
      path: infra/backend.tf
      content: |
        terraform {
          backend "s3" {
            bucket         = "company-tfstate-${{ parameters.env }}"
            key            = "${{ parameters.repoName }}/terraform.tfstate"
            region         = "${{ parameters.region }}"
            encrypt        = true
            dynamodb_table = "tf-locks-${{ parameters.env }}"
          }
        }

  - id: publish
    action: github:publish
    input:
      repoUrl: github.com?owner=example-org&repo=${{ parameters.repoName }}
      defaultBranch: main