kumogata 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/kumogata/ext/string_ext.rb +39 -3
- data/lib/kumogata/version.rb +1 -1
- data/spec/kumogata_convert_spec.rb +90 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d994503ecb53c0aa9e0a0d7317a3f6b6cc8b2b39
|
4
|
+
data.tar.gz: cd96c9f28fdc83ba2025828f9ef5b305a3d5a313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8392415cc172bc02adc1fb976316dfd7b7e4bdd4cde81cf6aca088a0af13480f5da9517461da3d1e8c530c1ce6a78662057a04e300706f2dda5695e046ccc621
|
7
|
+
data.tar.gz: 14a7759b1a3acfc951f3cc20ab317180972c9fe147b2f4fc7d1920cefda4b2c5d43c0f96c3e86499501404c66dec2855f279e4a6b7c4661a1e6b4aabb642ceec
|
data/README.md
CHANGED
@@ -5,12 +5,19 @@
|
|
5
5
|
|
6
6
|
Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
|
7
7
|
|
8
|
-
[![Gem Version](https://badge.fury.io/rb/kumogata.png?
|
9
|
-
[![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/kumogata.png?201403050220)](http://badge.fury.io/rb/kumogata)
|
9
|
+
[![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403050220)](https://drone.io/github.com/winebarrel/kumogata/latest)
|
10
10
|
|
11
11
|
It can define a template in Ruby DSL, such as:
|
12
12
|
|
13
13
|
```ruby
|
14
|
+
AWSTemplateFormatVersion "2010-09-09"
|
15
|
+
|
16
|
+
Description (<<-EOS).undent
|
17
|
+
Kumogata Sample Template
|
18
|
+
You can use Here document!
|
19
|
+
EOS
|
20
|
+
|
14
21
|
Parameters do
|
15
22
|
InstanceType do
|
16
23
|
Default "t1.micro"
|
@@ -123,7 +130,7 @@ JSON template can be converted to Ruby template.
|
|
123
130
|
|
124
131
|
### String#fn_joine()
|
125
132
|
|
126
|
-
Ruby templates will be converted as follows by `
|
133
|
+
Ruby templates will be converted as follows by `String#fn_join()`:
|
127
134
|
|
128
135
|
```ruby
|
129
136
|
UserData do
|
@@ -46,9 +46,45 @@ class String
|
|
46
46
|
null = "\0"
|
47
47
|
|
48
48
|
data = Object.new.instance_eval(<<-EOS)
|
49
|
-
@
|
50
|
-
|
51
|
-
|
49
|
+
@__functions__ = []
|
50
|
+
|
51
|
+
@__value_conv__ = proc do |v|
|
52
|
+
case v
|
53
|
+
when Array, Hash
|
54
|
+
v
|
55
|
+
else
|
56
|
+
v.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def Fn__Base64(value)
|
61
|
+
@__functions__ << {'Fn::Base64' => @__value_conv__[value]}
|
62
|
+
#{null.inspect}
|
63
|
+
end
|
64
|
+
|
65
|
+
def Fn__FindInMap(map_name, top_level_key, second_level_key)
|
66
|
+
@__functions__ << {'Fn::FindInMap' => [
|
67
|
+
map_name, top_level_key, second_level_key].map(&@__value_conv__)}
|
68
|
+
#{null.inspect}
|
69
|
+
end
|
70
|
+
|
71
|
+
def Fn__GetAtt(logical_name, attr_name)
|
72
|
+
@__functions__ << {'Fn::GetAtt' => [
|
73
|
+
logical_name, attr_name].map(&@__value_conv__)}
|
74
|
+
#{null.inspect}
|
75
|
+
end
|
76
|
+
|
77
|
+
def Fn__GetAZs(region)
|
78
|
+
@__functions__ << {'Fn::GetAZs' => @__value_conv__[region]}
|
79
|
+
#{null.inspect}
|
80
|
+
end
|
81
|
+
|
82
|
+
def Ref(value)
|
83
|
+
@__functions__ << {'Ref' => value}
|
84
|
+
#{null.inspect}
|
85
|
+
end
|
86
|
+
|
87
|
+
ERB.new(#{data.inspect}, nil, #{trim_mode.inspect}).result(binding).split(#{null.inspect}).zip(@__functions__)
|
52
88
|
EOS
|
53
89
|
|
54
90
|
data = data.flatten.select {|i| not i.nil? }.map {|i|
|
data/lib/kumogata/version.rb
CHANGED
@@ -343,6 +343,32 @@ Resources do
|
|
343
343
|
end # Metadata
|
344
344
|
end
|
345
345
|
end
|
346
|
+
|
347
|
+
Outputs do
|
348
|
+
WebsiteURL do
|
349
|
+
Value (<<-EOS).fn_join
|
350
|
+
http://<%= Fn__GetAtt "myEC2Instance", "PublicDnsName" %>
|
351
|
+
EOS
|
352
|
+
end
|
353
|
+
|
354
|
+
Base64Str do
|
355
|
+
Value (<<-EOS).fn_join
|
356
|
+
<%= Fn__Base64 "AWS CloudFormation" %>
|
357
|
+
EOS
|
358
|
+
end
|
359
|
+
|
360
|
+
MappedValue do
|
361
|
+
Value (<<-EOS).fn_join
|
362
|
+
<%= Fn__FindInMap "RegionMap", { "Ref" => "AWS::Region" }, 32 %>
|
363
|
+
EOS
|
364
|
+
end
|
365
|
+
|
366
|
+
AZ do
|
367
|
+
Value (<<-EOS).fn_join
|
368
|
+
<%= Fn__GetAZs "us-east-1" %>
|
369
|
+
EOS
|
370
|
+
end
|
371
|
+
end
|
346
372
|
TEMPLATE
|
347
373
|
|
348
374
|
json_template = run_client(:convert, :template => template)
|
@@ -421,6 +447,70 @@ end
|
|
421
447
|
}
|
422
448
|
}
|
423
449
|
}
|
450
|
+
},
|
451
|
+
"Outputs": {
|
452
|
+
"WebsiteURL": {
|
453
|
+
"Value": {
|
454
|
+
"Fn::Join": [
|
455
|
+
"",
|
456
|
+
[
|
457
|
+
"http://",
|
458
|
+
{
|
459
|
+
"Fn::GetAtt": [
|
460
|
+
"myEC2Instance",
|
461
|
+
"PublicDnsName"
|
462
|
+
]
|
463
|
+
},
|
464
|
+
"\n"
|
465
|
+
]
|
466
|
+
]
|
467
|
+
}
|
468
|
+
},
|
469
|
+
"Base64Str": {
|
470
|
+
"Value": {
|
471
|
+
"Fn::Join": [
|
472
|
+
"",
|
473
|
+
[
|
474
|
+
{
|
475
|
+
"Fn::Base64": "AWS CloudFormation"
|
476
|
+
},
|
477
|
+
"\n"
|
478
|
+
]
|
479
|
+
]
|
480
|
+
}
|
481
|
+
},
|
482
|
+
"MappedValue": {
|
483
|
+
"Value": {
|
484
|
+
"Fn::Join": [
|
485
|
+
"",
|
486
|
+
[
|
487
|
+
{
|
488
|
+
"Fn::FindInMap": [
|
489
|
+
"RegionMap",
|
490
|
+
{
|
491
|
+
"Ref": "AWS::Region"
|
492
|
+
},
|
493
|
+
"32"
|
494
|
+
]
|
495
|
+
},
|
496
|
+
"\n"
|
497
|
+
]
|
498
|
+
]
|
499
|
+
}
|
500
|
+
},
|
501
|
+
"AZ": {
|
502
|
+
"Value": {
|
503
|
+
"Fn::Join": [
|
504
|
+
"",
|
505
|
+
[
|
506
|
+
{
|
507
|
+
"Fn::GetAZs": "us-east-1"
|
508
|
+
},
|
509
|
+
"\n"
|
510
|
+
]
|
511
|
+
]
|
512
|
+
}
|
513
|
+
}
|
424
514
|
}
|
425
515
|
}
|
426
516
|
EOS
|