terraforming 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ab51ccecba0ce3d3701be95d8718f6d5fe6a796
4
- data.tar.gz: 0032ebcb37559bd617d042347b12c8764c2a82f3
3
+ metadata.gz: cb884d952f74d4079fcfb52bc4798a8a90d98587
4
+ data.tar.gz: 23fe2b8eeb2eea9843ecaf1dee41c5a387ea2a57
5
5
  SHA512:
6
- metadata.gz: de61ed94cc3077c1866602f6cf41f4298b02c0ce91105b8cae4d8c8054b45182feeb2318f531d574006d6fcb19c8302c26e7d2bb27c6257136ce90b3f038ff7a
7
- data.tar.gz: a1a27835df34c2e8c2830cab7c578381c75fec982a55f4859f427d6af2ffb7e3a921120333897621b3e604622f5bf6154f4496d44e7950481a0e0b4a963d5f70
6
+ metadata.gz: 72708c53e470e3d7b7d673b51b22bcd81a83af77e18e5166008880c164e14da85c16646bb20b91a6922c51bb88b914b365e4b14785e45a9152cc580567e62444
7
+ data.tar.gz: 810a584ff6e7b4f5ba4e4a07a44ae4685b629eb4ec523bf8f7397bb362b7de9134ff9654a31105dc06cccf8993ed87d7a99b8ac8a1510793cc929795f0c2efc5
data/.travis.yml CHANGED
@@ -4,7 +4,13 @@ rvm:
4
4
  - 2.2.5
5
5
  - 2.1.10
6
6
  env:
7
- - secure: n0mxwnyjuXI4mJO4mp++2TnsPJ+XgCF/J1U2L5piE5j3xMhSU+5V0JrA1uFlS0Pemb44M7BjgmF9S4G35BwyAQpctpCYhqy9tFa6+Y6nxEv5hCv2cZz7BSAZM6eb+zq20409hxTHRaQOr1DBeE4R5S2PrmOXRqvYfTRv3LNSLFk=
7
+ global:
8
+ - secure: n0mxwnyjuXI4mJO4mp++2TnsPJ+XgCF/J1U2L5piE5j3xMhSU+5V0JrA1uFlS0Pemb44M7BjgmF9S4G35BwyAQpctpCYhqy9tFa6+Y6nxEv5hCv2cZz7BSAZM6eb+zq20409hxTHRaQOr1DBeE4R5S2PrmOXRqvYfTRv3LNSLFk=
9
+ matrix:
10
+ - OJ=0
11
+ - OJ=1
12
+ before_script:
13
+ - if [[ $OJ -eq 1 ]]; then gem install oj; fi
8
14
  notifications:
9
15
  slack:
10
16
  secure: iTI8zpxXQJqf5e9ix4buLRsGlf9lJRZqA9Fawdqm41msBrC0Zsp31XzBS7ZPiTcdHhImtOC4lccTCW2C8kR6waaG5VOF0U2BwyKaNFKsXMaVk6yrNhYkvJ9YVicuU9hL+JKLyBrSDYQ7+vXcHqaz4H4dYpPThrv6sfq4jBOp+eM=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [v0.11.0](https://github.com/dtan4/terraforming/releases/tag/v0.11.0) (2016-11-14)
2
+
3
+ ## Resource
4
+
5
+ - AWS CloudWatch alarm [#273](https://github.com/dtan4/terraforming/pull/273) (thanks @eredi93)
6
+
7
+ ## Fixed / Updated
8
+
9
+ - Remove native extension gems and use wrapper gem [#275](https://github.com/dtan4/terraforming/pull/275)
10
+ - Generate `iops` field only with io1 volume [#271](https://github.com/dtan4/terraforming/pull/271)
11
+ - Set `force_destroy: false` for IAM users [#267](https://github.com/dtan4/terraforming/pull/267) (thanks @raylu)
12
+ - Remove commands to delete empty files in export in README.md [#261](https://github.com/dtan4/terraforming/pull/261) (thanks @benmanns)
13
+
1
14
  # [v0.10.0](https://github.com/dtan4/terraforming/releases/tag/v0.10.0) (2016-08-24)
2
15
 
3
16
  ## Resource
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ # Contributing
2
+
3
+ I love pull requests from everyone! By the way, I have a favor to ask you with your contribution :bow:
4
+
5
+ ## Making changes
6
+
7
+ - Currently, this gem supports only __AWS__ resources. Other providers are supported as separated gems.
8
+ - Datadog: [terraforming-datadog](https://github.com/dtan4/terraforming-datadog)
9
+ - DNSimple: [terraforming-dnsimple](https://github.com/dtan4/terraforming-dnsimple)
10
+ - Do not bump gem version in your pull request.
11
+ - Please follow the coding style of _existing_ code. Most of trivial rules can be checked by [RuboCop](https://github.com/bbatsov/rubocop) ([`rubocop.yml`](https://github.com/dtan4/terraforming/blob/master/.rubocop.yml)).
12
+ - Coding style is checked automatically by [SideCI](https://sideci.com) right after creating pull request. If there is error, SideCI comments at the point error occured.
13
+ - Please write tests for your changes. All tests are written with [RSpec](http://rspec.info/).
14
+
15
+ ## Adding new resource
16
+
17
+ - Class name must match to Terraforming's resource name without `aws_` prefix, and be a complete resource name.
18
+ - e.g. `aws_iam_group_membership`: `IAMGroupMembership`
19
+ - Yes, I know that some of resources I added a long ago don't follow to this rule...
20
+ - File name must also match to Terraforming's resource name without `aws_` prefix.
21
+ - e.g. `aws_iam_group_membership`: `iam_group_membership.rb`
22
+ - Command name should be abbreviation.
23
+ - e.g. `aws_iam_group_membership`: `iamgp`
24
+ - Please check generation result by executing `terraform plan` with real resources. There should be NO diff with generated `.tf` and `.tfstate`.
data/README.md CHANGED
@@ -77,6 +77,7 @@ PS C:\> terraforming ec2 --use-bundled-cert
77
77
  $ terraforming
78
78
  Commands:
79
79
  terraforming asg # AutoScaling Group
80
+ terraforming cwa # CloudWatch Alarm
80
81
  terraforming dbpg # Database Parameter Group
81
82
  terraforming dbsg # Database Security Group
82
83
  terraforming dbsn # Database Subnet Group
@@ -337,8 +338,8 @@ Example assuming you want to export everything from us-west-2 and you are using
337
338
  ```bash
338
339
  export AWS_REGION=us-west-2
339
340
  terraforming help | grep terraforming | grep -v help | awk '{print "terraforming", $2, "--profile", "default", ">", $2".tf";}' | bash
340
- # remove files that only have 1 empty line (nothing in AWS)
341
- find . -type f | xargs wc -l | grep '1 .' | awk '{print $2;}' | xargs rm
341
+ # find files that only have 1 empty line (likely nothing in AWS)
342
+ find . -type f -name '*.tf' | xargs wc -l | grep ' 1 .'
342
343
  ```
343
344
 
344
345
  ## Run as Docker container [![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
data/lib/terraforming.rb CHANGED
@@ -1,16 +1,6 @@
1
- require "oj"
2
-
3
- begin
4
- require "ox"
5
- rescue NameError => e
6
- spec = Gem::Specification.stubs.find { |s| s.name == 'ox' }
7
- raise e unless spec
8
- require File.join(spec.gem_dir, "lib/ox")
9
- end
10
-
11
1
  require "aws-sdk-core"
12
2
  require "erb"
13
- require "json"
3
+ require "multi_json"
14
4
  require "thor"
15
5
  require "zlib"
16
6
 
@@ -19,6 +9,7 @@ require "terraforming/version"
19
9
 
20
10
  require "terraforming/cli"
21
11
  require "terraforming/resource/auto_scaling_group"
12
+ require "terraforming/resource/cloud_watch_alarm"
22
13
  require "terraforming/resource/db_parameter_group"
23
14
  require "terraforming/resource/db_security_group"
24
15
  require "terraforming/resource/db_subnet_group"
@@ -14,6 +14,11 @@ module Terraforming
14
14
  execute(Terraforming::Resource::AutoScalingGroup, options)
15
15
  end
16
16
 
17
+ desc "cwa", "CloudWatch Alarm"
18
+ def cwa
19
+ execute(Terraforming::Resource::CloudWatchAlarm, options)
20
+ end
21
+
17
22
  desc "dbpg", "Database Parameter Group"
18
23
  def dbpg
19
24
  execute(Terraforming::Resource::DBParameterGroup, options)
@@ -216,10 +221,10 @@ module Terraforming
216
221
  end
217
222
 
218
223
  def tfstate(klass, tfstate_path)
219
- tfstate = tfstate_path ? JSON.parse(open(tfstate_path).read) : tfstate_skeleton
224
+ tfstate = tfstate_path ? MultiJson.load(open(tfstate_path).read) : tfstate_skeleton
220
225
  tfstate["serial"] = tfstate["serial"] + 1
221
226
  tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(klass.tfstate)
222
- JSON.pretty_generate(tfstate)
227
+ MultiJson.encode(tfstate, pretty: true)
223
228
  end
224
229
 
225
230
  def tfstate_skeleton
@@ -0,0 +1,87 @@
1
+ module Terraforming
2
+ module Resource
3
+ class CloudWatchAlarm
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::CloudWatch::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::CloudWatch::Client.new)
11
+ self.new(client).tfstate
12
+ end
13
+
14
+ def initialize(client)
15
+ @client = client
16
+ end
17
+
18
+ def tf
19
+ apply_template(@client, "tf/cloud_watch_alarm")
20
+ end
21
+
22
+ def tfstate
23
+ alarms.inject({}) do |resources, alarm|
24
+ resources["aws_cloudwatch_metric_alarm.#{module_name_of(alarm)}"] = {
25
+ "type" => "aws_cloudwatch_metric_alarm",
26
+ "primary" => {
27
+ "id" => alarm.alarm_name,
28
+ "attributes" => alarm_attributes(alarm)
29
+ }
30
+ }
31
+ resources
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def alarm_attributes(alarm)
38
+ attributes = {
39
+ "actions_enabled" => alarm.actions_enabled.to_s,
40
+ "alarm_description" => sanitize(alarm.alarm_description),
41
+ "alarm_name" => alarm.alarm_name,
42
+ "comparison_operator" => alarm.comparison_operator,
43
+ "evaluation_periods" => alarm.evaluation_periods.to_s,
44
+ "id" => alarm.alarm_name,
45
+ "metric_name" => alarm.metric_name,
46
+ "namespace" => alarm.namespace,
47
+ "period" => alarm.period.to_s,
48
+ "statistic" => alarm.statistic,
49
+ "threshold" => alarm.threshold.to_s,
50
+ "unit" => sanitize(alarm.unit)
51
+ }
52
+ add_checksummed_attributes(attributes, alarm)
53
+ end
54
+
55
+ def alarms
56
+ @client.describe_alarms.map(&:metric_alarms).flatten
57
+ end
58
+
59
+ def module_name_of(alarm)
60
+ normalize_module_name(alarm.alarm_name)
61
+ end
62
+
63
+ def sanitize(argument)
64
+ argument.nil? ? "" : argument
65
+ end
66
+
67
+ def add_checksummed_attributes(attributes, alarm)
68
+ %w(insufficient_data_actions alarm_actions ok_actions dimensions).each do |action|
69
+ attribute = alarm.send(action.to_sym)
70
+ attributes["#{action}.#"] = attribute.size.to_s
71
+ attribute.each do |attr|
72
+ if attr.is_a? String
73
+ checksum = Zlib.crc32(attr)
74
+ value = attr
75
+ else
76
+ checksum = attr.name
77
+ value = attr.value
78
+ end
79
+ attributes["#{action}.#{checksum}"] = value
80
+ end
81
+ end
82
+
83
+ attributes
84
+ end
85
+ end
86
+ end
87
+ end
@@ -27,12 +27,13 @@ module Terraforming
27
27
  "name" => user.user_name,
28
28
  "path" => user.path,
29
29
  "unique_id" => user.user_id,
30
+ "force_destroy" => "false",
30
31
  }
31
32
  resources["aws_iam_user.#{module_name_of(user)}"] = {
32
33
  "type" => "aws_iam_user",
33
34
  "primary" => {
34
35
  "id" => user.user_name,
35
- "attributes" => attributes
36
+ "attributes" => attributes,
36
37
  }
37
38
  }
38
39
 
@@ -0,0 +1,33 @@
1
+ <% alarms.each do |alarm| -%>
2
+ resource "aws_cloudwatch_metric_alarm" "<%= normalize_module_name(alarm.alarm_name) %>" {
3
+ alarm_name = "<%= alarm.alarm_name %>"
4
+ comparison_operator = "<%= alarm.comparison_operator %>"
5
+ evaluation_periods = "<%= alarm.evaluation_periods %>"
6
+ metric_name = "<%= alarm.metric_name %>"
7
+ namespace = "<%= alarm.namespace %>"
8
+ period = "<%= alarm.period %>"
9
+ statistic = "<%= alarm.statistic %>"
10
+ threshold = "<%= alarm.threshold %>"
11
+ alarm_description = "<%= alarm.alarm_description %>"
12
+ <%- unless alarm.ok_actions.empty? -%>
13
+ ok_actions = <%= alarm.ok_actions %>
14
+ <%- end -%>
15
+ <%- unless alarm.alarm_actions.empty? -%>
16
+ alarm_actions = <%= alarm.alarm_actions %>
17
+ <%- end -%>
18
+ <%- unless alarm.actions_enabled -%>
19
+ actions_enabled = <%= alarm.actions_enabled %>
20
+ <%- end -%>
21
+ <%- unless alarm.dimensions.empty? -%>
22
+ dimensions {
23
+ <% alarm.dimensions.each do |dimension| -%>
24
+ <%= dimension.name %> = "<%= dimension.value %>"
25
+ <% end -%>
26
+ }
27
+ <%- end -%>
28
+ <%- unless alarm.insufficient_data_actions.empty? -%>
29
+ insufficient_data_actions = <%= alarm.insufficient_data_actions %>
30
+ <%- end -%>
31
+ }
32
+
33
+ <%- end -%>
@@ -27,10 +27,10 @@ resource "aws_instance" "<%= module_name_of(instance) %>" {
27
27
  root_block_device {
28
28
  volume_type = "<%= block_device.volume_type %>"
29
29
  volume_size = <%= block_device.size %>
30
- <%- if block_device.iops -%>
30
+ delete_on_termination = <%= mapping.ebs.delete_on_termination %>
31
+ <%- if block_device.volume_type == "io1" && block_device.iops -%>
31
32
  iops = <%= block_device.iops %>
32
33
  <%- end -%>
33
- delete_on_termination = <%= mapping.ebs.delete_on_termination %>
34
34
  }
35
35
  <%- else -%>
36
36
  ebs_block_device {
@@ -38,10 +38,10 @@ resource "aws_instance" "<%= module_name_of(instance) %>" {
38
38
  snapshot_id = "<%= block_device.snapshot_id %>"
39
39
  volume_type = "<%= block_device.volume_type %>"
40
40
  volume_size = <%= block_device.size %>
41
- <%- if block_device.iops -%>
41
+ delete_on_termination = <%= mapping.ebs.delete_on_termination %>
42
+ <%- if block_device.volume_type == "io1" && block_device.iops -%>
42
43
  iops = <%= block_device.iops %>
43
44
  <%- end -%>
44
- delete_on_termination = <%= mapping.ebs.delete_on_termination %>
45
45
  }
46
46
  <% end -%>
47
47
 
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
data/terraforming.gemspec CHANGED
@@ -19,14 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "aws-sdk", "~> 2.5.1"
23
- spec.add_dependency "oj", "~> 2.17.1"
24
- spec.add_dependency "ox", "~> 2.4.0"
22
+ spec.add_dependency "aws-sdk", "~> 2.6.1"
23
+ spec.add_dependency "multi_json", "~> 1.12.1"
25
24
  spec.add_dependency "thor"
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.7"
28
27
  spec.add_development_dependency "coveralls", "~> 0.8.13"
29
28
  spec.add_development_dependency "rake"
30
29
  spec.add_development_dependency "rspec", "~> 3.2"
31
- spec.add_development_dependency "simplecov", "~> 0.11.1"
30
+ spec.add_development_dependency "simplecov", "~> 0.12.0"
32
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraforming
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.1
19
+ version: 2.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.1
26
+ version: 2.6.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: oj
28
+ name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.17.1
33
+ version: 1.12.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.17.1
41
- - !ruby/object:Gem::Dependency
42
- name: ox
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 2.4.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 2.4.0
40
+ version: 1.12.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: thor
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +114,14 @@ dependencies:
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: 0.11.1
117
+ version: 0.12.0
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: 0.11.1
124
+ version: 0.12.0
139
125
  description: Export existing AWS resources to Terraform style (tf, tfstate)
140
126
  email:
141
127
  - dtanshi45@gmail.com
@@ -150,6 +136,7 @@ files:
150
136
  - ".travis.yml"
151
137
  - CHANGELOG.md
152
138
  - CODE_OF_CONDUCT.md
139
+ - CONTRIBUTING.md
153
140
  - Gemfile
154
141
  - Guardfile
155
142
  - LICENSE
@@ -160,6 +147,7 @@ files:
160
147
  - lib/terraforming.rb
161
148
  - lib/terraforming/cli.rb
162
149
  - lib/terraforming/resource/auto_scaling_group.rb
150
+ - lib/terraforming/resource/cloud_watch_alarm.rb
163
151
  - lib/terraforming/resource/db_parameter_group.rb
164
152
  - lib/terraforming/resource/db_security_group.rb
165
153
  - lib/terraforming/resource/db_subnet_group.rb
@@ -196,6 +184,7 @@ files:
196
184
  - lib/terraforming/resource/vpc.rb
197
185
  - lib/terraforming/resource/vpn_gateway.rb
198
186
  - lib/terraforming/template/tf/auto_scaling_group.erb
187
+ - lib/terraforming/template/tf/cloud_watch_alarm.erb
199
188
  - lib/terraforming/template/tf/db_parameter_group.erb
200
189
  - lib/terraforming/template/tf/db_security_group.erb
201
190
  - lib/terraforming/template/tf/db_subnet_group.erb