Skip to content

Commit

Permalink
Terminator policies for CloudFront modules
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Nov 15, 2022
1 parent 488530e commit c9a638e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
24 changes: 24 additions & 0 deletions aws/policy/application-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ Statement:
- cloudformation:SetStackPolicy
- cloudformation:UpdateStack
- cloudformation:UpdateTerminationProtection
- cloudfront:CreateDistribution
- cloudfront:CreateDistributionWithTags
- cloudfront:DeleteDistribution
- cloudfront:UpdateDistribution
- cloudfront:GetDistribution
- cloudfront:GetDistributionConfig
- cloudfront:GetStreamingDistribution
- cloudfront:GetStreamingDistributionConfig
- cloudfront:ListCloudFrontOriginAccessIdentities
- cloudfront:ListDistributions
- cloudfront:ListDistributionsByWebACLId
- cloudfront:ListStreamingDistributions
- cloudfront:CreateCloudFrontOriginAccessIdentity
- cloudfront:DeleteCloudFrontOriginAccessIdentity
- cloudfront:GetCloudFrontOriginAccessIdentity
- cloudfront:GetCloudFrontOriginAccessIdentityConfig
- cloudfront:UpdateCloudFrontOriginAccessIdentity
- cloudfront:GetInvalidation
- cloudfront:CreateInvalidation
- cloudfront:TagResource
- cloudfront:UntagResource
- cloudfront:ListTagsForResource
- cloudfront:DeleteStreamingDistribution
- cloudwatch:DeleteAlarms
- cloudwatch:DescribeAlarms
- cloudwatch:PutMetricAlarm
Expand Down Expand Up @@ -167,6 +190,7 @@ Statement:
Resource:
- 'arn:aws:ssm:{{ aws_region }}:{{ aws_account_id }}:document/*'
- 'arn:aws:cloudformation:{{ aws_region }}:{{ aws_account_id }}:stack/*'
- 'arn:aws:cloudfront::{{ aws_account_id }}:distribution/*'
- 'arn:aws:cloudwatch:{{ aws_region }}:{{ aws_account_id }}:alarm:*'
- 'arn:aws:codebuild:{{ aws_region }}:{{ aws_account_id }}:*'
- 'arn:aws:codecommit:{{ aws_region }}:{{ aws_account_id }}:*'
Expand Down
38 changes: 38 additions & 0 deletions aws/terminator/application_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,41 @@ def name(self):

def terminate(self):
self.client.delete_document(Name=self.name)


class CloudFrontDistribution(Terminator):
@staticmethod
def create(credentials):
def paginate_distributions(client):
return client.get_paginator('list_distributions').paginate().build_full_result()['DistributionList']['Items']
return Terminator._create(credentials, CloudFrontDistribution, 'cloudfront', paginate_distributions)

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

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

def terminate(self):
self.client.delete_distribution(Id=self.instance['Id'])


class CloudFrontStreamingDistribution(Terminator):
@staticmethod
def create(credentials):
def paginate_streaming_distributions(client):
return client.get_paginator('list_streaming_distributions').paginate().build_full_result()['StreamingDistributionList']['Items']
return Terminator._create(credentials, CloudFrontStreamingDistribution, 'cloudfront', paginate_streaming_distributions)

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

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

def terminate(self):
self.client.delete_streaming_distribution(Id=self.instance['Id'])

0 comments on commit c9a638e

Please sign in to comment.