apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: terraform-project-template
  title: Create a Terraform project for AWS
  description: Create a starter terraform project for provisioning AWS resources, including compute and database options
  tags:
    - terraform
    - aws
    - graviton
spec:
  owner: cloud-team
  type: infrastructure

  parameters:
    - title: Terraform Project Configuration
      required:
        - projectName
        - instanceType
        - databaseSize
        - securityGroupType
      properties:
        projectName:
          title: Project Name
          type: string
          description: The name of the terraform project
        instanceType:
          title: Compute Instance Type (AWS Graviton)
          type: string
          enum:
            - t4g.micro
            - t4g.small
            - t4g.medium
          description: Select the Graviton instance type
        databaseSize:
          title: Database Size
          type: string
          enum:
            - small
            - medium
            - large
          description: Choose the size of the database
        securityGroupType:
          title: Security Group Type
          type: string
          enum:
            - internal
            - public
          description: Configure security group for internal or public access

  steps:
    - id: generateTerraform
      name: Generating Terraform Configuration
      action: fetch:template
      input:
        url: ./terraform-skeleton
        values:
          projectName: ${{ parameters.projectName }}
          instanceType: ${{ parameters.instanceType }}
          databaseSize: ${{ parameters.databaseSize }}
          securityGroupType: ${{ parameters.securityGroupType }}

    - id: publish
      name: Publishing Terraform Project
      action: publish:github
      input:
        allowedHosts: ['github.com']
        repoUrl: github.com?owner=my-org&repo=${{ parameters.projectName }}
        defaultBranch: main

    - id: register
      name: Registering the Catalog Info Component
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps.publish.output.repoContentsUrl }}
        catalogInfoPath: /catalog-info.yaml

  output:
    links:
      - title: Open the Terraform Repository
        url: ${{ steps.publish.output.remoteUrl }}
      - title: Open the Catalog Info Component
        icon: catalog
        entityRef: ${{ steps.register.output.entityRef }}