bazaarvoice / cloudformation-ruby-dsl

Ruby DSL for creating Cloudformation templates
Apache License 2.0
210 stars 76 forks source link

Added a possibility to get table header as list #76

Closed ssuprun closed 8 years ago

ssuprun commented 8 years ago

It can be used as parameter in function "get_multihash" when we need to make a whole map from table. For example: table (ami.txt):

region        hvm_ebs       hvm_s3        pv_ebs        pv_s3
us-east-1     ami-60b6c60a  ami-66b6c60c  ami-5fb8c835  ami-30b6c65a
us-west-2     ami-f0091d91  ami-31342050  ami-d93622b8  ami-960317f7
eu-west-1     ami-bff32ccc  ami-54e03f27  ami-95e33ce6  ami-54e53a27

Ruby code:

ami = Table.load File.dirname(__FILE__) + '/ami.txt'
mapping 'AmiMap', ami.get_multihash(:region, {}, *ami.get_header(:region))

map:

    "AmiMap": {
      "us-east-1": {
        "hvm_ebs": "ami-60b6c60a",
        "hvm_s3": "ami-66b6c60c",
        "pv_ebs": "ami-5fb8c835",
        "pv_s3": "ami-30b6c65a"
      },
      "us-west-2": {
        "hvm_ebs": "ami-f0091d91",
        "hvm_s3": "ami-31342050",
        "pv_ebs": "ami-d93622b8",
        "pv_s3": "ami-960317f7"
      },
      "eu-west-1": {
        "hvm_ebs": "ami-bff32ccc",
        "hvm_s3": "ami-54e03f27",
        "pv_ebs": "ami-95e33ce6",
        "pv_s3": "ami-54e53a27"
      }
    },