kumogata-template 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kumogata/template/autoscaling.rb +65 -2
- data/lib/kumogata/template/cloudwatch.rb +21 -3
- data/lib/kumogata/template/const.rb +18 -0
- data/lib/kumogata/template/ec2.rb +89 -5
- data/lib/kumogata/template/emr.rb +20 -3
- data/lib/kumogata/template/ext/kumogata.rb +68 -0
- data/lib/kumogata/template/helper.rb +3 -10
- data/lib/kumogata/template/iam.rb +83 -4
- data/lib/kumogata/template/s3.rb +25 -0
- data/lib/kumogata/template/version.rb +1 -1
- data/template/autoscaling-group.rb +2 -2
- data/template/autoscaling-scaling-policy.rb +10 -9
- data/template/cloudwatch-alarm.rb +1 -1
- data/template/ec2-network-acl-entry.rb +4 -1
- data/template/elb-loadbalancer.rb +1 -1
- data/template/iam-group.rb +7 -2
- data/template/iam-role.rb +2 -2
- data/template/iam-user.rb +13 -3
- data/template/output-s3.rb +1 -1
- data/template/rds-db-instance.rb +2 -1
- data/template/s3-bucket-policy.rb +2 -2
- data/template/s3-bucket.rb +1 -5
- data/test/autoscaling_test.rb +3 -1
- data/test/ec2_test.rb +97 -0
- data/test/emr_test.rb +23 -2
- data/test/helper_test.rb +1 -1
- data/test/iam_test.rb +60 -1
- data/test/template/autoscaling-scaling-policy_test.rb +1 -0
- data/test/template/cloudwatch-alarm_test.rb +1 -1
- data/test/template/elb-loadbalancer_test.rb +1 -1
- data/test/template/output-s3_test.rb +0 -19
- data/test/template/rds-db-instance_test.rb +1 -0
- data/test/template/s3-bucket-policy_test.rb +2 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1522206975c39c028a0365c00c79cfc420ca51ca
|
4
|
+
data.tar.gz: b7667dc8232129044d0c49ae110fafe77cd87fcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a3062c2066bc965e6a3d0e16e7f573a966dadf62dcf021f5b4a44148df8eeb90f2ba744b633206acd8fc7121b740f88ee2cba9ff040774931893d556c55653
|
7
|
+
data.tar.gz: 71eb8ee86ad0648e6f5be552d5861d9b3a10b6372c68ff2c48d32320dfb1ddd3a24827b543296f0507d8987d97af152870cfff7ad8a7704395a9a8cb265ee8ad
|
@@ -3,6 +3,46 @@
|
|
3
3
|
#
|
4
4
|
require 'kumogata/template/helper'
|
5
5
|
|
6
|
+
def _autoscaling_to_adjustment(value)
|
7
|
+
return value if value.nil?
|
8
|
+
case value.downcase
|
9
|
+
when "change"
|
10
|
+
"ChangeInCapacity"
|
11
|
+
when "exact"
|
12
|
+
"ExactCapacity"
|
13
|
+
when "percent"
|
14
|
+
"PercentChangeInCapacity"
|
15
|
+
else
|
16
|
+
value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def _autoscaling_to_metric(value)
|
21
|
+
return value if value.nil?
|
22
|
+
case value.downcase
|
23
|
+
when "min"
|
24
|
+
"Minimum"
|
25
|
+
when "max"
|
26
|
+
"Maximum"
|
27
|
+
when "avg"
|
28
|
+
"Average"
|
29
|
+
else
|
30
|
+
value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def _autoscaling_to_policy(value)
|
35
|
+
return value if value.nil?
|
36
|
+
case value.downcase
|
37
|
+
when "simple"
|
38
|
+
"SimpleScaling"
|
39
|
+
when "step"
|
40
|
+
"StepScaling"
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
6
46
|
def _autoscaling_metrics
|
7
47
|
_{
|
8
48
|
Granularity "1Minute"
|
@@ -42,8 +82,8 @@ def _autoscaling_step(args)
|
|
42
82
|
scaling = args[:scaling] || 1
|
43
83
|
|
44
84
|
_{
|
45
|
-
MetricIntervalLowerBound lower unless lower.empty?
|
46
|
-
MetricIntervalUpperBound upper unless upper.empty?
|
85
|
+
MetricIntervalLowerBound lower unless lower.to_s.empty?
|
86
|
+
MetricIntervalUpperBound upper unless upper.to_s.empty?
|
47
87
|
ScalingAdjustment scaling
|
48
88
|
}
|
49
89
|
end
|
@@ -75,3 +115,26 @@ def _autoscaling_tags(args)
|
|
75
115
|
end
|
76
116
|
tags
|
77
117
|
end
|
118
|
+
|
119
|
+
def _autoscaling_terminations(args)
|
120
|
+
terminations = args[:terminations]
|
121
|
+
return [] if terminations.nil?
|
122
|
+
|
123
|
+
array = []
|
124
|
+
terminations.each do |termination|
|
125
|
+
array <<
|
126
|
+
case termination.downcase
|
127
|
+
when "old instance"
|
128
|
+
"OldestInstance"
|
129
|
+
when "new instance"
|
130
|
+
"NewestInstance"
|
131
|
+
when "old launch"
|
132
|
+
"OldestLaunchConfiguration"
|
133
|
+
when "close"
|
134
|
+
"ClosestToNextInstanceHour"
|
135
|
+
else
|
136
|
+
"Default"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
array
|
140
|
+
end
|
@@ -2,6 +2,24 @@
|
|
2
2
|
# Helper - CloudWatch
|
3
3
|
#
|
4
4
|
|
5
|
+
def _cloudwatch_to_statistic(value)
|
6
|
+
return value if value.nil?
|
7
|
+
case value.downcase
|
8
|
+
when "sample"
|
9
|
+
"SampleCount"
|
10
|
+
when "avg"
|
11
|
+
"Average"
|
12
|
+
when "Sum"
|
13
|
+
"Sum"
|
14
|
+
when "min"
|
15
|
+
"Minimum"
|
16
|
+
when "max"
|
17
|
+
"Maximum"
|
18
|
+
else
|
19
|
+
value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
5
23
|
def _cloudwatch_convert_operator(operator)
|
6
24
|
case operator
|
7
25
|
when ">="
|
@@ -9,13 +27,13 @@ def _cloudwatch_convert_operator(operator)
|
|
9
27
|
when ">"
|
10
28
|
"GreaterThanThreshold"
|
11
29
|
when "<="
|
12
|
-
"LessThanThreshold"
|
13
|
-
when "<"
|
14
30
|
"LessThanOrEqualToThreshold"
|
31
|
+
when "<"
|
32
|
+
"LessThanThreshold"
|
15
33
|
else
|
16
34
|
_valid_values(operator,
|
17
35
|
%w( GreaterThanOrEqualToThreshold GreaterThanThreshold
|
18
|
-
LessThanThreshold
|
36
|
+
LessThanOrEqualToThreshold LessThanThreshold ),
|
19
37
|
"GreaterThanThreshold")
|
20
38
|
end
|
21
39
|
end
|
@@ -13,6 +13,7 @@ AWS_REGION = {
|
|
13
13
|
sydney: "ap-southeast-2",
|
14
14
|
seoul: "ap-northeast-2",
|
15
15
|
saopaulo: "sa-east-1",
|
16
|
+
mumbai: "ap-south-1",
|
16
17
|
}
|
17
18
|
|
18
19
|
PORT = {
|
@@ -83,6 +84,10 @@ EC2_INSTANCE_TYPES =
|
|
83
84
|
# i2.4xlarge 16 122 4 x 800
|
84
85
|
# i2.8xlarge 32 244 8 x 800
|
85
86
|
"i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge",
|
87
|
+
|
88
|
+
# Model vCPU Mem (GiB) SSD Storage (GB) network Bandwidth
|
89
|
+
# x1.32xlargee 128 1,952 2 x 1,902 SSD 10 Gbps 10 Gbps
|
90
|
+
"x1.32xlarge",
|
86
91
|
]
|
87
92
|
EC2_DEFAULT_INSTANCE_TYPE = "t2.medium"
|
88
93
|
|
@@ -173,3 +178,16 @@ EMR_DEFAULT_INSTANCE_TYPE = "c4.large"
|
|
173
178
|
|
174
179
|
# http://docs.aws.amazon.com/ElasticMapReduce/latest/ReleaseGuide/emr-whatsnew.html
|
175
180
|
EMR_DEFAULT_RELEASE = "emr-4.6.0"
|
181
|
+
|
182
|
+
ELB_ACCESS_LOG_ACCOUNT_ID = {
|
183
|
+
"us-east-1": "127311923021",
|
184
|
+
"us-west-2": "797873946194",
|
185
|
+
"us-west-1": "027434742980",
|
186
|
+
"eu-west-1": "156460612806",
|
187
|
+
"eu-central-1": "054676820928",
|
188
|
+
"ap-southeast-1": "114774131450",
|
189
|
+
"ap-northeast-1": "582318560864",
|
190
|
+
"ap-southeast-2": "783225319266",
|
191
|
+
"ap-northeast-2": "600734575887",
|
192
|
+
"sa-east-1": "507241528517",
|
193
|
+
}
|
@@ -34,7 +34,7 @@ def _ec2_security_group_egress(args)
|
|
34
34
|
destination = _ref_string("destination", args, "security group")
|
35
35
|
from = _ref_string("from", args)
|
36
36
|
group = _ref_string("group", args, "security group")
|
37
|
-
ip = args[:
|
37
|
+
ip = args[:ip] || "tcp"
|
38
38
|
to = _ref_string("to", args)
|
39
39
|
from = to if from.empty?
|
40
40
|
|
@@ -63,12 +63,13 @@ def _ec2_security_group_ingress(args)
|
|
63
63
|
from = _ref_string("from", args)
|
64
64
|
group_id = _ref_string("group", args, "security group")
|
65
65
|
group_name = args[:group_name] || ""
|
66
|
-
ip = args[:
|
66
|
+
ip = args[:ip] || "tcp"
|
67
67
|
source_group_name = _ref_string("source_group_name", args, "security group")
|
68
68
|
source_group_id = _ref_string("source_group_id", args, "security group")
|
69
69
|
source_group_owner_id = _ref_string("source_group_owner_id", args, "account id")
|
70
70
|
to = _ref_string("to", args)
|
71
71
|
to = from if to.empty?
|
72
|
+
ip = -1 and from = 0 and to = 65535 if ip == "all"
|
72
73
|
|
73
74
|
_{
|
74
75
|
CidrIp cidr if source_group_name.empty? and source_group_id.empty?
|
@@ -109,12 +110,13 @@ def _ec2_block_device(args)
|
|
109
110
|
}
|
110
111
|
end
|
111
112
|
|
112
|
-
def _ec2_network_interface(args)
|
113
|
+
def _ec2_network_interface(args, is_spot = false)
|
113
114
|
associate_public = _bool("associate_public", args, true)
|
114
115
|
delete = _bool("delete", args, true)
|
115
116
|
description = args[:description] || ""
|
116
117
|
device = args[:device] || 0
|
117
118
|
group_set = _ref_array("group_set", args, "security group")
|
119
|
+
groups = _ref_array("groups", args, "security group")
|
118
120
|
network_interface = _ref_string("network", args)
|
119
121
|
private_ip = args[:private_ip] || ""
|
120
122
|
private_ips = args[:private_ips] || ""
|
@@ -126,9 +128,13 @@ def _ec2_network_interface(args)
|
|
126
128
|
DeleteOnTermination delete
|
127
129
|
Description description unless description.empty?
|
128
130
|
DeviceIndex device
|
129
|
-
|
131
|
+
if is_spot
|
132
|
+
Groups groups unless groups.empty?
|
133
|
+
else
|
134
|
+
GroupSet group_set unless group_set.empty?
|
135
|
+
end
|
130
136
|
NetworkInterfaceId network_interface unless network_interface.empty?
|
131
|
-
PrivateIpAddress private_ip
|
137
|
+
PrivateIpAddress private_ip if is_spot and !private_ip.empty?
|
132
138
|
PrivateIpAddresses private_ips unless private_ips.empty?
|
133
139
|
SecondaryPrivateIpAddressCount secondary_private_ip unless secondary_private_ip.empty?
|
134
140
|
SubnetId subnet
|
@@ -163,3 +169,81 @@ def _ec2_protocol_number(protocol)
|
|
163
169
|
-1
|
164
170
|
end
|
165
171
|
end
|
172
|
+
|
173
|
+
def _ec2_spot_fleet_request(args)
|
174
|
+
allocation = _valid_values(args[:allocation], %w( lowestPrice diversified), "lowestPrice")
|
175
|
+
express = _valid_values(args[:express], %w( noTermination default), "")
|
176
|
+
iam = args[:iam] # IAM Role "aws-ec2-spot-fleet-role" auto generated
|
177
|
+
launches = args[:launches].collect{|v| _ec2_spot_fleet_launches(v) }
|
178
|
+
price = args[:price] || 0.00
|
179
|
+
target = _ref_string("target", args, "")
|
180
|
+
target = 1 if target.empty?
|
181
|
+
terminate = _bool("terminate", args, false)
|
182
|
+
valid_from = (args.key? :valid_from) ? _timestamp_utc(args[:valid_from]) : ''
|
183
|
+
valid_until =
|
184
|
+
if args.key? :valid_until
|
185
|
+
_timestamp_utc(args[:valid_until])
|
186
|
+
elsif args.key? :valid_from
|
187
|
+
_timestamp_utc(args[:valid_from] + (60 * 60 * 24 * 365))
|
188
|
+
else
|
189
|
+
''
|
190
|
+
end
|
191
|
+
|
192
|
+
_{
|
193
|
+
AllocationStrategy allocation
|
194
|
+
ExcessCapacityTerminationPolicy express unless express.empty?
|
195
|
+
IamFleetRole iam
|
196
|
+
LaunchSpecifications launches
|
197
|
+
SpotPrice price
|
198
|
+
TargetCapacity target
|
199
|
+
TerminateInstancesWithExpiration terminate
|
200
|
+
ValidFrom valid_from if args.key? :valid_from
|
201
|
+
ValidUntil valid_until if args.key? :valid_from or args.key? :valid_until
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
def _ec2_spot_fleet_launches(args)
|
206
|
+
block_devices = (args[:block_devices] || []).collect{|v| _ec2_block_device(v) }
|
207
|
+
ebs = _bool("ebs", args, false)
|
208
|
+
iam = _ref_string("iam", args, "iam instance profile")
|
209
|
+
iam = _ref_attr_string("iam", "Arn", args, "iam instance profile") if iam.empty?
|
210
|
+
instance_type = _ref_string("instance_type", args, "instance type")
|
211
|
+
image =_ec2_image(instance_type, args)
|
212
|
+
kernel = args[:kernel] || ""
|
213
|
+
key_name = _ref_string("key_name", args, "key name")
|
214
|
+
monitoring = _bool("monitoring", args, false)
|
215
|
+
network_interfaces = (args[:network_interfaces] || []).collect{|v| _ec2_network_interface(v, true) }
|
216
|
+
placement = _ref_string("placement", args)
|
217
|
+
ram_disk = args[:ram_disk] || ""
|
218
|
+
security_groups = _ref_array("security_groups", args, "security group")
|
219
|
+
subnet = _ref_string("subnet", args, "subnet")
|
220
|
+
user_data = _ref_string("user_data", args, "user data")
|
221
|
+
weighted = args[:weighted] || ""
|
222
|
+
|
223
|
+
_{
|
224
|
+
BlockDeviceMappings block_devices unless block_devices.empty?
|
225
|
+
EbsOptimized ebs
|
226
|
+
IamInstanceProfile do
|
227
|
+
Arn iam
|
228
|
+
end unless iam.empty?
|
229
|
+
ImageId image
|
230
|
+
InstanceType instance_type
|
231
|
+
KernelId kernel unless kernel.empty?
|
232
|
+
KeyName key_name unless key_name.empty?
|
233
|
+
Monitoring do
|
234
|
+
Enabled monitoring
|
235
|
+
end
|
236
|
+
NetworkInterfaces network_interfaces unless network_interfaces.empty?
|
237
|
+
Placement placement unless placement.empty?
|
238
|
+
RamdiskId ram_disk unless ram_disk.empty?
|
239
|
+
SecurityGroups security_groups unless security_groups.empty?
|
240
|
+
SubnetId subnet unless subnet.empty?
|
241
|
+
UserData do
|
242
|
+
Fn__Base64 (<<-EOS).undent
|
243
|
+
#!/bin/bash
|
244
|
+
#{user_data}
|
245
|
+
EOS
|
246
|
+
end unless user_data.empty?
|
247
|
+
WeightedCapacity weighted if args.key? :weighted
|
248
|
+
}
|
249
|
+
end
|
@@ -42,11 +42,28 @@ def _emr_configurations(args)
|
|
42
42
|
array = []
|
43
43
|
configurations.each do |configuration|
|
44
44
|
classification = configuration[:classification] || ""
|
45
|
-
properties = configuration[:properties] ||
|
45
|
+
properties = configuration[:properties] || {}
|
46
|
+
configuring = _emr_configuring(configuration)
|
46
47
|
array << _{
|
47
48
|
Classification classification unless classification.empty?
|
48
|
-
ConfigurationProperties properties
|
49
|
-
|
49
|
+
ConfigurationProperties properties
|
50
|
+
Configurations configuring
|
51
|
+
}
|
52
|
+
end
|
53
|
+
array
|
54
|
+
end
|
55
|
+
|
56
|
+
def _emr_configuring(args)
|
57
|
+
configurations = args[:configurations] || []
|
58
|
+
|
59
|
+
array = []
|
60
|
+
configurations.each do |configuration|
|
61
|
+
classification = configuration[:classification] || ""
|
62
|
+
properties = configuration[:properties] || {}
|
63
|
+
array << _{
|
64
|
+
Classification classification unless classification.empty?
|
65
|
+
ConfigurationProperties properties
|
66
|
+
Configurations []
|
50
67
|
}
|
51
68
|
end
|
52
69
|
array
|
@@ -100,4 +100,72 @@ class Kumogata::Client
|
|
100
100
|
template_path = File.join(template_path, "#{file}.rb") unless file.nil?
|
101
101
|
template_path
|
102
102
|
end
|
103
|
+
|
104
|
+
def evaluate_template(template, path_or_url)
|
105
|
+
key_converter = proc do |key|
|
106
|
+
key = key.to_s
|
107
|
+
unless @options.skip_replace_underscore?
|
108
|
+
key.gsub!('_', ':')
|
109
|
+
key.gsub!('__', '::')
|
110
|
+
end
|
111
|
+
key
|
112
|
+
end
|
113
|
+
|
114
|
+
value_converter = proc do |v|
|
115
|
+
case v
|
116
|
+
when Hash, Array
|
117
|
+
v
|
118
|
+
else
|
119
|
+
v.to_s
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
template = Dslh.eval(template.read, {
|
124
|
+
:key_conv => key_converter,
|
125
|
+
:value_conv => value_converter,
|
126
|
+
:scope_hook => proc {|scope|
|
127
|
+
define_template_func(scope, path_or_url)
|
128
|
+
},
|
129
|
+
:filename => path_or_url,
|
130
|
+
})
|
131
|
+
|
132
|
+
@outputs_filter.fetch!(template)
|
133
|
+
@post_processing.fetch!(template)
|
134
|
+
|
135
|
+
return template
|
136
|
+
end
|
137
|
+
|
138
|
+
def devaluate_template(template)
|
139
|
+
exclude_key = proc do |k|
|
140
|
+
k = k.to_s.gsub('::', '__')
|
141
|
+
k !~ /\A[_a-z]\w+\Z/i and k !~ %r|\A/\S*\Z|
|
142
|
+
end
|
143
|
+
|
144
|
+
key_conv = proc do |k|
|
145
|
+
k = k.to_s
|
146
|
+
|
147
|
+
if k =~ %r|\A/\S*\Z|
|
148
|
+
proc do |v, nested|
|
149
|
+
if nested
|
150
|
+
"_path(#{k.inspect}) #{v}"
|
151
|
+
else
|
152
|
+
"_path #{k.inspect}, #{v}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
else
|
156
|
+
k.gsub(':', '_')
|
157
|
+
k.gsub('::', '__')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
value_conv = proc do |v|
|
162
|
+
if v.kind_of?(String) and v =~ /\A(?:0|[1-9]\d*)\Z/
|
163
|
+
v.to_i
|
164
|
+
else
|
165
|
+
v
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
Dslh.deval(template, :key_conv => key_conv, :value_conv => value_conv, :exclude_key => exclude_key)
|
170
|
+
end
|
103
171
|
end
|
@@ -164,19 +164,12 @@ def _availability_zones(args, use_subnet = true)
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
def _timestamp_utc(
|
168
|
-
time
|
169
|
-
if year.nil?
|
170
|
-
Time.now
|
171
|
-
else
|
172
|
-
Time.local(year, month, day, hour, min)
|
173
|
-
end
|
174
|
-
time.utc.strftime("%Y-%m-%dT%H:%M:00Z")
|
167
|
+
def _timestamp_utc(time = Time.now)
|
168
|
+
time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
175
169
|
end
|
176
170
|
|
177
171
|
def _timestamp_utc_from_string(time)
|
178
|
-
|
179
|
-
_timestamp_utc(time.year, time.month, time.day, time.hour, time.min)
|
172
|
+
_timestamp_utc(Time.strptime(time, "%Y-%m-%d %H:%M"))
|
180
173
|
end
|
181
174
|
|
182
175
|
def _maintenance_window(service, start_time)
|
@@ -3,6 +3,19 @@
|
|
3
3
|
#
|
4
4
|
require 'kumogata/template/helper'
|
5
5
|
|
6
|
+
def _iam_to_policy(value)
|
7
|
+
case value
|
8
|
+
when 'admin'
|
9
|
+
'AdministratorAccess'
|
10
|
+
when 'power'
|
11
|
+
'PowerUserAccess'
|
12
|
+
when 'readonly'
|
13
|
+
'ReadOnlyAccess'
|
14
|
+
else
|
15
|
+
value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
6
19
|
def _iam_policies(name, args)
|
7
20
|
array = []
|
8
21
|
policies = args["#{name}".to_sym] || []
|
@@ -45,12 +58,35 @@ def _iam_policy_document(name, args)
|
|
45
58
|
array
|
46
59
|
end
|
47
60
|
|
48
|
-
def _iam_assume_role_policy_document(
|
61
|
+
def _iam_assume_role_policy_document(args)
|
62
|
+
aws =
|
63
|
+
if args.key? :aws
|
64
|
+
_iam_arn("iam", args[:aws])
|
65
|
+
else
|
66
|
+
""
|
67
|
+
end
|
68
|
+
service = args[:service] || ""
|
69
|
+
condition =
|
70
|
+
if args.key? :external_id
|
71
|
+
true
|
72
|
+
else
|
73
|
+
false
|
74
|
+
end
|
75
|
+
external_id = args[:external_id] || ""
|
76
|
+
|
49
77
|
[
|
50
78
|
_{
|
51
79
|
Effect "Allow"
|
52
|
-
Principal _{
|
80
|
+
Principal _{
|
81
|
+
AWS aws unless aws.empty?
|
82
|
+
Service [ "#{service}.amazonaws.com" ] unless service.empty?
|
83
|
+
}
|
53
84
|
Action [ "sts:AssumeRole" ]
|
85
|
+
Condition _{
|
86
|
+
StringEquals _{
|
87
|
+
sts_ExternalId external_id unless external_id.empty?
|
88
|
+
}
|
89
|
+
} if condition
|
54
90
|
}
|
55
91
|
]
|
56
92
|
end
|
@@ -85,12 +121,55 @@ def _iam_arn(service, resource)
|
|
85
121
|
|
86
122
|
when "iam"
|
87
123
|
if resource.key? :sts
|
88
|
-
"arn:aws:sts::#{account_id}:#{resource[:type]}/#{resource[:user]}"
|
124
|
+
"arn:aws:sts::#{resource[:account_id]}:#{resource[:type]}/#{resource[:user]}"
|
125
|
+
elsif resource.key? :policy
|
126
|
+
"arn:aws:iam::aws:policy/#{_iam_to_policy(resource[:policy])}"
|
127
|
+
elsif resource.key? :root
|
128
|
+
"#{arn_prefix}::#{resource[:account_id]}:root"
|
89
129
|
else
|
90
|
-
"#{arn_prefix}::#{account_id}:#{resource[:type]}/#{resource[:user]}"
|
130
|
+
"#{arn_prefix}::#{resource[:account_id]}:#{resource[:type]}/#{resource[:user]}"
|
91
131
|
end
|
92
132
|
|
93
133
|
when "elasticloadbalancing"
|
94
134
|
"#{arn_prefix}:*:*:loadbalancer/#{resource}"
|
135
|
+
|
136
|
+
when "logs"
|
137
|
+
"#{arn_prefix}:*:*:*"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def _iam_s3_bucket_policy(region, bucket, prefix, aws_account_id)
|
142
|
+
account_id = ELB_ACCESS_LOG_ACCOUNT_ID[region.to_sym]
|
143
|
+
prefix = [ prefix ] if prefix.is_a? String
|
144
|
+
resource = prefix.collect{|v| "#{bucket}/#{v}/AWSLogs/#{aws_account_id}/*" }
|
145
|
+
[
|
146
|
+
{
|
147
|
+
service: "s3",
|
148
|
+
action: [ "PutObject" ],
|
149
|
+
principal: {
|
150
|
+
"AWS": [ account_id ],
|
151
|
+
},
|
152
|
+
resource: resource,
|
153
|
+
},
|
154
|
+
]
|
155
|
+
end
|
156
|
+
|
157
|
+
def _iam_login_profile(args)
|
158
|
+
password = args[:password] || ""
|
159
|
+
reset_required = _bool("reset_required", args, true)
|
160
|
+
|
161
|
+
_{
|
162
|
+
Password password
|
163
|
+
PasswordResetRequired reset_required
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
def _iam_managed_policies(args)
|
168
|
+
arns = args[:managed_policies]
|
169
|
+
|
170
|
+
array = []
|
171
|
+
arns.each do |v|
|
172
|
+
array << _iam_arn("iam", { policy: v })
|
95
173
|
end
|
174
|
+
array
|
96
175
|
end
|
data/lib/kumogata/template/s3.rb
CHANGED
@@ -3,6 +3,31 @@
|
|
3
3
|
#
|
4
4
|
require 'kumogata/template/helper'
|
5
5
|
|
6
|
+
def _s3_to_access(value)
|
7
|
+
return "Private" if value.nil?
|
8
|
+
|
9
|
+
case value
|
10
|
+
when "auth"
|
11
|
+
"AuthenticatedRead"
|
12
|
+
when "aws_exec"
|
13
|
+
"AwsExecRead"
|
14
|
+
when "owner"
|
15
|
+
"BucketOwnerRead"
|
16
|
+
when "owner_full"
|
17
|
+
"BucketOwnerFullControl"
|
18
|
+
when "log_delivery_w"
|
19
|
+
"LogDeliveryWrite"
|
20
|
+
when "private"
|
21
|
+
"Private"
|
22
|
+
when "public_r"
|
23
|
+
"PublicRead"
|
24
|
+
when "public_rw"
|
25
|
+
"PublicReadWrite"
|
26
|
+
else
|
27
|
+
value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
6
31
|
def _s3_cors(args)
|
7
32
|
rules = args[:cors] || []
|
8
33
|
|
@@ -1 +1 @@
|
|
1
|
-
KUMOGATA_TEMPLATE_VERSION = '0.0.
|
1
|
+
KUMOGATA_TEMPLATE_VERSION = '0.0.4'
|
@@ -21,7 +21,7 @@ max = min if max < min
|
|
21
21
|
notifications = (args[:notifications] || []).collect{|v| _autoscaling_notification(v) }
|
22
22
|
placement = args[:placement] || ""
|
23
23
|
tags = _autoscaling_tags(args)
|
24
|
-
|
24
|
+
terminations = _autoscaling_terminations(args)
|
25
25
|
vpc_zones = _ref_array("vpc_zones", args, "subnet")
|
26
26
|
|
27
27
|
_(name) do
|
@@ -41,7 +41,7 @@ _(name) do
|
|
41
41
|
NotificationConfigurations notifications
|
42
42
|
PlacementGroup placement unless placement.empty?
|
43
43
|
Tags tags
|
44
|
-
TerminationPolicies
|
44
|
+
TerminationPolicies terminations unless terminations.empty?
|
45
45
|
VPCZoneIdentifier vpc_zones unless vpc_zones.empty?
|
46
46
|
end
|
47
47
|
end
|
@@ -3,31 +3,32 @@
|
|
3
3
|
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-policy.html
|
4
4
|
#
|
5
5
|
require 'kumogata/template/helper'
|
6
|
+
require 'kumogata/template/autoscaling'
|
6
7
|
|
7
8
|
name = _resource_name(args[:name], "autoscaling scaling policy")
|
8
|
-
adjustment = _valid_values(args[:adjustment],
|
9
|
+
adjustment = _valid_values(_autoscaling_to_adjustment(args[:adjustment]),
|
9
10
|
%w( ChangeInCapacity ExactCapacity PercentChangeInCapacity ),
|
10
11
|
"ChangeInCapacity")
|
11
12
|
autoscaling = _ref_string("autoscaling", args, "autoscaling group")
|
12
|
-
cooldown = args[:cooldown] ||
|
13
|
+
cooldown = args[:cooldown] || "60"
|
13
14
|
estimated = args[:estimated] || ""
|
14
|
-
metric = _valid_values(args[:metric], %w( Minimum Maximum Average ), "Average")
|
15
|
+
metric = _valid_values(_autoscaling_to_metric(args[:metric]), %w( Minimum Maximum Average ), "Average")
|
15
16
|
min = args[:min] || ""
|
16
|
-
policy = _valid_values(args[:policy], %w( SimpleScaling StepScaling ), "SimpleScaling")
|
17
|
+
policy = _valid_values(_autoscaling_to_policy(args[:policy]), %w( SimpleScaling StepScaling ), "SimpleScaling")
|
17
18
|
scaling = args[:scaling] || 1
|
18
|
-
|
19
|
+
steps = (args[:steps] || []).collect{|v| _autoscaling_step(v) }
|
19
20
|
|
20
21
|
_(name) do
|
21
22
|
Type "AWS::AutoScaling::ScalingPolicy"
|
22
23
|
Properties do
|
23
24
|
AdjustmentType adjustment
|
24
25
|
AutoScalingGroupName autoscaling
|
25
|
-
Cooldown cooldown unless
|
26
|
+
Cooldown cooldown unless policy == "StepScaling"
|
26
27
|
EstimatedInstanceWarmup estimated unless estimated.empty?
|
27
28
|
MetricAggregationType metric unless policy == "SimpleScaling"
|
28
|
-
MinAdjustmentMagnitude min
|
29
|
+
MinAdjustmentMagnitude min if policy == "PercentChangeInCapacity"
|
29
30
|
PolicyType policy
|
30
|
-
ScalingAdjustment scaling
|
31
|
-
StepAdjustments
|
31
|
+
ScalingAdjustment scaling if policy == "SimpleScaling"
|
32
|
+
StepAdjustments steps unless steps.empty?
|
32
33
|
end
|
33
34
|
end
|
@@ -18,7 +18,7 @@ metric = args[:metric]
|
|
18
18
|
namespace = args[:namespace]
|
19
19
|
ok_actions = args[:ok_actions] || []
|
20
20
|
period = args[:period] || 60
|
21
|
-
statistic = _valid_values(args[:statistic],
|
21
|
+
statistic = _valid_values(_cloudwatch_to_statistic(args[:statistic]),
|
22
22
|
%w(SampleCount Average Sum Minimum Maximum), "Average")
|
23
23
|
threshold = args[:threshold] || 60
|
24
24
|
unit = _valid_values(args[:unit], %w(Seconds Microseconds Milliseconds Bytes Kilobytes Megabytes Gigabytes Terabytes Bits Kilobits Megabits Gigabits Terabits Percent Count Bytes/Second Kilobytes/Second Megabytes/Second Gigabytes/Second Terabytes/Second Bits/Second Kilobits/Second Megabits/Second Gigabits/Second Terabits/Second Count/Second None), "")
|
@@ -21,7 +21,10 @@ _(name) do
|
|
21
21
|
Properties do
|
22
22
|
CidrBlock cidr
|
23
23
|
Egress egress
|
24
|
-
Icmp
|
24
|
+
Icmp _{
|
25
|
+
Code -1
|
26
|
+
Type -1
|
27
|
+
} if protocol == 1
|
25
28
|
NetworkAclId network_acl
|
26
29
|
PortRange port_range if protocol == -1 or protocol == 6 or protocol == 17
|
27
30
|
Protocol protocol
|
@@ -11,7 +11,7 @@ app_cookie = _elb_app_cookie_stickiness_policy(args)
|
|
11
11
|
azs = _availability_zones(args, false)
|
12
12
|
connection_draining = _elb_connection_draining_policy(args)
|
13
13
|
connection_setting = _elb_connection_settings(args)
|
14
|
-
cross = _bool("cross", args,
|
14
|
+
cross = _bool("cross", args, true)
|
15
15
|
health = _elb_health_check(args)
|
16
16
|
instances = _ref_array("instances", args, "instance")
|
17
17
|
cookie = _elb_cookie_stickiness_policy(args)
|
data/template/iam-group.rb
CHANGED
@@ -6,14 +6,19 @@ require 'kumogata/template/helper'
|
|
6
6
|
require 'kumogata/template/iam'
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "group")
|
9
|
-
|
9
|
+
managed_policies =
|
10
|
+
if args.key? :managed_policies
|
11
|
+
_iam_managed_policies(args)
|
12
|
+
else
|
13
|
+
[]
|
14
|
+
end
|
10
15
|
path = args[:path] || "/"
|
11
16
|
policies = _iam_policies("policies", args)
|
12
17
|
|
13
18
|
_(name) do
|
14
19
|
Type "AWS::IAM::Group"
|
15
20
|
Properties do
|
16
|
-
ManagedPolicyArns
|
21
|
+
ManagedPolicyArns managed_policies unless managed_policies.empty?
|
17
22
|
Path path
|
18
23
|
Policies policies unless policies.empty?
|
19
24
|
end
|
data/template/iam-role.rb
CHANGED
@@ -6,7 +6,7 @@ require 'kumogata/template/helper'
|
|
6
6
|
require 'kumogata/template/iam'
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "role")
|
9
|
-
|
9
|
+
policy = _iam_assume_role_policy_document(args)
|
10
10
|
path = args[:path] || "/"
|
11
11
|
|
12
12
|
_(name) do
|
@@ -14,7 +14,7 @@ _(name) do
|
|
14
14
|
Properties do
|
15
15
|
AssumeRolePolicyDocument do
|
16
16
|
Version "2012-10-17"
|
17
|
-
Statement
|
17
|
+
Statement policy
|
18
18
|
end
|
19
19
|
Path path
|
20
20
|
end
|
data/template/iam-user.rb
CHANGED
@@ -7,8 +7,18 @@ require 'kumogata/template/iam'
|
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "user")
|
9
9
|
group = _ref_array("group", args)
|
10
|
-
login_profile =
|
11
|
-
|
10
|
+
login_profile =
|
11
|
+
if args.key? :login_profile
|
12
|
+
_iam_login_profile(args[:login_profile])
|
13
|
+
else
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
managed_policies =
|
17
|
+
if args.key? :managed_policies
|
18
|
+
_iam_managed_policies(args)
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
12
22
|
path = args[:path] || "/"
|
13
23
|
policies = _iam_policies("policies", args)
|
14
24
|
|
@@ -17,7 +27,7 @@ _(name) do
|
|
17
27
|
Properties do
|
18
28
|
Group group unless group.empty?
|
19
29
|
LoginProfile login_profile unless login_profile.empty?
|
20
|
-
ManagedPolicyArns
|
30
|
+
ManagedPolicyArns managed_policies unless managed_policies.empty?
|
21
31
|
Path path
|
22
32
|
Policies policies unless policies.empty?
|
23
33
|
end
|
data/template/output-s3.rb
CHANGED
@@ -4,5 +4,5 @@
|
|
4
4
|
|
5
5
|
bucket = "#{args[:name]} bucket"
|
6
6
|
|
7
|
-
_output "#{bucket} s3 domain name", ref_value: [ bucket, "DomainName" ]
|
7
|
+
_output "#{bucket} s3 domain name", ref_value: [ bucket, "DomainName" ]
|
8
8
|
_output "#{bucket} s3 web site url", ref_value: [ bucket, "WebsiteURL" ]
|
data/template/rds-db-instance.rb
CHANGED
@@ -40,6 +40,7 @@ maintenance = _maintenance_window("rds", args[:maintenance] || DEFAULT_MAINTENAN
|
|
40
40
|
publicly = _bool("publicly", args, false)
|
41
41
|
source_db = _ref_string("source_db", args, "db source db")
|
42
42
|
storage_encrypted = _bool("encrypted", args, false)
|
43
|
+
storage_type = _valid_values(args[:storage_type], %w( standard gp2 io1 ), "gp2")
|
43
44
|
tags = _tags(args)
|
44
45
|
security_groups = _ref_array("security_groups", args, "security group")
|
45
46
|
|
@@ -75,7 +76,7 @@ _(name) do
|
|
75
76
|
PubliclyAccessible publicly
|
76
77
|
SourceDBInstanceIdentifier source_db unless source_db.empty?
|
77
78
|
StorageEncrypted storage_encrypted if storage_encrypted == true
|
78
|
-
|
79
|
+
StorageType storage_type
|
79
80
|
Tags tags
|
80
81
|
VPCSecurityGroups security_groups unless security_groups.empty?
|
81
82
|
end
|
@@ -6,12 +6,12 @@ require 'kumogata/template/helper'
|
|
6
6
|
require 'kumogata/template/iam'
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "bucket policy")
|
9
|
-
bucket =
|
9
|
+
bucket = _ref_string("bucket", args, "bucket")
|
10
10
|
|
11
11
|
_(name) do
|
12
12
|
Type "AWS::S3::BucketPolicy"
|
13
13
|
Properties do
|
14
|
-
|
14
|
+
Bucket bucket
|
15
15
|
PolicyDocument do
|
16
16
|
Version "2012-10-17"
|
17
17
|
Statement _iam_policy_document("policy_document", args)
|
data/template/s3-bucket.rb
CHANGED
@@ -6,11 +6,7 @@ require 'kumogata/template/helper'
|
|
6
6
|
require 'kumogata/template/s3'
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "bucket")
|
9
|
-
access =
|
10
|
-
%w( AuthenticatedRead AwsExecRead BucketOwnerRead
|
11
|
-
BucketOwnerFullControl LogDeliveryWrite
|
12
|
-
Private PublicRead PublicReadWrite ),
|
13
|
-
"Private")
|
9
|
+
access = _s3_to_access(args[:access])
|
14
10
|
access = "PublicRead" if args.key? :website
|
15
11
|
bucket = _ref_name("bucket", args)
|
16
12
|
cors = _s3_cors(args)
|
data/test/autoscaling_test.rb
CHANGED
@@ -51,12 +51,14 @@ Test _autoscaling_notification(topic_arn: "test")
|
|
51
51
|
|
52
52
|
def test_autoscaling_step
|
53
53
|
template = <<-EOS
|
54
|
-
Test _autoscaling_step(scaling: 10)
|
54
|
+
Test _autoscaling_step(scaling: 10, lower: 0, upper: 20)
|
55
55
|
EOS
|
56
56
|
act_template = run_client_as_json(template)
|
57
57
|
exp_template = <<-EOS
|
58
58
|
{
|
59
59
|
"Test": {
|
60
|
+
"MetricIntervalLowerBound": "0",
|
61
|
+
"MetricIntervalUpperBound": "20",
|
60
62
|
"ScalingAdjustment": "10"
|
61
63
|
}
|
62
64
|
}
|
data/test/ec2_test.rb
CHANGED
@@ -279,6 +279,103 @@ Test _ec2_port_range({})
|
|
279
279
|
"From": "0",
|
280
280
|
"To": "65535"
|
281
281
|
}
|
282
|
+
}
|
283
|
+
EOS
|
284
|
+
assert_equal exp_template.chomp, act_template
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_ec2_spot_fleet_request
|
288
|
+
template = <<-EOS
|
289
|
+
Test _ec2_spot_fleet_request({ iam: "test", launches: [] })
|
290
|
+
EOS
|
291
|
+
act_template = run_client_as_json(template)
|
292
|
+
exp_template = <<-EOS
|
293
|
+
{
|
294
|
+
"Test": {
|
295
|
+
"AllocationStrategy": "lowestPrice",
|
296
|
+
"IamFleetRole": "test",
|
297
|
+
"LaunchSpecifications": [
|
298
|
+
|
299
|
+
],
|
300
|
+
"SpotPrice": "0.0",
|
301
|
+
"TargetCapacity": "1",
|
302
|
+
"TerminateInstancesWithExpiration": "false"
|
303
|
+
}
|
304
|
+
}
|
305
|
+
EOS
|
306
|
+
assert_equal exp_template.chomp, act_template
|
307
|
+
|
308
|
+
template = <<-EOS
|
309
|
+
Test _ec2_spot_fleet_request({ iam: "test", launches: [ { image_id: "test", instance_type: "test" } ] })
|
310
|
+
EOS
|
311
|
+
act_template = run_client_as_json(template)
|
312
|
+
exp_template = <<-EOS
|
313
|
+
{
|
314
|
+
"Test": {
|
315
|
+
"AllocationStrategy": "lowestPrice",
|
316
|
+
"IamFleetRole": "test",
|
317
|
+
"LaunchSpecifications": [
|
318
|
+
{
|
319
|
+
"EbsOptimized": "false",
|
320
|
+
"ImageId": "test",
|
321
|
+
"InstanceType": "test",
|
322
|
+
"Monitoring": {
|
323
|
+
"Enabled": "false"
|
324
|
+
}
|
325
|
+
}
|
326
|
+
],
|
327
|
+
"SpotPrice": "0.0",
|
328
|
+
"TargetCapacity": "1",
|
329
|
+
"TerminateInstancesWithExpiration": "false"
|
330
|
+
}
|
331
|
+
}
|
332
|
+
EOS
|
333
|
+
assert_equal exp_template.chomp, act_template
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_ec2_spot_fleet_launches
|
337
|
+
template = <<-EOS
|
338
|
+
Test _ec2_spot_fleet_launches({ block_devices: [ { ref_size: "test" } ], iam: "test", image_id: "test", ref_instance_type: "test", ref_key_name: "test", network_interfaces: [ { ref_subnet_id: "test" } ] } )
|
339
|
+
EOS
|
340
|
+
act_template = run_client_as_json(template)
|
341
|
+
exp_template = <<-EOS
|
342
|
+
{
|
343
|
+
"Test": {
|
344
|
+
"BlockDeviceMappings": [
|
345
|
+
{
|
346
|
+
"DeviceName": "/dev/sda1",
|
347
|
+
"Ebs": {
|
348
|
+
"DeleteOnTermination": "true",
|
349
|
+
"VolumeSize": {
|
350
|
+
"Ref": "TestVolumeSize"
|
351
|
+
},
|
352
|
+
"VolumeType": "gp2"
|
353
|
+
}
|
354
|
+
}
|
355
|
+
],
|
356
|
+
"EbsOptimized": "false",
|
357
|
+
"IamInstanceProfile": {
|
358
|
+
"Arn": "test"
|
359
|
+
},
|
360
|
+
"ImageId": "test",
|
361
|
+
"InstanceType": {
|
362
|
+
"Ref": "TestInstanceType"
|
363
|
+
},
|
364
|
+
"KeyName": {
|
365
|
+
"Ref": "TestKeyName"
|
366
|
+
},
|
367
|
+
"Monitoring": {
|
368
|
+
"Enabled": "false"
|
369
|
+
},
|
370
|
+
"NetworkInterfaces": [
|
371
|
+
{
|
372
|
+
"AssociatePublicIpAddress": "true",
|
373
|
+
"DeleteOnTermination": "true",
|
374
|
+
"DeviceIndex": "0",
|
375
|
+
"SubnetId": ""
|
376
|
+
}
|
377
|
+
]
|
378
|
+
}
|
282
379
|
}
|
283
380
|
EOS
|
284
381
|
assert_equal exp_template.chomp, act_template
|
data/test/emr_test.rb
CHANGED
@@ -42,14 +42,35 @@ Test _emr_bootstraps(bootstraps: [ { name: "test", script_path: "test" } ])
|
|
42
42
|
|
43
43
|
def test_emr_configurations
|
44
44
|
template = <<-EOS
|
45
|
-
|
45
|
+
configuration = {
|
46
|
+
classification: "test",
|
47
|
+
properties: {},
|
48
|
+
configurations: [
|
49
|
+
classification: "export",
|
50
|
+
properties: { JAVA_HOME: "/usr/java/default" },
|
51
|
+
],
|
52
|
+
}
|
53
|
+
Test _emr_configurations(configurations: [ configuration ] )
|
46
54
|
EOS
|
47
55
|
act_template = run_client_as_json(template)
|
48
56
|
exp_template = <<-EOS
|
49
57
|
{
|
50
58
|
"Test": [
|
51
59
|
{
|
52
|
-
"Classification": "test"
|
60
|
+
"Classification": "test",
|
61
|
+
"ConfigurationProperties": {
|
62
|
+
},
|
63
|
+
"Configurations": [
|
64
|
+
{
|
65
|
+
"Classification": "export",
|
66
|
+
"ConfigurationProperties": {
|
67
|
+
"JAVA_HOME": "/usr/java/default"
|
68
|
+
},
|
69
|
+
"Configurations": [
|
70
|
+
|
71
|
+
]
|
72
|
+
}
|
73
|
+
]
|
53
74
|
}
|
54
75
|
]
|
55
76
|
}
|
data/test/helper_test.rb
CHANGED
@@ -520,7 +520,7 @@ Test _availability_zones({})
|
|
520
520
|
end
|
521
521
|
|
522
522
|
def test_timestamp_utc
|
523
|
-
assert_equal _timestamp_utc(2016, 4, 1), "2016-03-31T15:00:00Z"
|
523
|
+
assert_equal _timestamp_utc(Time.local(2016, 4, 1)), "2016-03-31T15:00:00Z"
|
524
524
|
end
|
525
525
|
|
526
526
|
def test_timestamp_utc_from_string
|
data/test/iam_test.rb
CHANGED
@@ -55,7 +55,7 @@ PolicyDocument _iam_policy_document "test", test: [ { service: "s3" } ]
|
|
55
55
|
|
56
56
|
def test_iam_assume_role_policy_document
|
57
57
|
template = <<-EOS
|
58
|
-
Statement _iam_assume_role_policy_document("ec2")
|
58
|
+
Statement _iam_assume_role_policy_document({ service: "ec2" })
|
59
59
|
EOS
|
60
60
|
act_template = run_client_as_json(template)
|
61
61
|
exp_template = <<-EOS
|
@@ -86,6 +86,65 @@ arn _iam_arn("s3", "test")
|
|
86
86
|
exp_template = <<-EOS
|
87
87
|
{
|
88
88
|
"arn": "arn:aws:s3:::test"
|
89
|
+
}
|
90
|
+
EOS
|
91
|
+
assert_equal exp_template.chomp, act_template
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_iam_s3_bucket_policy
|
95
|
+
template = <<-EOS
|
96
|
+
arn _iam_s3_bucket_policy("us_east1", "test", "test", 1234)
|
97
|
+
EOS
|
98
|
+
act_template = run_client_as_json(template)
|
99
|
+
exp_template = <<-EOS
|
100
|
+
{
|
101
|
+
"arn": [
|
102
|
+
{
|
103
|
+
"service": "s3",
|
104
|
+
"action": [
|
105
|
+
"PutObject"
|
106
|
+
],
|
107
|
+
"principal": {
|
108
|
+
"AWS": [
|
109
|
+
null
|
110
|
+
]
|
111
|
+
},
|
112
|
+
"resource": [
|
113
|
+
"test/test/AWSLogs/1234/*"
|
114
|
+
]
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
EOS
|
119
|
+
assert_equal exp_template.chomp, act_template
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_iam_login_profile
|
123
|
+
template = <<-EOS
|
124
|
+
profile _iam_login_profile(password: "test")
|
125
|
+
EOS
|
126
|
+
act_template = run_client_as_json(template)
|
127
|
+
exp_template = <<-EOS
|
128
|
+
{
|
129
|
+
"profile": {
|
130
|
+
"Password": "test",
|
131
|
+
"PasswordResetRequired": "true"
|
132
|
+
}
|
133
|
+
}
|
134
|
+
EOS
|
135
|
+
assert_equal exp_template.chomp, act_template
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_iam_managed_policies
|
139
|
+
template = <<-EOS
|
140
|
+
managed _iam_managed_policies(managed_policies: %w( admin ))
|
141
|
+
EOS
|
142
|
+
act_template = run_client_as_json(template)
|
143
|
+
exp_template = <<-EOS
|
144
|
+
{
|
145
|
+
"managed": [
|
146
|
+
"arn:aws:iam::aws:policy/AdministratorAccess"
|
147
|
+
]
|
89
148
|
}
|
90
149
|
EOS
|
91
150
|
assert_equal exp_template.chomp, act_template
|
@@ -16,7 +16,7 @@ _cloudwatch_alarm "test", actions: "test", alarm_name: "test", namespace: "test"
|
|
16
16
|
"test"
|
17
17
|
],
|
18
18
|
"AlarmName": "test",
|
19
|
-
"ComparisonOperator": "
|
19
|
+
"ComparisonOperator": "LessThanThreshold",
|
20
20
|
"Dimensions": [
|
21
21
|
{
|
22
22
|
"Name": "test",
|
@@ -2,25 +2,6 @@ require 'abstract_unit'
|
|
2
2
|
|
3
3
|
class OutputS3Test < Minitest::Test
|
4
4
|
def test_normal
|
5
|
-
template = <<-EOS
|
6
|
-
_output_s3 "test"
|
7
|
-
EOS
|
8
|
-
act_template = run_client_as_json(template)
|
9
|
-
exp_template = <<-EOS
|
10
|
-
{
|
11
|
-
"TestBucketS3WebSiteUrl": {
|
12
|
-
"Description": "description of TestBucketS3WebSiteUrl",
|
13
|
-
"Value": {
|
14
|
-
"Fn::GetAtt": [
|
15
|
-
"TestBucket",
|
16
|
-
"WebsiteURL"
|
17
|
-
]
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}
|
21
|
-
EOS
|
22
|
-
assert_equal exp_template.chomp, act_template
|
23
|
-
|
24
5
|
template = <<-EOS
|
25
6
|
_output_s3 "test", domain: true
|
26
7
|
EOS
|
@@ -51,6 +51,7 @@ _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group
|
|
51
51
|
"PreferredBackupWindow": "21:30-22:00",
|
52
52
|
"PreferredMaintenanceWindow": "Thu:20:30-Thu:21:00",
|
53
53
|
"PubliclyAccessible": "false",
|
54
|
+
"StorageType": "gp2",
|
54
55
|
"Tags": [
|
55
56
|
{
|
56
57
|
"Key": "Name",
|
@@ -4,7 +4,7 @@ class S3BucketPolicyTest < Minitest::Test
|
|
4
4
|
def test_normal
|
5
5
|
template = <<-EOS
|
6
6
|
policy = {}
|
7
|
-
_s3_bucket_policy "test", policy_document: policy
|
7
|
+
_s3_bucket_policy "test", bucket: "test", policy_document: policy
|
8
8
|
EOS
|
9
9
|
act_template = run_client_as_json(template)
|
10
10
|
exp_template = <<-EOS
|
@@ -12,19 +12,7 @@ _s3_bucket_policy "test", policy_document: policy
|
|
12
12
|
"TestBucketPolicy": {
|
13
13
|
"Type": "AWS::S3::BucketPolicy",
|
14
14
|
"Properties": {
|
15
|
-
"
|
16
|
-
"Fn::Join": [
|
17
|
-
"-",
|
18
|
-
[
|
19
|
-
{
|
20
|
-
"Ref": "Service"
|
21
|
-
},
|
22
|
-
{
|
23
|
-
"Ref": "Name"
|
24
|
-
}
|
25
|
-
]
|
26
|
-
]
|
27
|
-
},
|
15
|
+
"Bucket": "test",
|
28
16
|
"PolicyDocument": {
|
29
17
|
"Version": "2012-10-17",
|
30
18
|
"Statement": [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumogata-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoya Nakazawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|