From ba81f541d74ef697364e2b8d83472975a76620a4 Mon Sep 17 00:00:00 2001 From: Justin Cinkelj Date: Mon, 9 Dec 2024 10:34:57 +0100 Subject: [PATCH 1/6] TEMP use fork Signed-off-by: Justin Cinkelj --- extensions/patterns/configure_ec2/setup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml index c0d5484b..ac47b396 100644 --- a/extensions/patterns/configure_ec2/setup.yml +++ b/extensions/patterns/configure_ec2/setup.yml @@ -12,12 +12,12 @@ controller_labels: controller_projects: - name: AWS Operations / Configure EC2 Instance Pattern Project organization: "{{ organization | default('Default') }}" - scm_branch: main + scm_branch: backstage-templates scm_clean: false scm_delete_on_update: false scm_type: git scm_update_on_launch: true - scm_url: https://github.com/redhat-cop/cloud.aws_ops.git + scm_url: https://github.com/kcagran/cloud.aws_ops.git controller_templates: - name: AWS Operations / Create EC2 Instance From 852838b4424531b5ee4479d88d9622cefee4ed84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20=C4=8Cagran?= Date: Tue, 10 Dec 2024 06:59:26 +0100 Subject: [PATCH 2/6] Add backstage templates --- .../template_rhdh/configure_ec2.yml | 0 .../template_rhdh/create_ec2_instance.yml | 185 ++++++++++++++++++ .../template_rhdh/terminate_ec2_instance.yml | 108 ++++++++++ 3 files changed, 293 insertions(+) delete mode 100644 extensions/patterns/configure_ec2/template_rhdh/configure_ec2.yml create mode 100644 extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml create mode 100644 extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml diff --git a/extensions/patterns/configure_ec2/template_rhdh/configure_ec2.yml b/extensions/patterns/configure_ec2/template_rhdh/configure_ec2.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml new file mode 100644 index 00000000..c682b374 --- /dev/null +++ b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml @@ -0,0 +1,185 @@ +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 the nodes this job will be ran + against. You can only select one credential of each type. For + machine credentials (SSH), checking "Prompt on launch" without + selecting credentials will require you to select a machine + credential at run time. If you select credentials and check "Prompt + on launch", the selected credential(s) become the defaults that can + be updated at run time. + 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 + 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 or create for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' + 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: + - "" + - '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: + 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 }} diff --git a/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml new file mode 100644 index 00000000..006dc441 --- /dev/null +++ b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml @@ -0,0 +1,108 @@ +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 the nodes this job will be ran + against. You can only select one credential of each type. For + machine credentials (SSH), checking "Prompt on launch" without + selecting credentials will require you to select a machine + credential at run time. If you select credentials and check "Prompt + on launch", the selected credential(s) become the defaults that can + be updated at run time. + 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 created + type: string + ui:options: + rows: 5 + instance_name: + title: Instance Name + description: Name of EC2 instance to create + type: string + ui:options: + rows: 5 + key_name: + title: Key Pair Name + description: Name of key pair to use or create for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' + 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 + 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 }} From 542f7939335c8aea1704bfe9f6169b2bc7a3230f Mon Sep 17 00:00:00 2001 From: Justin Cinkelj Date: Thu, 12 Dec 2024 14:14:49 +0100 Subject: [PATCH 3/6] Revert "TEMP use fork" This reverts commit ba81f541d74ef697364e2b8d83472975a76620a4. --- extensions/patterns/configure_ec2/setup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/patterns/configure_ec2/setup.yml b/extensions/patterns/configure_ec2/setup.yml index ac47b396..c0d5484b 100644 --- a/extensions/patterns/configure_ec2/setup.yml +++ b/extensions/patterns/configure_ec2/setup.yml @@ -12,12 +12,12 @@ controller_labels: controller_projects: - name: AWS Operations / Configure EC2 Instance Pattern Project organization: "{{ organization | default('Default') }}" - scm_branch: backstage-templates + scm_branch: main scm_clean: false scm_delete_on_update: false scm_type: git scm_update_on_launch: true - scm_url: https://github.com/kcagran/cloud.aws_ops.git + scm_url: https://github.com/redhat-cop/cloud.aws_ops.git controller_templates: - name: AWS Operations / Create EC2 Instance From 0e564449cf4dbd22a1ad1b727896309ac68135b6 Mon Sep 17 00:00:00 2001 From: Justin Cinkelj Date: Thu, 12 Dec 2024 16:15:07 +0100 Subject: [PATCH 4/6] Update credentials description Signed-off-by: Justin Cinkelj --- .../configure_ec2/template_rhdh/create_ec2_instance.yml | 9 ++------- .../template_rhdh/terminate_ec2_instance.yml | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml index c682b374..b776696f 100644 --- a/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml @@ -36,13 +36,8 @@ spec: ui:field: AAPResourcePicker credentials: title: Credentials - description: Select credentials for accessing the nodes this job will be ran - against. You can only select one credential of each type. For - machine credentials (SSH), checking "Prompt on launch" without - selecting credentials will require you to select a machine - credential at run time. If you select credentials and check "Prompt - on launch", the selected credential(s) become the defaults that can - be updated at run time. + description: Select credentials for accessing AWS. + The credentials need to be of type "Amazon Web Services". type: array ui:field: AAPResourcePicker resource: credentials diff --git a/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml index 006dc441..0c52a299 100644 --- a/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml @@ -36,13 +36,8 @@ spec: ui:field: AAPResourcePicker credentials: title: Credentials - description: Select credentials for accessing the nodes this job will be ran - against. You can only select one credential of each type. For - machine credentials (SSH), checking "Prompt on launch" without - selecting credentials will require you to select a machine - credential at run time. If you select credentials and check "Prompt - on launch", the selected credential(s) become the defaults that can - be updated at run time. + description: Select credentials for accessing AWS. + The credentials need to be of type "Amazon Web Services". type: array ui:field: AAPResourcePicker resource: credentials From 07f0517d5a8aae7540a51a7b26db21ecf355bc20 Mon Sep 17 00:00:00 2001 From: Justin Cinkelj Date: Thu, 12 Dec 2024 16:15:25 +0100 Subject: [PATCH 5/6] Update description - delete vs create Signed-off-by: Justin Cinkelj --- .../template_rhdh/terminate_ec2_instance.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml index 0c52a299..b6303720 100644 --- a/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/template_rhdh/terminate_ec2_instance.yml @@ -54,25 +54,25 @@ spec: properties: aws_region: title: AWS Region - description: AWS region where resources should be created + 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 create + 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 use or create for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' + description: Name of key pair to delete for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' type: string ui:options: rows: 5 vpc_name: title: VPC Name - description: Name of the VPC to create. Defaults to '{{instance_name}}-vpc' + description: Name of the VPC to delete. Defaults to '{{instance_name}}-vpc' type: string ui:options: rows: 5 From 3cc1222ceebfa9e0bf6e73a98d398e2d918073f4 Mon Sep 17 00:00:00 2001 From: Justin Cinkelj Date: Mon, 16 Dec 2024 07:49:59 +0100 Subject: [PATCH 6/6] Update extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml Co-authored-by: Helen Bailey --- .../configure_ec2/template_rhdh/create_ec2_instance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml index b776696f..cf39f919 100644 --- a/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml +++ b/extensions/patterns/configure_ec2/template_rhdh/create_ec2_instance.yml @@ -79,7 +79,7 @@ spec: rows: 5 key_name: title: Key Pair Name - description: Name of key pair to use or create for SSH access to the EC2 instance. Defaults to '{{ instance_name }}-key' + 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