-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathdeploy.template.yaml
More file actions
158 lines (155 loc) · 5.81 KB
/
Copy pathdeploy.template.yaml
File metadata and controls
158 lines (155 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
AWSTemplateFormatVersion: "2010-09-09"
Description: "deploy the AWSQS::Kubernetes::Helm resource into CloudFormation registry"
Resources:
ExecutionRole:
Type: AWS::IAM::Role
Properties:
MaxSessionDuration: 8400
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- "lambda.amazonaws.com"
- "resources.cloudformation.amazonaws.com"
Action: sts:AssumeRole
Path: "/"
Policies:
- PolicyName: ResourceTypePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "secretsmanager:GetSecretValue"
- "kms:Decrypt"
- "eks:DescribeCluster"
- "s3:GetObject"
- "sts:AssumeRole"
- "iam:PassRole"
- "iam:ListRolePolicies"
- "iam:ListAttachedRolePolicies"
- "iam:GetRole"
- "iam:GetPolicy"
- "iam:GetPolicyVersion"
- "ec2:CreateNetworkInterface"
- "ec2:DeleteNetworkInterface"
- "ec2:Describe*"
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- "lambda:*"
Resource: "*"
LogDeliveryRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- cloudformation.amazonaws.com
- resources.cloudformation.amazonaws.com
Action: sts:AssumeRole
Path: "/"
Policies:
- PolicyName: ResourceTypePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:DescribeLogGroups"
- "logs:DescribeLogStreams"
- "logs:PutLogEvents"
- "cloudwatch:ListMetrics"
- "cloudwatch:PutMetricData"
Resource: "*"
RegisterTypeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
Policies:
- PolicyName: ResourceTypePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "cloudformation:*"
- "iam:PassRole"
Resource: "*"
RegisterTypeFunction:
Type: "AWS::Lambda::Function"
Properties:
Timeout: 900
Runtime: python3.7
Handler: index.handler
Role: !GetAtt RegisterTypeRole.Arn
Code:
ZipFile: !Sub |
import cfnresponse
import logging
import boto3
from time import sleep
def stabilize(token, cfn):
p = cfn.describe_type_registration(RegistrationToken=token)
while p['ProgressStatus'] == "IN_PROGRESS":
sleep(5)
p = cfn.describe_type_registration(RegistrationToken=token)
if p['ProgressStatus'] == 'FAILED':
logging.error(p)
return cfnresponse.FAILED, p['TypeVersionArn']
return cfnresponse.SUCCESS, p['TypeVersionArn']
def register(cfn):
response = cfn.register_type(
Type='RESOURCE',
TypeName='AWSQS::Kubernetes::Helm',
SchemaHandlerPackage="s3://aws-quickstart/quickstart-helm-resource-provider/awsqs-kubernetes-helm.zip",
LoggingConfig={"LogRoleArn": "${LogDeliveryRole.Arn}", "LogGroupName": "awsqs-kubernetes-helm-logs"},
ExecutionRoleArn="${ExecutionRole.Arn}"
)
status, version_arn = stabilize(response['RegistrationToken'], cfn)
cfn.set_type_default_version(Arn=version_arn)
return status, version_arn
def handler(event, context):
print(event)
status = cfnresponse.SUCCESS
physical_id = event.get('PhysicalResourceId')
try:
cfn = boto3.client('cloudformation')
if event['RequestType'] == 'Create':
status, physical_id = register(cfn)
if event['RequestType'] == 'Update':
status, physical_id = register(cfn)
if event['RequestType'] == 'Delete':
versions = cfn.list_type_versions(Type='RESOURCE', TypeName='AWSQS::Kubernetes::Helm')['TypeVersionSummaries']
if len(versions) > 1:
cfn.deregister_type(Arn=physical_id)
else:
cfn.deregister_type(Type='RESOURCE', TypeName='AWSQS::Kubernetes::Helm')
except Exception:
logging.error('Unhandled exception', exc_info=True)
status = cfnresponse.FAILED
finally:
cfnresponse.send(event, context, status, {}, physicalResourceId=physical_id)
RegisterType:
Type: "AWS::CloudFormation::CustomResource"
Properties:
ServiceToken: !GetAtt RegisterTypeFunction.Arn
Outputs:
ExecutionRoleArn:
Value: !GetAtt ExecutionRole.Arn