spec/kumogata_convert_spec.rb in kumogata-0.1.8 vs spec/kumogata_convert_spec.rb in kumogata-0.1.9
- old
+ new
@@ -182,12 +182,11 @@
" -r myEC2Instance --region ",
{
"Ref": "AWS::Region"
},
"\n",
- "echo END | logger",
- "\n"
+ "echo END | logger\n"
]
]
}
}
},
@@ -217,12 +216,11 @@
[
"echo ",
{
"Ref": "Password"
},
- " > /tmp/my-password",
- "\n"
+ " > /tmp/my-password\n"
]
]
}
}
}
@@ -249,11 +247,11 @@
Type "AWS::EC2::Instance"
Properties do
ImageId "ami-XXXXXXXX"
InstanceType "t1.micro"
- UserData _user_data(<<-EOS)
+ UserData (<<-EOS).undent.encode64
#!/bin/bash
yum install -y httpd
services start httpd
EOS
end
@@ -280,9 +278,148 @@
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-XXXXXXXX",
"InstanceType": "t1.micro",
"UserData": "IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgLXkgaHR0cGQKc2VydmljZXMgc3RhcnQgaHR0cGQK"
+ }
+ }
+ }
+}
+ EOS
+ end
+
+ it 'convert Ruby template to JSON template with block args' do
+ template = <<-'TEMPLATE'
+Parameters do
+ Password do
+ NoEcho true
+ Type "String"
+ end
+end
+
+Resources do
+ myEC2Instance do |resource_name|
+ Type "AWS::EC2::Instance"
+ Properties do
+ ImageId "ami-XXXXXXXX"
+ InstanceType "t1.micro"
+
+ UserData do
+ Fn__Base64 _join(<<-EOS)
+ #!/bin/bash
+ echo START | logger
+ /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r #{resource_name} --region <%= Ref "AWS::Region" %>
+ echo END | logger
+ EOS
+ end
+ end
+
+ Metadata do
+ AWS__CloudFormation__Init do
+ config do
+
+ packages do
+ yum({"httpd"=>[]})
+ end
+
+ services do
+ sysvinit do
+ httpd do
+ enabled "true"
+ ensureRunning "true"
+ end
+ end
+ end
+
+ commands do
+ any_name do
+ command _join(<<-EOS)
+ echo <%= Ref "Password" %> > /tmp/my-password
+ EOS
+ end
+ end
+
+ end # config
+ end # AWS__CloudFormation__Init
+ end # Metadata
+ end
+end
+ TEMPLATE
+
+ json_template = run_client(:convert, :template => template)
+
+ expect(json_template).to eq((<<-'EOS').chomp)
+{
+ "Parameters": {
+ "Password": {
+ "NoEcho": "true",
+ "Type": "String"
+ }
+ },
+ "Resources": {
+ "myEC2Instance": {
+ "Type": "AWS::EC2::Instance",
+ "Properties": {
+ "ImageId": "ami-XXXXXXXX",
+ "InstanceType": "t1.micro",
+ "UserData": {
+ "Fn::Base64": {
+ "Fn::Join": [
+ "",
+ [
+ "#!/bin/bash\n",
+ "echo START | logger\n",
+ "/opt/aws/bin/cfn-init -s ",
+ {
+ "Ref": "AWS::StackName"
+ },
+ " -r myEC2Instance --region ",
+ {
+ "Ref": "AWS::Region"
+ },
+ "\n",
+ "echo END | logger\n"
+ ]
+ ]
+ }
+ }
+ },
+ "Metadata": {
+ "AWS::CloudFormation::Init": {
+ "config": {
+ "packages": {
+ "yum": {
+ "httpd": [
+
+ ]
+ }
+ },
+ "services": {
+ "sysvinit": {
+ "httpd": {
+ "enabled": "true",
+ "ensureRunning": "true"
+ }
+ }
+ },
+ "commands": {
+ "any_name": {
+ "command": {
+ "Fn::Join": [
+ "",
+ [
+ "echo ",
+ {
+ "Ref": "Password"
+ },
+ " > /tmp/my-password\n"
+ ]
+ ]
+ }
+ }
+ }
+ }
+ }
}
}
}
}
EOS