Skip to content

Instantly share code, notes, and snippets.

@Sigler
Last active August 3, 2021 17:32
Show Gist options
  • Save Sigler/6ea9fb12e79a760bfc0611f4df200f08 to your computer and use it in GitHub Desktop.
Save Sigler/6ea9fb12e79a760bfc0611f4df200f08 to your computer and use it in GitHub Desktop.
summary: Remove unused EC2 key pairs
workflow-loop:
# only showing 5 of 500
- set: prod
variables:
awsRegion: us-east-1
parameters:
- connection: aws-prod-cac
awsRegion: {{awsRegion}}
- connection: aws-prod-euc
awsRegion: {{awsRegion}}
- connection: aws-prod-euw1
awsRegion: {{awsRegion}}
- connection: aws-prod-euw2
awsRegion: {{awsRegion}}
- connection: aws-prod-apne
awsRegion: {{awsRegion}}
- set: dev
- connection: aws-dev-foo
awsRegion: us-west-1
- connection: aws-dev-bar
awsRegion: us-east-1
parameters:
connection:
description: The target account
default:
awsRegion:
description: The AWS region to run in
default: us-east-1
dryRun:
description: True if you dont want to actually delete the resources. Use this to test the workflow and ensure it is behaving as expected.
default: 'true'
triggers:
- name: schedule
source:
type: schedule
schedule: '0 * * * *'
binding:
parameters:
awsRegion: {{awsRegion}}
dryRun: true
steps:
- name: describe-instances
image: relaysh/aws-ec2-step-instances-describe
spec:
aws:
connection: ${parameters.connection}
# connection: ${connections.aws.{{my-aws-account}}}
region: ${parameters.{{awsRegion}}}
- name: describe-key-pairs
image: relaysh/aws-ec2-step-key-pairs-describe
spec:
connection: ${connections.aws.{{my-aws-account}}}
region: ${parameters.{{awsRegion}}}
- name: filter-key-pairs
image: relaysh/core:latest-python
spec:
instances: !Output {from: describe-instances, name: instances}
keyPairs: !Output { from: describe-key-pairs, name: keyPairs}
inputFile: https://raw.githubusercontent.com/puppetlabs/relay-workflows/master/ec2-remove-unused-key-pairs/filter-key-pairs.py
- name: approval
description: Wait for approval to delete key pairs
type: approval
dependsOn: filter-key-pairs
when: ${parameters.dryrun == 'false'}
- name: delete-key-pairs
dependsOn: approval
image: relaysh/aws-ec2-step-key-pairs-delete
when: ${parameters.dryrun == 'false'}
spec:
aws:
# This uses a separate connection named awsAdmin. What kind of issues does this surface?
connection: ${connections.aws.awsAdmin}
region: ${parameters.{{awsRegion}}}
keyPairNames: !Output {from: filter-key-pairs, name: keyPairNames}
@Sigler
Copy link
Author

Sigler commented Aug 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment