terraforming 0.3.2 → 0.4.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: 3d8063a94e5a55a6c2e02d54db3753f320c73066
4
- data.tar.gz: d77958c73ad676dff4e22ebee924b8ee0cdfd103
3
+ metadata.gz: 66c5df7584aafe8c899dd0fc56b1aa3c67afd047
4
+ data.tar.gz: c81276bc2e5fe556971f7ee27d67b89b581a8edc
5
5
  SHA512:
6
- metadata.gz: 65b64fe9016d48fddf60d257625520563699a5ca16846469df92be4fa1b19c7c4b64aefaaed7dcc43bd7ed962d5ece83af5eea8aac49974894fb964d2e543492
7
- data.tar.gz: d4a557a91a7fd86c9ec3c0185907fcb7007fffd72e8fba529620ae7539ea4da7fa47910611b76070638477bf25bdc58868a46d61df6e1c78ecf03f98cfc6c2a8
6
+ metadata.gz: f64e996eabafb2a6dc9457b8bc2f5d92cb833cdee12d8a26acc454445a60de89e15066804030f1c47d0d7a08b60ec9f5ac242475bf579811a9ae597a4e0412f2
7
+ data.tar.gz: 1b38d910a7f83523ad7833c98273f00021c0719e9d2c354cf6f3c812ab89f0d026390ca58c498162d0755f749de8f55d765efb026eb9f0a2262d2cc0cbc7551b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [v0.4.0](https://github.com/dtan4/terraforming/releases/tag/v0.4.0) (2015-10-06)
2
+
3
+ ## New feature
4
+
5
+ - Add `--profile` option to read credential profile #135 (thanks @k1LoW)
6
+
7
+ ## Resource
8
+
9
+ - AWS AutoScaling Group #134
10
+
1
11
  # [v0.3.2](https://github.com/dtan4/terraforming/releases/tag/v0.3.2) (2015-10-06)
2
12
 
3
13
  ## Fixed
data/README.md CHANGED
@@ -51,11 +51,24 @@ export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
51
51
  export AWS_DEFAULT_REGION=xx-yyyy-0
52
52
  ```
53
53
 
54
+ You can also specify credential profile in `~/.aws/credentials` by `--profile` option.
55
+
56
+ ```bash
57
+ $ cat ~/.aws/credentials
58
+ [hoge]
59
+ aws_access_key_id = Hoge
60
+ aws_secret_access_key = FugaFuga
61
+
62
+ # Pass profile name by --profile option
63
+ $ terraforming s3 --profile hoge
64
+ ```
65
+
54
66
  ## Usage
55
67
 
56
68
  ```bash
57
69
  $ terraforming
58
70
  Commands:
71
+ terraforming asg # AutoScaling Group
59
72
  terraforming dbpg # Database Parameter Group
60
73
  terraforming dbsg # Database Security Group
61
74
  terraforming dbsn # Database Subnet Group
@@ -85,7 +98,7 @@ Commands:
85
98
  ### Export tf
86
99
 
87
100
  ```bash
88
- $ terraforming <resource>
101
+ $ terraforming <resource> [--profile PROFILE]
89
102
  ```
90
103
 
91
104
  (e.g. S3 buckets):
@@ -109,7 +122,7 @@ resource "aws_s3_bucket" "fuga" {
109
122
  ### Export tfstate
110
123
 
111
124
  ```bash
112
- $ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite]
125
+ $ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite] [--profile PROFILE]
113
126
  ```
114
127
 
115
128
  (e.g. S3 buckets):
data/lib/terraforming.rb CHANGED
@@ -11,6 +11,7 @@ require "terraforming/util"
11
11
  require "terraforming/version"
12
12
 
13
13
  require "terraforming/cli"
14
+ require "terraforming/resource/auto_scaling_group"
14
15
  require "terraforming/resource/db_parameter_group"
15
16
  require "terraforming/resource/db_security_group"
16
17
  require "terraforming/resource/db_subnet_group"
@@ -3,6 +3,12 @@ module Terraforming
3
3
  class_option :merge, type: :string, desc: "tfstate file to merge"
4
4
  class_option :overwrite, type: :boolean, desc: "Overwrite existng tfstate"
5
5
  class_option :tfstate, type: :boolean, desc: "Generate tfstate"
6
+ class_option :profile, type: :string, desc: "AWS credentials profile"
7
+
8
+ desc "asg", "AutoScaling Group"
9
+ def asg
10
+ execute(Terraforming::Resource::AutoScalingGroup, options)
11
+ end
6
12
 
7
13
  desc "dbpg", "Database Parameter Group"
8
14
  def dbpg
@@ -137,6 +143,7 @@ module Terraforming
137
143
  private
138
144
 
139
145
  def execute(klass, options)
146
+ Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: options[:profile]) if options[:profile]
140
147
  result = options[:tfstate] ? tfstate(klass, options[:merge]) : tf(klass)
141
148
 
142
149
  if options[:tfstate] && options[:merge] && options[:overwrite]
@@ -0,0 +1,90 @@
1
+ module Terraforming
2
+ module Resource
3
+ class AutoScalingGroup
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::AutoScaling::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::AutoScaling::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/auto_scaling_group")
20
+ end
21
+
22
+ def tfstate
23
+ auto_scaling_groups.inject({}) do |resources, group|
24
+ vpc_zone_specified = vpc_zone_specified?(group)
25
+
26
+ attributes = {
27
+ "availability_zones.#" => vpc_zone_specified ? "0" : group.availability_zones.length.to_s,
28
+ "default_cooldown" => "300",
29
+ "desired_capacity" => group.desired_capacity.to_s,
30
+ "health_check_grace_period" => group.health_check_grace_period.to_s,
31
+ "health_check_type" => group.health_check_type,
32
+ "id" => group.auto_scaling_group_name,
33
+ "launch_configuration" => group.launch_configuration_name,
34
+ "load_balancers.#" => "0",
35
+ "max_size" => group.max_size.to_s,
36
+ "min_size" => group.min_size.to_s,
37
+ "name" => group.auto_scaling_group_name,
38
+ "tag.#" => group.tags.length.to_s,
39
+ "termination_policies.#" => "0",
40
+ "vpc_zone_identifier.#" => vpc_zone_specified ? vpc_zone_identifier_of(group).length.to_s : "0",
41
+ }
42
+
43
+ group.tags.each do |tag|
44
+ hashcode = tag_hashcode_of(tag)
45
+ attributes.merge!({
46
+ "tag.#{hashcode}.key" => tag.key,
47
+ "tag.#{hashcode}.propagate_at_launch" => tag.propagate_at_launch.to_s,
48
+ "tag.#{hashcode}.value" => tag.value,
49
+ })
50
+ end
51
+
52
+ resources["aws_autoscaling_group.#{module_name_of(group)}"] = {
53
+ "type" => "aws_autoscaling_group",
54
+ "primary" => {
55
+ "id" => group.auto_scaling_group_name,
56
+ "attributes" => attributes,
57
+ "meta" => {
58
+ "schema_version" => "1"
59
+ }
60
+ }
61
+ }
62
+
63
+ resources
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def auto_scaling_groups
70
+ @client.describe_auto_scaling_groups.auto_scaling_groups
71
+ end
72
+
73
+ def module_name_of(group)
74
+ normalize_module_name(group.auto_scaling_group_name)
75
+ end
76
+
77
+ def tag_hashcode_of(tag)
78
+ Zlib.crc32("#{tag.key}-#{tag.value}-#{tag.propagate_at_launch}-")
79
+ end
80
+
81
+ def vpc_zone_identifier_of(group)
82
+ group.vpc_zone_identifier.split(",")
83
+ end
84
+
85
+ def vpc_zone_specified?(group)
86
+ group.vpc_zone_identifier && vpc_zone_identifier_of(group).length > 0
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,27 @@
1
+ <% auto_scaling_groups.each do |group| -%>
2
+ <%- vpc_zone_specified = vpc_zone_specified?(group) -%>
3
+ resource "aws_autoscaling_group" "<%= module_name_of(group) %>" {
4
+ <%- unless vpc_zone_specified -%>
5
+ availability_zones = <%= group.availability_zones.inspect %>
6
+ <%- end -%>
7
+ desired_capacity = <%= group.desired_capacity %>
8
+ health_check_grace_period = <%= group.health_check_grace_period %>
9
+ health_check_type = "<%= group.health_check_type %>"
10
+ launch_configuration = "<%= group.launch_configuration_name %>"
11
+ max_size = <%= group.max_size %>
12
+ min_size = <%= group.min_size %>
13
+ name = "<%= group.auto_scaling_group_name %>"
14
+ <%- if vpc_zone_specified -%>
15
+ vpc_zone_identifier = <%= vpc_zone_identifier_of(group).inspect %>
16
+ <%- end -%>
17
+
18
+ tag {
19
+ <% group.tags.each do |tag| -%>
20
+ key = "<%= tag.key %>"
21
+ value = "<%= tag.value %>"
22
+ propagate_at_launch = <%= tag.propagate_at_launch.to_s %>
23
+ <% end -%>
24
+ }
25
+ }
26
+
27
+ <% end -%>
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  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.3.2
4
+ version: 0.4.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: 2015-10-05 00:00:00.000000000 Z
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -185,6 +185,7 @@ files:
185
185
  - bin/terraforming
186
186
  - lib/terraforming.rb
187
187
  - lib/terraforming/cli.rb
188
+ - lib/terraforming/resource/auto_scaling_group.rb
188
189
  - lib/terraforming/resource/db_parameter_group.rb
189
190
  - lib/terraforming/resource/db_security_group.rb
190
191
  - lib/terraforming/resource/db_subnet_group.rb
@@ -211,6 +212,7 @@ files:
211
212
  - lib/terraforming/resource/security_group.rb
212
213
  - lib/terraforming/resource/subnet.rb
213
214
  - lib/terraforming/resource/vpc.rb
215
+ - lib/terraforming/template/tf/auto_scaling_group.erb
214
216
  - lib/terraforming/template/tf/db_parameter_group.erb
215
217
  - lib/terraforming/template/tf/db_security_group.erb
216
218
  - lib/terraforming/template/tf/db_subnet_group.erb