I am trying to generate AWS cloudformation YAML from ruby hash. But I am not able to figure out on how to represent the aws internal function in ruby hash. e.g what would be the equivalent ruby object for the following snippet ?
我正在尝试从ruby hash生成AWS cloudformation YAML。但我无法弄清楚如何在ruby hash中表示aws内部函数。例如,以下代码段的等效ruby对象是什么?
Resources: AppNode: Type: AWS::EC2::Instance Properties: InstanceType: t2.large ImageId: ami-0def3275 KeyName: mykey SecurityGroups: - !Ref AppNodeSG AppNodeSG: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: for the app nodes that allow ssh port SecurityGroupIngress: - IpProtocol: tcp FromPort: '22' ToPort: '22' CidrIp: 0.0.0.0/0
1 个解决方案
#1
0
This would be:
这将是:
{ 'Resources' => {
'AppNode' => {
'Type' => 'AWS::EC2::Instance',
'Properties' => {
'InstanceType' => 't2.large',
'ImageId' => 'ami-0def3275',
'KeyName' => 'mykey',
'SecurityGroups' => ['AppNodeSG']
}
},
'AppNodeSG' => {
'Type' => 'AWS::EC2::SecurityGroup',
'Properties' => {
'GroupDescription' => 'for the app nodes that allow ssh port',
'SecurityGroupIngress' => [{ 'IpProtocol' => 'tcp', 'FromPort' => '22', 'ToPort' => '22', 'CidrIp' => '0.0.0.0/0' }]
}
}
} }
Ruby has YAML built in which allows you to parse YAML into a hash or convert a hash into YAML.
Ruby内置了YAML,允许您将YAML解析为哈希或将哈希转换为YAML。
#1
0
This would be:
这将是:
{ 'Resources' => {
'AppNode' => {
'Type' => 'AWS::EC2::Instance',
'Properties' => {
'InstanceType' => 't2.large',
'ImageId' => 'ami-0def3275',
'KeyName' => 'mykey',
'SecurityGroups' => ['AppNodeSG']
}
},
'AppNodeSG' => {
'Type' => 'AWS::EC2::SecurityGroup',
'Properties' => {
'GroupDescription' => 'for the app nodes that allow ssh port',
'SecurityGroupIngress' => [{ 'IpProtocol' => 'tcp', 'FromPort' => '22', 'ToPort' => '22', 'CidrIp' => '0.0.0.0/0' }]
}
}
} }
Ruby has YAML built in which allows you to parse YAML into a hash or convert a hash into YAML.
Ruby内置了YAML,允许您将YAML解析为哈希或将哈希转换为YAML。