awslabs / harmonix

A developer portal to meet your Enterprise needs. Fast, secure, and at-scale.
https://harmonixonaws.io/
Apache License 2.0
190 stars 35 forks source link

Create new template from existing template #107

Closed pgpbpadilla closed 2 weeks ago

pgpbpadilla commented 2 weeks ago

Description

Duplicated an existing template by copying the whole template directory and renaming it. I edited the key fields like name, type, etc. I waited for the scanner to import my new template, but nothing happened after the scheduled interval. I tried to register the template using the UI but it failed:

{
  "error": {
    "name": "InputError",
    "message": "Error: YAML error at url:/aws-s3-static-site/content/.backstage/catalog-info.yaml, YAMLParseError: Plain value cannot start with directive indicator character % at line 6, column 4:\n\n {%- if values.description %}\n ^\n"
  },
  "request": {
    "method": "POST",
    "url": "/locations?dryRun=true"
  },
  "response": {
    "statusCode": 400
  }
}

catalog-info.yaml:

apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: ${{ values.component_id | dump }}
  title: ${{ values.title | dump }}
  {%- if values.description %}
  description: ${{values.description | dump}}
  {%- endif %}
  tags:
    - aws
    - bucket
    - html
    - static-site
    - s3
  annotations:
  iacType: cdk
  bucketName: ${{ values.bucketName | dump }}
  awsArn: ""
spec:
  type: aws-app
  subType: s3-static-site
  owner: ${{ values.owner | dump }}
  lifecycle: experimental
  dependsOn: []

Versions

yarn list --cwd backstage --pattern aws-apps
yarn list v1.22.22
├─ @aws/plugin-aws-apps-backend-for-backstage@0.3.2
├─ @aws/plugin-aws-apps-common-for-backstage@0.3.2
├─ @aws/plugin-aws-apps-demo-for-backstage@0.3.1
├─ @aws/plugin-aws-apps-for-backstage@0.3.2
└─ @aws/plugin-scaffolder-backend-aws-apps-for-backstage@0.3.2

Reproduction Code [Required]

Steps to reproduce the behavior:

Expected behavior

My template should be registered and then I should see it in the Catalog.

Actual behavior

Registration fails with error provided above.

Terminal Output Screenshot(s)

image

Additional context

awsjim commented 2 weeks ago

Hi @pgpbpadilla 👋
When registering an existing component, you should specify the template.yaml file for the url. For example: https://git.mycompany.com/opa-admin/backstage-reference/-/blob/main/templates/my-new-project/template.yaml

I see the same behavior that you reported if I try to import the .backstage/catalog-info.yaml file.

Can you confirm that you're importing the correct file?

pgpbpadilla commented 2 weeks ago

I have now tried to use the template.yaml and get the following:

{
  "error": {
    "name": "InputError",
    "message": "InputError: No processor recognized the entity template:default/aws-s3-static-site as valid, possibly caused by a foreign kind or apiVersion"
  },
  "request": {
    "method": "POST",
    "url": "/locations?dryRun=true"
  },
  "response": {
    "statusCode": 400
  }
}

Here's the content of the template:

apiVersion: backstage.io/v1alpha1
# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-template
kind: Template
metadata:
  name: aws-s3-static-site
  title: Static site hosted in AWS S3 Bucket
  description: >-
    Create a static site hosted in Amazon S3 Bucket.
  tags:
    - html
    - static-site
    - s3
    - aws
spec:
  owner: group:admins
  type: website

# The rest of the template is a copy of: https://github.com/awslabs/harmonix/blob/main/backstage-reference/templates/aws-s3-resource/template.yaml

Basically I just duplicated the parent directory of aws-s3-resource and then renamed a few things.

awsjim commented 2 weeks ago

Check the apiVersion value. The value for a scaffolder template should be: apiVersion: scaffolder.backstage.io/v1beta3

Regarding discovery of the template, you may need to check the allTemplates.yaml file in the backstage-reference repository and ensure that you've got a reference for your new template.

pgpbpadilla commented 2 weeks ago

That was the issue 😓