kumogata-template 0.0.15 → 0.0.16
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/.gitignore +2 -1
- data/.travis.yml +1 -1
- data/Gemfile.lock +44 -21
- data/README.md +10 -1
- data/bin/kumogata-template +2 -2
- data/kumogata-template.gemspec +5 -6
- data/lib/kumogata/template.rb +3 -0
- data/lib/kumogata/template/codebuild.rb +86 -0
- data/lib/kumogata/template/codecommit.rb +20 -0
- data/lib/kumogata/template/ec2.rb +1 -1
- data/lib/kumogata/template/elb.rb +4 -1
- data/lib/kumogata/template/ext/argument_parser.rb +8 -0
- data/lib/kumogata/template/ext/kumogata.rb +41 -40
- data/lib/kumogata/template/ext/option_parser.rb +6 -0
- data/lib/kumogata/template/helper.rb +17 -11
- data/lib/kumogata/template/iam.rb +3 -0
- data/lib/kumogata/template/lambda.rb +5 -0
- data/lib/kumogata/template/logs.rb +18 -0
- data/lib/kumogata/template/sns.rb +21 -12
- data/lib/kumogata/template/version.rb +1 -1
- data/template/codebuild-project.rb +32 -0
- data/template/codecommit-repository.rb +20 -0
- data/template/ecs-cluster.rb +5 -1
- data/template/ecs-task-definition.rb +7 -1
- data/template/elasticache-replication-group.rb +2 -0
- data/template/elasticache-subnet-group.rb +2 -0
- data/template/kms-alias.rb +17 -0
- data/template/kms-key.rb +25 -0
- data/template/lambda-function.rb +2 -0
- data/template/logs-destination.rb +26 -0
- data/template/logs-log-group.rb +18 -0
- data/template/logs-log-stream.rb +18 -0
- data/template/logs-metric-filter.rb +21 -0
- data/template/logs-subscription_filter.rb +24 -0
- data/template/rds-db-instance.rb +6 -0
- data/template/s3-bucket-policy.rb +3 -2
- data/template/s3-bucket.rb +1 -1
- data/template/sns-subscription.rb +20 -0
- data/template/sns-topic.rb +1 -1
- data/test/abstract_unit.rb +8 -26
- data/test/codebuild_test.rb +76 -0
- data/test/elb_test.rb +44 -0
- data/test/logs_test.rb +23 -0
- data/test/s3_test.rb +0 -1
- data/test/sns_test.rb +1 -1
- data/test/template/codebuild-project_test.rb +72 -0
- data/test/template/codecommit-repository_test.rb +21 -0
- data/test/template/codedeploy-application_test.rb +1 -1
- data/test/template/ec2-network-acl-entry_test.rb +2 -2
- data/test/template/ecs-cluster_test.rb +5 -2
- data/test/template/elasticache-replication-group_test.rb +29 -1
- data/test/template/emr-cluster_test.rb +1 -1
- data/test/template/iam-managed-policy_test.rb +1 -1
- data/test/template/iam-policy_test.rb +1 -1
- data/test/template/kms-alias_test.rb +22 -0
- data/test/template/kms-key_test.rb +36 -0
- data/test/template/logs-destination_test.rb +37 -0
- data/test/template/logs-log-group_test.rb +34 -0
- data/test/template/logs-log-stream_test.rb +46 -0
- data/test/template/logs-metric-filter_test.rb +41 -0
- data/test/template/logs-subscription-filter_test.rb +36 -0
- data/test/template/rds-event-subscription_test.rb +1 -1
- data/test/template/sns-subscription_test.rb +28 -0
- metadata +52 -28
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Logs subscription filter resource
|
3
|
+
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html
|
4
|
+
#
|
5
|
+
require 'kumogata/template/helper'
|
6
|
+
require 'kumogata/template/logs'
|
7
|
+
|
8
|
+
name = _resource_name(args[:name], "logs subscription filter")
|
9
|
+
dest = _ref_attr_string("dest", "Arn", args, "role")
|
10
|
+
# Filter and Pattern Syntax
|
11
|
+
# http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
|
12
|
+
pattern = args[:pattern]
|
13
|
+
group = _ref_name("group", args)
|
14
|
+
role = _ref_attr_string("role", "Arn", args, "role")
|
15
|
+
|
16
|
+
_(name) do
|
17
|
+
Type "AWS::Logs::SubscriptionFilter"
|
18
|
+
Properties do
|
19
|
+
DestinationArn dest
|
20
|
+
FilterPattern pattern
|
21
|
+
LogGroupName group
|
22
|
+
RoleArn role
|
23
|
+
end
|
24
|
+
end
|
data/template/rds-db-instance.rb
CHANGED
@@ -26,6 +26,8 @@ parameter = "default.mysql5.7" if parameter.empty?
|
|
26
26
|
security = _ref_array("security_groups", args, "security group")
|
27
27
|
subnet_group = _ref_string("subnet_group", args, "db subnet group")
|
28
28
|
snapshot = _ref_string("snapshot", args, "db snapshot")
|
29
|
+
domain = args[:domain] || ""
|
30
|
+
domain_iam = args[:domain_iam] || ""
|
29
31
|
engine_version = _ref_string("engine_version", args, "db engine version")
|
30
32
|
engine_version = RDS_DEFAULT_ENGINE_VERSION[engine.to_sym] if engine_version.empty?
|
31
33
|
iops = args[:iops] || ""
|
@@ -42,6 +44,7 @@ source_db = _ref_string("source_db", args, "db source db")
|
|
42
44
|
storage_encrypted = _bool("encrypted", args, false)
|
43
45
|
storage_type = _valid_values(args[:storage_type], %w( standard gp2 io1 ), "gp2")
|
44
46
|
tags = _tags(args)
|
47
|
+
timezone = args[:timezone] || ""
|
45
48
|
security_groups = _ref_array("security_groups", args, "security group")
|
46
49
|
|
47
50
|
_(name) do
|
@@ -61,6 +64,8 @@ _(name) do
|
|
61
64
|
DBSecurityGroups security if security_groups.empty?
|
62
65
|
DBSnapshotIdentifier snapshot unless snapshot.empty?
|
63
66
|
DBSubnetGroupName subnet_group
|
67
|
+
Domain domain unless domain.empty? and engine !~ /sqlserver/
|
68
|
+
DomainIAMRoleName domain_iam unless domain_iam.empty? and engine !~ /sqlserver/
|
64
69
|
Engine engine
|
65
70
|
EngineVersion engine_version
|
66
71
|
Iops iops unless iops.empty?
|
@@ -78,6 +83,7 @@ _(name) do
|
|
78
83
|
StorageEncrypted storage_encrypted if storage_encrypted == true
|
79
84
|
StorageType storage_type
|
80
85
|
Tags tags
|
86
|
+
Timezone timezone unless timezone.empty?
|
81
87
|
VPCSecurityGroups security_groups unless security_groups.empty?
|
82
88
|
end
|
83
89
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# S3
|
2
|
+
# S3 Bucket Policy resource
|
3
3
|
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-policy.html
|
4
4
|
#
|
5
5
|
require 'kumogata/template/helper'
|
@@ -7,6 +7,7 @@ require 'kumogata/template/iam'
|
|
7
7
|
|
8
8
|
name = _resource_name(args[:name], "bucket policy")
|
9
9
|
bucket = _ref_string("bucket", args, "bucket")
|
10
|
+
policy = _iam_policy_document("policy_document", args)
|
10
11
|
|
11
12
|
_(name) do
|
12
13
|
Type "AWS::S3::BucketPolicy"
|
@@ -14,7 +15,7 @@ _(name) do
|
|
14
15
|
Bucket bucket
|
15
16
|
PolicyDocument do
|
16
17
|
Version "2012-10-17"
|
17
|
-
Statement
|
18
|
+
Statement policy
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/template/s3-bucket.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# SNS Subscription resource
|
3
|
+
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html
|
4
|
+
#
|
5
|
+
require 'kumogata/template/helper'
|
6
|
+
require 'kumogata/template/sns'
|
7
|
+
|
8
|
+
name = _resource_name(args[:name], "sns subscription")
|
9
|
+
protocol = _sns_to_protocol(args[:protocol])
|
10
|
+
endpoint = _sns_to_endpoint(protocol, args[:endpoint])
|
11
|
+
topic = _ref_attr_string("topic", "Arn", args, "topic")
|
12
|
+
|
13
|
+
_(name) do
|
14
|
+
Type "AWS::SNS::Subscription"
|
15
|
+
Properties do
|
16
|
+
Endpoint endpoint
|
17
|
+
Protocol protocol
|
18
|
+
TopicArn topic
|
19
|
+
end
|
20
|
+
end
|
data/template/sns-topic.rb
CHANGED
data/test/abstract_unit.rb
CHANGED
@@ -1,24 +1,13 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'kumogata2/plugin/ruby'
|
2
|
+
require 'kumogata'
|
3
|
+
require 'kumogata/argument_parser'
|
5
4
|
require 'json'
|
6
5
|
require 'tempfile'
|
7
6
|
|
8
7
|
# for only test
|
9
8
|
ENV['TZ'] = 'Asia/Tokyo'
|
10
9
|
|
11
|
-
class
|
12
|
-
include Kumogata2::Logger::Helper
|
13
|
-
|
14
|
-
def initialize(options)
|
15
|
-
@options = options.kind_of?(Hashie::Mash) ? options : Hashie::Mash.new(options)
|
16
|
-
@plugin_by_ext = {}
|
17
|
-
## Do not initialize AWS client
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Kumogata2::Plugin::Ruby::Context
|
10
|
+
class Kumogata::Client
|
22
11
|
def define_template_func(scope, path_or_url)
|
23
12
|
functions = ""
|
24
13
|
Dir.glob("template/*.rb").all? do |file|
|
@@ -84,11 +73,6 @@ def tempfile(content, template_ext = nil)
|
|
84
73
|
basename = "#{File.basename __FILE__}.#{$$}"
|
85
74
|
basename = [basename, template_ext] if template_ext
|
86
75
|
|
87
|
-
content = <<EOS
|
88
|
-
template do
|
89
|
-
#{content}
|
90
|
-
end
|
91
|
-
EOS
|
92
76
|
Tempfile.open(basename) do |f|
|
93
77
|
f << content
|
94
78
|
f.flush
|
@@ -100,16 +84,14 @@ end
|
|
100
84
|
def run_client(template)
|
101
85
|
$stdout = open('/dev/null', 'w') unless ENV['DEBUG']
|
102
86
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
options[:result_log] = '/dev/null'
|
108
|
-
options[:command_result_log] = '/dev/null'
|
87
|
+
kumogata_options = Kumogata::ArgumentParser::DEFAULT_OPTIONS
|
88
|
+
kumogata_options[:output_format] = 'json'
|
89
|
+
kumogata_options[:result_log] = '/dev/null'
|
90
|
+
kumogata_options[:command_result_log] = '/dev/null'
|
109
91
|
template_ext = '.rb'
|
110
92
|
|
111
93
|
template = tempfile(template, template_ext) do |f|
|
112
|
-
|
94
|
+
Kumogata::Client.new(kumogata_options).send(:evaluate_template, f, f.path)
|
113
95
|
end
|
114
96
|
end
|
115
97
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'kumogata/template/codebuild'
|
3
|
+
|
4
|
+
class CodebuildTest < Minitest::Test
|
5
|
+
def test_codebuild_artifacts
|
6
|
+
template = <<-EOS
|
7
|
+
Test _codebuild_artifacts({})
|
8
|
+
EOS
|
9
|
+
act_template = run_client_as_json(template)
|
10
|
+
exp_template = <<-EOS
|
11
|
+
{
|
12
|
+
"Test": {
|
13
|
+
"Type": "no_artifacts"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
EOS
|
17
|
+
assert_equal exp_template.chomp, act_template
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_codebuild_environment
|
21
|
+
template = <<-EOS
|
22
|
+
Test _codebuild_environement({ compute: "large", env: { test: "test" }, image: "test" })
|
23
|
+
EOS
|
24
|
+
act_template = run_client_as_json(template)
|
25
|
+
exp_template = <<-EOS
|
26
|
+
{
|
27
|
+
"Test": {
|
28
|
+
"ComputeType": "BUILD_GENERAL1_LARGE",
|
29
|
+
"EnvironmentVariables": [
|
30
|
+
{
|
31
|
+
"Name": "test",
|
32
|
+
"Value": "test"
|
33
|
+
}
|
34
|
+
],
|
35
|
+
"Image": "test",
|
36
|
+
"Type": "LINUX_CONTAINER"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
EOS
|
40
|
+
assert_equal exp_template.chomp, act_template
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_codebuild_environment_hash
|
44
|
+
template = <<-EOS
|
45
|
+
Test _codebuild_environement_hash({ test: "test" })
|
46
|
+
EOS
|
47
|
+
act_template = run_client_as_json(template)
|
48
|
+
exp_template = <<-EOS
|
49
|
+
{
|
50
|
+
"Test": [
|
51
|
+
{
|
52
|
+
"Name": "test",
|
53
|
+
"Value": "test"
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
57
|
+
EOS
|
58
|
+
assert_equal exp_template.chomp, act_template
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_codebuild_source
|
62
|
+
template = <<-EOS
|
63
|
+
Test _codebuild_source({ type: "github", location: "test" })
|
64
|
+
EOS
|
65
|
+
act_template = run_client_as_json(template)
|
66
|
+
exp_template = <<-EOS
|
67
|
+
{
|
68
|
+
"Test": {
|
69
|
+
"Location": "test",
|
70
|
+
"Type": "GITHUB"
|
71
|
+
}
|
72
|
+
}
|
73
|
+
EOS
|
74
|
+
assert_equal exp_template.chomp, act_template
|
75
|
+
end
|
76
|
+
end
|
data/test/elb_test.rb
CHANGED
@@ -122,6 +122,50 @@ Test _elb_listeners({})
|
|
122
122
|
"Protocol": "HTTP"
|
123
123
|
}
|
124
124
|
]
|
125
|
+
}
|
126
|
+
EOS
|
127
|
+
assert_equal exp_template.chomp, act_template
|
128
|
+
|
129
|
+
template = <<-EOS
|
130
|
+
Test _elb_listeners({ listeners: [ { protocol: "https", ssl: "test" } ] })
|
131
|
+
EOS
|
132
|
+
act_template = run_client_as_json(template)
|
133
|
+
exp_template = <<-EOS
|
134
|
+
{
|
135
|
+
"Test": [
|
136
|
+
{
|
137
|
+
"InstancePort": "443",
|
138
|
+
"InstanceProtocol": "HTTPS",
|
139
|
+
"LoadBalancerPort": "443",
|
140
|
+
"PolicyNames": [
|
141
|
+
"ELBSecurityPolicy-2016-08"
|
142
|
+
],
|
143
|
+
"Protocol": "HTTPS",
|
144
|
+
"SSLCertificateId": "test"
|
145
|
+
}
|
146
|
+
]
|
147
|
+
}
|
148
|
+
EOS
|
149
|
+
assert_equal exp_template.chomp, act_template
|
150
|
+
|
151
|
+
template = <<-EOS
|
152
|
+
Test _elb_listeners({ listeners: [ { protocol: "https", ssl: "test", policy: "TLS-1-2-2017-01" } ] })
|
153
|
+
EOS
|
154
|
+
act_template = run_client_as_json(template)
|
155
|
+
exp_template = <<-EOS
|
156
|
+
{
|
157
|
+
"Test": [
|
158
|
+
{
|
159
|
+
"InstancePort": "443",
|
160
|
+
"InstanceProtocol": "HTTPS",
|
161
|
+
"LoadBalancerPort": "443",
|
162
|
+
"PolicyNames": [
|
163
|
+
"ELBSecurityPolicy-TLS-1-2-2017-01"
|
164
|
+
],
|
165
|
+
"Protocol": "HTTPS",
|
166
|
+
"SSLCertificateId": "test"
|
167
|
+
}
|
168
|
+
]
|
125
169
|
}
|
126
170
|
EOS
|
127
171
|
assert_equal exp_template.chomp, act_template
|
data/test/logs_test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'kumogata/template/logs'
|
3
|
+
|
4
|
+
class LogsTest < Minitest::Test
|
5
|
+
def test_logs_metric_filter_transformations
|
6
|
+
template = <<-EOS
|
7
|
+
Test _logs_metric_filter_transformations(transformations: [ { name: "test", ns: "test", value: "test" } ])
|
8
|
+
EOS
|
9
|
+
act_template = run_client_as_json(template)
|
10
|
+
exp_template = <<-EOS
|
11
|
+
{
|
12
|
+
"Test": [
|
13
|
+
{
|
14
|
+
"MetricName": "test",
|
15
|
+
"MetricNamespace": "test",
|
16
|
+
"MetricValue": "test"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
EOS
|
21
|
+
assert_equal exp_template.chomp, act_template
|
22
|
+
end
|
23
|
+
end
|
data/test/s3_test.rb
CHANGED
data/test/sns_test.rb
CHANGED
@@ -4,7 +4,7 @@ require 'kumogata/template/sns'
|
|
4
4
|
class SnsTest < Minitest::Test
|
5
5
|
def test_sns_subscription
|
6
6
|
template = <<-EOS
|
7
|
-
Test
|
7
|
+
Test _sns_subscription_list(subscription: [ { protocol: "lambda", endpoint: "test" } ])
|
8
8
|
EOS
|
9
9
|
act_template = run_client_as_json(template)
|
10
10
|
exp_template = <<-EOS
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class CodebuildProjectTest < Minitest::Test
|
4
|
+
def test_normal
|
5
|
+
template = <<-EOS
|
6
|
+
_codebuild_project "test", { artifacts: { type: "test" },
|
7
|
+
environment: { compute: "large", image: "test", env: { "test": "test" } },
|
8
|
+
project: "test",
|
9
|
+
service: "test",
|
10
|
+
source: { type: "github" } }
|
11
|
+
EOS
|
12
|
+
act_template = run_client_as_json(template)
|
13
|
+
exp_template = <<-EOS
|
14
|
+
{
|
15
|
+
"TestCodebuildProject": {
|
16
|
+
"Type": "AWS::CodeBuild::Project",
|
17
|
+
"Properties": {
|
18
|
+
"Artifacts": {
|
19
|
+
"Type": "no_artifacts"
|
20
|
+
},
|
21
|
+
"Environment": {
|
22
|
+
"ComputeType": "BUILD_GENERAL1_LARGE",
|
23
|
+
"EnvironmentVariables": [
|
24
|
+
{
|
25
|
+
"Name": "test",
|
26
|
+
"Value": "test"
|
27
|
+
}
|
28
|
+
],
|
29
|
+
"Image": "test",
|
30
|
+
"Type": "LINUX_CONTAINER"
|
31
|
+
},
|
32
|
+
"Name": "test",
|
33
|
+
"ServiceRole": "test",
|
34
|
+
"Source": {
|
35
|
+
"Location": "",
|
36
|
+
"Type": "GITHUB"
|
37
|
+
},
|
38
|
+
"Tags": [
|
39
|
+
{
|
40
|
+
"Key": "Name",
|
41
|
+
"Value": {
|
42
|
+
"Fn::Join": [
|
43
|
+
"-",
|
44
|
+
[
|
45
|
+
{
|
46
|
+
"Ref": "Service"
|
47
|
+
},
|
48
|
+
"test"
|
49
|
+
]
|
50
|
+
]
|
51
|
+
}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"Key": "Service",
|
55
|
+
"Value": {
|
56
|
+
"Ref": "Service"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"Key": "Version",
|
61
|
+
"Value": {
|
62
|
+
"Ref": "Version"
|
63
|
+
}
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
EOS
|
70
|
+
assert_equal exp_template.chomp, act_template
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class CodecommitRepositoryTest < Minitest::Test
|
4
|
+
def test_normal
|
5
|
+
template = <<-EOS
|
6
|
+
_codecommit_repository "test"
|
7
|
+
EOS
|
8
|
+
act_template = run_client_as_json(template)
|
9
|
+
exp_template = <<-EOS
|
10
|
+
{
|
11
|
+
"TestCodecommitRepository": {
|
12
|
+
"Type": "AWS::CodeCommit::Repository",
|
13
|
+
"Properties": {
|
14
|
+
"RepositoryName": "test"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
EOS
|
19
|
+
assert_equal exp_template.chomp, act_template
|
20
|
+
end
|
21
|
+
end
|