Backstage - creating a template and replace values in your template
1. First, you need to create an input form.
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
# some metadata about the template itself
metadata:
name: v1beta3-demo
title: Test
description: TestandTest
spec:
owner: testowner
type: service
# these are the steps which are rendered in the frontend with the form input
parameters:
- title: Fill in some steps
required:
- name
properties:
name:
title: short application name
type: string
description: Please provide a name for your application
ui:autofocus: true
maxLength: 10
ui:options:
rows: 2
appname:
title: Application Name
type: string
description: Please provide a name for your application
ui:autofocus: true
maxLength: 40
ui:options:
rows: 2
k8snamespace:
title: kubernetes namespace name that the application targeted to run on
type: string
description: Please provide a name for your namespace
maxLength: 12
ui:autofocus: true
ui:options:
rows: 2
azureresourcegroupname:
title: Azure resource group name
type: string
description: Resource group that will be hosting your infrastructure resources in Azure
ui:autofocus: true
maxLength: 10
ui:options:
rows: 2
steward:
title: Squad or steward name
type: string
description: Please provide a name for your team (the steward for this application)
ui:autofocus: true
maxLength: 20
ui:options:
rows: 5
- title: Choose a location
required:
- repoUrl
properties:
repoUrl:
title: Repository Location
type: string
ui:field: RepoUrlPicker
ui:options:
allowedHosts:
- dev.azure.com
# here's the steps that are executed in series in the scaffolder backend
steps:
- id: fetch-base
name: Fetch Base
action: fetch:template
input:
url: ./
values:
name: ${{ parameters.name }}
appname: ${{ parameters.appname }}
k8snamespace: ${{ parameters.k8snamespace }}
azureresourcegroupname: ${{ parameters.azureresourcegroupname }}
steward: ${{ parameters.steward }}
- id: publish
name: Publish
action: publish:azure
input:
repoUrl: ${{ parameters.repoUrl }}
description: This is ${{ parameters.name }}
gitCommitMessage: 'automation-work'
default: initialcode
- id: register
name: Register
action: catalog:register
input:
repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
catalogInfoPath: /backstage/catalog-info.yaml
2. Next, you have to update your template. Let's use a very simple example, say you need these value to be populated into application.config and it has the following content
-------------------------------- application.config --------------------------------
name: ${{ values.name }}
appname: ${{ values.appname }}
k8snamespace: ${{ values.k8snamespace }}
azureresourcegroupname: ${{ values.azureresourcegroupname }}
Comments