forked from stelligent/cloud-custodian-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
100 lines (95 loc) · 2.51 KB
/
template.yml
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
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
Subnet:
DependsOn: VPC
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.0.0/24
User:
Type: AWS::IAM::User
Properties:
Path: "/"
Policies:
- PolicyName: root
PolicyDocument:
Statement:
- Effect: Allow
Action: "*"
Resource: "*"
Keys:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref User
DirtyInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-22ce4934
Tags:
- Key: Name
Value: Dirty Instance
- Key: DirtyInstance
Value: yup
CustodianInstance:
Type: AWS::EC2::Instance
DependsOn:
- User
- Keys
- Subnet
- SecurityGroup
- DirtyInstance
Metadata:
AWS::CloudFormation::Init:
config:
files:
/root/custodian.yml:
mode: "000644"
owner: "root"
group: "root"
content: !Sub |
---
policies:
- name: keep-instance-policy
resource: ec2
filters:
- "tag:DirtyInstance": present
actions:
- terminate
/root/.aws/credentials:
mode: "000644"
owner: "root"
group: "root"
content: !Sub |
[default]
aws_access_key_id=${Keys}
aws_secret_access_key=${Keys.SecretAccessKey}
/root/.aws/config:
mode: "000644"
owner: "root"
group: "root"
content: !Sub |
[default]
region=us-east-1
commands:
1-virtualenv:
command: "virtualenv custodian"
cwd: "~"
2-source:
command: "source custodian/bin/activate && pip install c7n && custodian run --output-dir=. /root/custodian.yml"
cwd: "~"
Properties:
SubnetId: !Ref Subnet
InstanceType: t2.micro
ImageId: ami-22ce4934
Tags:
- Key: Name
Value: Custodian Instance
UserData:
Fn::Base64: !Sub |
#!/bin/bash -v
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -s ${AWS::StackId} -r CustodianInstance --region ${AWS::Region}