ruby - 如何表示 aws 内部函数以将 ruby​​ 哈希转换为 yaml

标签 ruby yaml aws-cloudformation

我正在尝试从 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/

相关文章:

ruby - 以数组为值迭代哈希

xml - 嵌入式设备GUI设计工具

aws-cloudformation - 如何使用 CloudFormation 在 CodeDeploy 中设置自动回滚?

amazon-web-services - 在CFT中,当TriggerType为Scheduled时,Appflow中的ScheduleStartTime的格式是什么

ruby - "Please install the mysql2 adapter"

ruby-on-rails - 在 Linux 上安装 ruby​​-filemagic gem 时缺少库

javascript - 自定义 symfony view.yml 文件

ruby - redhat 上的 Yaml 解析问题

amazon-web-services - Fargate 配置文件错误 : FargateECSTaskDefinition

ruby-on-rails - Ruby 正则表达式的价格