apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  description: Adds a Go application with AWS resources
  name: app-with-aws-resources
  title: Add a Go App with AWS resources
spec:
  owner: guests
  type: service
  parameters:
    - properties:
        name:
          title: Application Name
          type: string
          description: Unique name of the component
          ui:autofocus: true
        labels:
          title: Labels
          type: object
          additionalProperties:
            type: string
          description: Labels to apply to the application
          ui:autofocus: true
      required:
        - name
      title: Choose your repository location
    - description: Configure your bucket
      properties:
        apiVersion:
          default: awsblueprints.io/v1alpha1
          description: APIVersion for the resource
          type: string
        kind:
          default: ObjectStorage
          description: Kind for the resource
          type: string
        config:
          description: ObjectStorageSpec defines the desired state of ObjectStorage
          properties:
            resourceConfig:
              description: ResourceConfig defines general properties of this AWS resource.
              properties:
                deletionPolicy:
                  description: Defaults to Delete
                  enum:
                    - Delete
                    - Orphan
                  type: string
                region:
                  type: string
                providerConfigName:
                  type: string
                  default: default
                tags:
                  items:
                    properties:
                      key:
                        type: string
                      value:
                        type: string
                    required:
                      - key
                      - value
                    type: object
                  type: array
              required:
                - region
              type: object
          required:
            - resourceConfig
          title: Bucket configuration options
          type: object
  steps:
    - id: template
      name: Generating component
      action: fetch:template
      input:
        url: ./skeleton
        values:
          name: ${{parameters.name}}
    - action: roadiehq:utils:serialize:yaml
      id: serialize
      input:
        data:
          apiVersion: awsblueprints.io/v1alpha1
          kind: ${{ parameters.kind }}
          metadata:
            name: ${{ parameters.name }}
          spec: ${{ parameters.config }}
      name: serialize
    - action: roadiehq:utils:fs:write
      id: write
      input:
        content: ${{ steps['serialize'].output.serialized }}
        path: kustomize/base/${{ parameters.name }}.yaml
      name: write-to-file
    - id: publish
      name: Publishing to a gitea git repository
      action: publish:gitea
      input:
        description: This is an example app
        # Hard coded value for this demo purposes only.
        repoUrl: gitea.observability.think-ahead.cloud:443/?repo=${{parameters.name}}
        defaultBranch: main
    - id: create-argocd-app
      name: Create ArgoCD App
      action: cnoe:create-argocd-app
      input:
        appName: ${{parameters.name}}
        appNamespace: default
        argoInstance: in-cluster
        projectName: default
        # necessary until we generate our own cert
        repoUrl: https://gitea.observability.think-ahead.cloud:443/giteaAdmin/${{parameters.name}}
        path: "kustomize/base"
    - id: register
      name: Register
      action: catalog:register
      input:
        repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
        catalogInfoPath: 'catalog-info.yaml'
  output:
    links:
      - title: Open in catalog
        icon: catalog
        entityRef: ${{ steps['register'].output.entityRef }}
