<commit_before># Kumogata

![Stack is not required!](http://serif.hatelabo.jp/images/cache/a69b56ca6985b6ee7e605a102445953f355f54f5/62192c286da4377e608f3f5a5200f1bec272a92e.gif)


Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).

[![Gem Version](https://badge.fury.io/rb/kumogata.png?201403050245)](http://badge.fury.io/rb/kumogata)
[![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403050245)](https://drone.io/github.com/winebarrel/kumogata/latest)

It can define a template in Ruby DSL, such as:

```ruby
AWSTemplateFormatVersion "2010-09-09"

Description (<<-EOS).undent
  Kumogata Sample Template
  You can use Here document!
EOS

Parameters do
  InstanceType do
    Default "t1.micro"
    Description "Instance Type"
    Type "String"
  end
end

Resources do
  myEC2Instance do
    Type "AWS::EC2::Instance"
    Properties do
      ImageId "ami-XXXXXXXX"
      InstanceType { Ref "InstanceType" }
      KeyName "your_key_name"

      UserData (<<-EOS).undent.encode64
        #!/bin/bash
        yum install -y httpd
        service httpd start
      EOS
    end
  end
end

Outputs do
  AZ do
    Value do
      Fn__GetAtt "myEC2Instance", "AvailabilityZone"
    end
  end
end
```

Ruby template structure is almost the same as [JSON template](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-structure.html).

## Installation

    $ gem install kumogata

## Usage

```
Usage: kumogata <command> [args] [options]

Commands:
  create         PATH_OR_URL [STACK_NAME]  Create resources as specified in the template
  validate       PATH_OR_URL               Validate a specified template
  convert        PATH_OR_URL               Convert a template format
  update         PATH_OR_URL STACK_NAME    Update a stack as specified in the template
  delete         STACK_NAME                Delete a specified stack
  list           [STACK_NAME]              List summary information for stacks
  export         STACK_NAME                Export a template from a specified stack
  show-outputs   STACK_NAME                Show outputs for a specified stack
  show-resources STACK_NAME                Show resources for a specified stack

Options:
    -k, --access-key ACCESS_KEY
    -s, --secret-key SECRET_KEY
    -r, --region REGION
        --skip-replace-underscore
        --skip-delete-stack
    -p, --parameters KEY_VALUES
        --capabilities CAPABILITIES
        --disable-rollback
        --notify SNS_TOPICS
        --timeout MINUTES
        --result-log PATH
        --force
        --no-color
        --debug
```

### Create resources

    $ kumogata create template.rb

If you want to save the stack, please specify the stack name:

    $ kumogata create template.rb any_stack_name

If you want to pass parameters, please use `-p` option:

    $ kumogata create template.rb -p "InstanceType=m1.large,KeyName=any_other_key"


**Notice**

**The stack will be delete if you do not specify the stack name explicitly.**
(And only the resources will remain)

I think the stack that manage resources is not required in many case...

### Convert JSON to Ruby

JSON template can be converted to Ruby template.

    $ kumogata convert https://s3.amazonaws.com/cloudformation-templates-us-east-1/Drupal_Single_Instance.template

* Data that cannot be converted will be converted to Array and Hash
* `::` is converted to `__`
  * `Fn::GetAtt` => `Fn__GetAtt`
* `_{ ... }` is convered to Hash
  * `SecurityGroups [_{Ref "WebServerSecurityGroup"}]` => `{"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]}`
* `_path()` creates Hash that has a key of path
  * `_path("/etc/passwd-s3fs") { content "..." }` => `{"/etc/passwd-s3fs": {"content": "..."}}`
* ~~_user_data() creates Base64-encoded UserData~~
  * `_user_data()` has been removed
* `_join()` has been removed

### String#fn_joine()

Ruby templates will be converted as follows by `String#fn_join()`:

```ruby
UserData do
  Fn__Base64 (<<-EOS).fn_join
    #!/bin/bash
    /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
  EOS
end
```

```javascript
"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        "#!/bin/bash\n",
        "/opt/aws/bin/cfn-init -s ",
        {
          "Ref": "AWS::StackName"
        },
        " -r myEC2Instance --region ",
        {
          "Ref": "AWS::Region"
        },
        "\n"
      ]
    ]
  }
}
```

## Demo

* Create resources
  * https://asciinema.org/a/7979
* Convert a template
  * https://asciinema.org/a/7980

## Contributing

1. Fork it ( http://github.com/winebarrel/kumogata/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
<commit_msg>Update badge timestamp<commit_after># Kumogata

![Stack is not required!](http://serif.hatelabo.jp/images/cache/a69b56ca6985b6ee7e605a102445953f355f54f5/62192c286da4377e608f3f5a5200f1bec272a92e.gif)


Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).

[![Gem Version](https://badge.fury.io/rb/kumogata.png?201403051030)](http://badge.fury.io/rb/kumogata)
[![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403051030)](https://drone.io/github.com/winebarrel/kumogata/latest)

It can define a template in Ruby DSL, such as:

```ruby
AWSTemplateFormatVersion "2010-09-09"

Description (<<-EOS).undent
  Kumogata Sample Template
  You can use Here document!
EOS

Parameters do
  InstanceType do
    Default "t1.micro"
    Description "Instance Type"
    Type "String"
  end
end

Resources do
  myEC2Instance do
    Type "AWS::EC2::Instance"
    Properties do
      ImageId "ami-XXXXXXXX"
      InstanceType { Ref "InstanceType" }
      KeyName "your_key_name"

      UserData (<<-EOS).undent.encode64
        #!/bin/bash
        yum install -y httpd
        service httpd start
      EOS
    end
  end
end

Outputs do
  AZ do
    Value do
      Fn__GetAtt "myEC2Instance", "AvailabilityZone"
    end
  end
end
```

Ruby template structure is almost the same as [JSON template](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-structure.html).

## Installation

    $ gem install kumogata

## Usage

```
Usage: kumogata <command> [args] [options]

Commands:
  create         PATH_OR_URL [STACK_NAME]  Create resources as specified in the template
  validate       PATH_OR_URL               Validate a specified template
  convert        PATH_OR_URL               Convert a template format
  update         PATH_OR_URL STACK_NAME    Update a stack as specified in the template
  delete         STACK_NAME                Delete a specified stack
  list           [STACK_NAME]              List summary information for stacks
  export         STACK_NAME                Export a template from a specified stack
  show-outputs   STACK_NAME                Show outputs for a specified stack
  show-resources STACK_NAME                Show resources for a specified stack

Options:
    -k, --access-key ACCESS_KEY
    -s, --secret-key SECRET_KEY
    -r, --region REGION
        --skip-replace-underscore
        --skip-delete-stack
    -p, --parameters KEY_VALUES
        --capabilities CAPABILITIES
        --disable-rollback
        --notify SNS_TOPICS
        --timeout MINUTES
        --result-log PATH
        --force
        --no-color
        --debug
```

### Create resources

    $ kumogata create template.rb

If you want to save the stack, please specify the stack name:

    $ kumogata create template.rb any_stack_name

If you want to pass parameters, please use `-p` option:

    $ kumogata create template.rb -p "InstanceType=m1.large,KeyName=any_other_key"


**Notice**

**The stack will be delete if you do not specify the stack name explicitly.**
(And only the resources will remain)

I think the stack that manage resources is not required in many case...

### Convert JSON to Ruby

JSON template can be converted to Ruby template.

    $ kumogata convert https://s3.amazonaws.com/cloudformation-templates-us-east-1/Drupal_Single_Instance.template

* Data that cannot be converted will be converted to Array and Hash
* `::` is converted to `__`
  * `Fn::GetAtt` => `Fn__GetAtt`
* `_{ ... }` is convered to Hash
  * `SecurityGroups [_{Ref "WebServerSecurityGroup"}]` => `{"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]}`
* `_path()` creates Hash that has a key of path
  * `_path("/etc/passwd-s3fs") { content "..." }` => `{"/etc/passwd-s3fs": {"content": "..."}}`
* ~~_user_data() creates Base64-encoded UserData~~
  * `_user_data()` has been removed
* `_join()` has been removed

### String#fn_joine()

Ruby templates will be converted as follows by `String#fn_join()`:

```ruby
UserData do
  Fn__Base64 (<<-EOS).fn_join
    #!/bin/bash
    /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
  EOS
end
```

```javascript
"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        "#!/bin/bash\n",
        "/opt/aws/bin/cfn-init -s ",
        {
          "Ref": "AWS::StackName"
        },
        " -r myEC2Instance --region ",
        {
          "Ref": "AWS::Region"
        },
        "\n"
      ]
    ]
  }
}
```

## Demo

* Create resources
  * https://asciinema.org/a/7979
* Convert a template
  * https://asciinema.org/a/7980

## Contributing

1. Fork it ( http://github.com/winebarrel/kumogata/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

{'fraction_non_alphanumeric': 0.11976660866004708, 'fraction_numerical': 0.024362780223154877, 'mean_word_length': 2.7765751836103596, 'pattern_counts': {'":': 18, '<': 21, '<?xml version=': 0, '>': 15, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2155346', 'n_tokens_mistral': 3394, 'n_tokens_neox': 3162, 'n_words': 882}