Complexity Score
Low
Open Issues
N/A
Dependent Projects
2
Weekly Downloadsglobal
47
License
- MIT
- Yesattribution
- Permissivelinking
- Permissivedistribution
- Permissivemodification
- Nopatent grant
- Yesprivate use
- Permissivesublicensing
- Notrademark grant
Downloads
Readme
kumogata2-plugin-ruby
It is the Ruby plug-in of Kumogata2.
It convert the Ruby DSL to JSON.
Installation
Add this line to your application’s Gemfile:
gem 'kumogata2-plugin-ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kumogata2-plugin-ruby
Usage
kumogata2 export my-stack --output-format rb > my-stack.rb
kumogata2 dry-run my-stack.rb my-stack
kumogata2 update my-stack.rb my-stack
Export using braces
EXPORT_RUBY_USE_BRACES=1 kumogata2 export ... --output-format rb
Export old format
EXPORT_RUBY_OLD_FORMAT=1 kumogata2 export ... --output-format rb
Example
template do
AWSTemplateFormatVersion "2010-09-09"
Description (<<-EOS).undent
Kumogata Sample Template
You can use Here document!
EOS
Parameters do
InstanceType do
Default "t2.micro"
Description "Instance Type"
Type "String"
end
end
Resources do
myEC2Instance do
Type "AWS::EC2::Instance"
Properties do
ImageId "ami-XXXXXXXX"
InstanceType { Ref "InstanceType" }
KeyName "your_key_name"
UserData do
Fn__Base64 (<<-EOS).undent
#!/bin/bash
yum install -y httpd
service httpd start
EOS
end
end
end
end
end
::
is converted to__
Fn::GetAtt
=>Fn__GetAtt
_{ ... }
is convered to HashSecurityGroups [_{Ref "WebServerSecurityGroup"}]
=>{"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]}
_path()
creates Hash that has a key of path_path("/etc/passwd-s3fs") { content "..." }
=>{"/etc/passwd-s3fs": {"content": "..."}}
String#fn_join()
Ruby templates will be converted as follows by String#fn_join()
:
UserData do
Fn__Base64 (<<-EOS).fn_join
#!/bin/bash
/opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
EOS
end
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"/opt/aws/bin/cfn-init -s ",
{
"Ref": "AWS::StackName"
},
" -r myEC2Instance --region ",
{
"Ref": "AWS::Region"
},
"\n"
]
]
}
}
Split a template file
- template.rb
template do
Resources do
_include 'template2.rb', :ami_id => 'ami-XXXXXXXX'
end
end
- template2.rb
myEC2Instance do
Type "AWS::EC2::Instance"
Properties do
ImageId args[:ami_id]
InstanceType { Ref "InstanceType" }
KeyName "your_key_name"
end
end
- Converted JSON template
{
"Resources": {
"myEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-XXXXXXXX",
"InstanceType": {
"Ref": "InstanceType"
},
"KeyName": "your_key_name"
}
}
}
}
Post hook
You can run ruby script after building servers using post()
.
template do
...
end
post do |output|
puts output
#=> '{"WebsiteURL"=>"http://ec2-XX-XX-XX-XX.ap-northeast-1.compute.amazonaws.com"}'
end
Dependencies
No runtime dependency information found for this package.
CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
Yes
Github Stars
6
Dependenciestotal
0
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No
Learn how to distribute kumogata2-plugin-ruby in your own private RubyGems registry
$gem install kumogata2-plugin-ruby
/Processing...
✓Done
9 Releases
RubyGems on Cloudsmith