我正在尝试从 ruby 哈希生成 AWS cloudformation YAML。但我无法弄清楚如何在 ruby 哈希中表示 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
最佳答案
这将是:
{ '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 有 YAML内置允许您将 YAML 解析为哈希或将哈希转换为 YAML。
关于ruby - 如何表示 aws 内部函数以将 ruby 哈希转换为 yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48128569/