Skip to content

Commit

Permalink
Merge pull request #119 from tremble/launch_template
Browse files Browse the repository at this point in the history
Support for EC2 Launch Templates
  • Loading branch information
jillr authored Dec 14, 2020
2 parents a578710 + 5d7a74f commit 0095d5e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions aws/policy/compute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ Statement:
- ec2:AttachVolume
- ec2:CreateImage
- ec2:CreateKeyPair
- ec2:CreateLaunchTemplate
- ec2:CreateLaunchTemplateVersion
- ec2:CreateSnapshot
- ec2:CreateTags
- ec2:CreateTransitGateway
- ec2:DeleteKeyPair
- ec2:DeleteLaunchTemplate
- ec2:DeleteLaunchTemplateVersions
- ec2:DeleteSnapshot
- ec2:DeleteTags
- ec2:DeleteTransitGateway
Expand All @@ -72,15 +76,19 @@ Statement:
- ec2:DescribeInstances
- ec2:DescribeInstanceStatus
- ec2:DescribeKeyPairs
- ec2:DescribeLaunchTemplates
- ec2:DescribeLaunchTemplateVersions
- ec2:DescribeRegions
- ec2:DescribeSnapshots
- ec2:DescribeTags
- ec2:DescribeVolumes
- ec2:DetachVolume
- ec2:DisassociateIamInstanceProfile
- ec2:GetLaunchTemplateData
- ec2:ImportKeyPair
- ec2:ModifyImageAttribute
- ec2:ModifyInstanceAttribute
- ec2:ModifyLaunchTemplate
- ec2:ModifyVolume
- ec2:RegisterImage
- ec2:ReplaceIamInstanceProfileAssociation
Expand Down
26 changes: 26 additions & 0 deletions aws/terminator/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,29 @@ def terminate(self):
except botocore.exceptions.ClientError as ex:
if not ex.response['Error']['Code'] == 'ResourceInUseFault':
raise


class LaunchTemplate(Terminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials,
LaunchTemplate,
'ec2',
lambda client: client.describe_launch_templates()['LaunchTemplates']
)

@property
def id(self):
return self.instance['LaunchTemplateId']

@property
def name(self):
return self.instance['LaunchTemplateName']

@property
def created_time(self):
return self.instance['CreateTime']

def terminate(self):
self.client.delete_launch_template(LaunchTemplateId=self.id)
3 changes: 0 additions & 3 deletions hacking/aws_config/test_policies/compute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ Statement:
- Sid: AllowGlobalUnrestrictedResourceActionsWhichIncurFees
Effect: Allow
Action:
- ec2:*LaunchTemplate
- ec2:*LaunchTemplateVersion
- ec2:*LaunchTemplateVersions
- ec2:ReportInstanceStatus
- SNS:ListSubscriptions
- SNS:SetTopicAttributes
Expand Down

0 comments on commit 0095d5e

Please sign in to comment.