Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backstage templates #127

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: cloud-configure-ec2
title: AWS Operations / Create EC2 Instance
description: This wizard will guide you on how to create EC2 instance in the Amazon cloud
namespace: default
tags:
- aap-operations
- intermediate
- cloud-aws-ops
- configure-ec2-pattern
- create-ec2-instance
spec:
type: service
parameters:
- title: Prompts
description: Create EC2 instance in the Amazon cloud
required:
- token
- inventory
properties:
token:
title: Token
type: string
description: Oauth2 token
ui:field: AAPTokenField
ui:widget: password
ui:backstage:
review:
show: false
inventory:
title: Inventory
description: Please enter the inventory you want to use the services on
resource: inventories
ui:field: AAPResourcePicker
credentials:
title: Credentials
description: Select credentials for accessing AWS.
The credentials need to be of type "Amazon Web Services".
type: array
ui:field: AAPResourcePicker
resource: credentials
verbosity:
title: Verbosity
description: Control the level of output Ansible will produce as the playbook executes.
resource: verbosity
ui:field: AAPResourcePicker
- title: Survey
required:
- aws_region
- instance_name
- instance_type
description: Create EC2 instance in the Amazon cloud
properties:
aws_region:
title: AWS Region
description: AWS region where resources should be created
type: string
ui:options:
rows: 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with how the backstage templates work, what does rows: 5 do?

Copy link
Contributor Author

@kcagran kcagran Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance_name:
title: Instance Name
description: Name of EC2 instance to create
type: string
ui:options:
rows: 5
instance_type:
title: Instance Type
description: Type of EC2 instance to create (e.g., t2.micro, m5.large)
type: string
ui:options:
rows: 5
ami_id:
title: AMI ID
description: Amazon Machine Image (AMI) ID to use for the instance, if not provided will default to the RHEL 9 AMI for the provided region and instance type
type: string
ui:options:
rows: 5
key_name:
title: Key Pair Name
description: Name of key pair to use for SSH access to the EC2 instance. If the key does not exist or is not provided, the instance will not be accessible via SSH.
type: string
ui:options:
rows: 5
wait_for_state:
title: Wait for State
description: Whether to wait for the EC2 instance to be in the running state before continuing. Defaults to true
type: string
enum:
- ""
hakbailey marked this conversation as resolved.
Show resolved Hide resolved
- 'true'
- 'false'
instance_tags:
title: Instance Tags
description: 'A dict of tags for the instance, e.g. {"environment: test", "owner": "team foobar"}'
type: string
ui:options:
rows: 5
vpc_name:
title: VPC Name
description: Name of the VPC to create. Defaults to '{{instance_name}}-vpc'
type: string
ui:options:
rows: 5
vpc_cidr:
title: VPC CIDR Block
description: CIDR block to use for the VPC being created. Defaults to 10.0.0.0/24
type: string
ui:options:
rows: 5
subnet_cidr:
title: Subnet CIDR block
description: CIDR block to use for the subnet being created. 10.0.0.0/25
type: string
ui:options:
rows: 5
sg_name:
title: Security Group Name
description: Name of the security group to create for securing traffic to the instance. Defaults to '{{ instance_name }}-sg'
type: string
ui:options:
rows: 5
sg_description:
title: Security Group Description
description: Description for the security group. Defaults to 'Security group for EC2 instance {{ instance_name }}'
type: string
ui:options:
rows: 5
sg_rules:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we should double check, because I didn't see it tested in the demo video, is that this field correctly handles multiline yaml text, e.g.:

- proto: tcp 
  ports: 80 
  cidr_ip: 0.0.0.0/0

I've verified this works when running the job from AAP, I just want to make sure it also works as expected when launching the job template from RHDH.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested, with port 80, 8080, 22 in the list. Part of AAP job output:

TASK [Get security group rules list from string input] *************************  
ok: [localhost] => {"ansible_facts": {"sg_rules_list": [{"cidr_ip": "0.0.0.0/0", "ports": 80, "proto": "tcp"}, {"cidr_ip": "0.0.0.0/0", "ports": 8080, "proto": "tcp"}, {"cidr_ip": "0.0.0.0/0", "ports": 22, "proto": "tcp"}]}, "changed": false}

It works

title: Security Group Rules
description: 'A list of security group rules in yaml format, e.g.: - proto: tcp ports: 80 cidr_ip: 0.0.0.0/0 Defaults to allowing SSH access from within the VPC'
type: string
ui:options:
rows: 5
ui:widget: textarea
external_access:
title: Create External Access Resources
description: Whether to create resources for external access to the EC2 instance. Defaults to true. When true, adds security groups rules allowing inbound HTTP and HTTPS traffic, creates an internet gateway, creates a custom route table routing all internet traffic to the gateway, and allocates an elastic IP address for the instance.
type: string
enum:
- ""
- 'true'
- 'false'

steps:
- id: launch-job
name: Launch AWS Operations / Create EC2 Instance
action: rhaap:launch-job-template
input:
token: ${{ parameters.token }}
values:
inventory: ${{ parameters.inventory }}
credentials: ${{ parameters.credentials }}
verbosity: ${{parameters.verbosity}}
extraVariables:
aws_region: ${{ parameters.aws_region }}
instance_name: ${{ parameters.instance_name }}
instance_type: ${{ parameters.instance_type }}
ami_id: ${{ parameters.ami_id }}
key_name: ${{ parameters.key_name }}
wait_for_state: ${{ parameters.wait_for_state }}
instance_tags: ${{ parameters.instance_tags }}
vpc_name: ${{ parameters.vpc_name }}
vpc_cidr: ${{ parameters.vpc_cidr }}
subnet_cidr: ${{ parameters.subnet_cidr }}
sg_name: ${{ parameters.sg_name }}
sg_description: ${{ parameters.sg_description }}
sg_rules: ${{ parameters.sg_rules }}
external_access: ${{ parameters.external_access }}
output:
text:
- title: AWS Operations / Create EC2 Instance template executed
successfully
content: |
**Job ID:** ${{ steps['launch-job'].output.data.id }}
**Job STATUS:** ${{ steps['launch-job'].output.data.status }}
links:
- title: View in RH AAP
url: ${{ steps['launch-job'].output.data.url }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: cloud-terminate-ec2
title: AWS Operations / Terminate EC2 Instance
description: This wizard will guide you on how to terminate EC2 instance in the Amazon cloud
namespace: default
tags:
- aap-operations
- intermediate
- cloud-aws-ops
- configure-ec2-pattern
- terminate-ec2-instance
spec:
type: service
parameters:
- title: Prompts
description: Terminate EC2 instance in the Amazon cloud
required:
- token
- inventory
properties:
token:
title: Token
type: string
description: Oauth2 token
ui:field: AAPTokenField
ui:widget: password
ui:backstage:
review:
show: false
inventory:
title: Inventory
description: Please enter the inventory you want to use the services on
resource: inventories
ui:field: AAPResourcePicker
credentials:
title: Credentials
description: Select credentials for accessing AWS.
The credentials need to be of type "Amazon Web Services".
type: array
ui:field: AAPResourcePicker
resource: credentials
verbosity:
title: Verbosity
description: Control the level of output Ansible will produce as the playbook executes.
resource: verbosity
ui:field: AAPResourcePicker
- title: Survey
required:
- aws_region
- instance_name
description: Terminate EC2 instance in the Amazon cloud
properties:
aws_region:
title: AWS Region
description: AWS region where resources should be deleted
type: string
ui:options:
rows: 5
instance_name:
title: Instance Name
description: Name of EC2 instance to delete
type: string
ui:options:
rows: 5
key_name:
title: Key Pair Name
description: Name of key pair to delete for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key'
GomathiselviS marked this conversation as resolved.
Show resolved Hide resolved
type: string
ui:options:
rows: 5
vpc_name:
title: VPC Name
description: Name of the VPC to delete. Defaults to '{{instance_name}}-vpc'
type: string
ui:options:
rows: 5
steps:
- id: launch-job
name: Launch AWS Operations / Terminate EC2 Instance
action: rhaap:launch-job-template
input:
token: ${{ parameters.token }}
values:
inventory: ${{ parameters.inventory }}
credentials: ${{ parameters.credentials }}
verbosity: ${{parameters.verbosity}}
extraVariables:
aws_region: ${{ parameters.aws_region }}
instance_name: ${{ parameters.instance_name }}
key_name: ${{ parameters.key_name }}
vpc_name: ${{ parameters.vpc_name }}
output:
text:
- title: AWS Operations / Terminate EC2 Instance template executed
successfully
content: |
**Job ID:** ${{ steps['launch-job'].output.data.id }}
**Job STATUS:** ${{ steps['launch-job'].output.data.status }}
links:
- title: View in RH AAP
url: ${{ steps['launch-job'].output.data.url }}
Loading