terraforming 0.11.0 → 0.12.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: cb884d952f74d4079fcfb52bc4798a8a90d98587
4
- data.tar.gz: 23fe2b8eeb2eea9843ecaf1dee41c5a387ea2a57
3
+ metadata.gz: 0207edd5bbc29b4447cf4a914e4a015baff47d71
4
+ data.tar.gz: dfccf028d7c75bf7a9985c918381e35844def811
5
5
  SHA512:
6
- metadata.gz: 72708c53e470e3d7b7d673b51b22bcd81a83af77e18e5166008880c164e14da85c16646bb20b91a6922c51bb88b914b365e4b14785e45a9152cc580567e62444
7
- data.tar.gz: 810a584ff6e7b4f5ba4e4a07a44ae4685b629eb4ec523bf8f7397bb362b7de9134ff9654a31105dc06cccf8993ed87d7a99b8ac8a1510793cc929795f0c2efc5
6
+ metadata.gz: 61254cf936a3ab76a5ea25b3c3ce53bc9384d6ba79322932fb6340d06884ad9c2824f9d654ed4370b72da7c0f4131d6c5aa97baf7a390a748c8dbc72285906c0
7
+ data.tar.gz: 59059b7a2d224657436234c2ac2c77e685346e288f81bb2427e11b071f353f2c1e828dbb20f350fbecb602631061e7efdfc63c6287287405147022956a813435
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # [v0.12.0](https://github.com/dtan4/terraforming/releases/tag/v0.11.0) (2016-12-20)
2
+
3
+ ## Resource
4
+
5
+ - AWS ALB [#291](https://github.com/dtan4/terraforming/pull/291)
6
+ - AWS EFS File System [#283](https://github.com/dtan4/terraforming/pull/283) (thanks @notjames)
7
+
8
+ ## Fixed / Updated
9
+
10
+ - Fix associate_public_ip_address attr for EC2 [#287](https://github.com/dtan4/terraforming/pull/287) (thanks @diwaniuk)
11
+
1
12
  # [v0.11.0](https://github.com/dtan4/terraforming/releases/tag/v0.11.0) (2016-11-14)
2
13
 
3
14
  ## Resource
data/README.md CHANGED
@@ -76,6 +76,7 @@ PS C:\> terraforming ec2 --use-bundled-cert
76
76
  ```bash
77
77
  $ terraforming
78
78
  Commands:
79
+ terraforming alb # ALB
79
80
  terraforming asg # AutoScaling Group
80
81
  terraforming cwa # CloudWatch Alarm
81
82
  terraforming dbpg # Database Parameter Group
@@ -84,6 +85,7 @@ Commands:
84
85
  terraforming ec2 # EC2
85
86
  terraforming ecc # ElastiCache Cluster
86
87
  terraforming ecsn # ElastiCache Subnet Group
88
+ terraforming efs # EFS File System
87
89
  terraforming eip # EIP
88
90
  terraforming elb # ELB
89
91
  terraforming help [COMMAND] # Describe available commands or one specific command
data/lib/terraforming.rb CHANGED
@@ -8,6 +8,7 @@ require "terraforming/util"
8
8
  require "terraforming/version"
9
9
 
10
10
  require "terraforming/cli"
11
+ require "terraforming/resource/alb"
11
12
  require "terraforming/resource/auto_scaling_group"
12
13
  require "terraforming/resource/cloud_watch_alarm"
13
14
  require "terraforming/resource/db_parameter_group"
@@ -17,6 +18,7 @@ require "terraforming/resource/ec2"
17
18
  require "terraforming/resource/eip"
18
19
  require "terraforming/resource/elasti_cache_cluster"
19
20
  require "terraforming/resource/elasti_cache_subnet_group"
21
+ require "terraforming/resource/efs_file_system"
20
22
  require "terraforming/resource/elb"
21
23
  require "terraforming/resource/iam_group"
22
24
  require "terraforming/resource/iam_group_membership"
@@ -9,6 +9,11 @@ module Terraforming
9
9
  type: :boolean,
10
10
  desc: "Use the bundled CA certificate from AWS SDK"
11
11
 
12
+ desc "alb", "ALB"
13
+ def alb
14
+ execute(Terraforming::Resource::ALB, options)
15
+ end
16
+
12
17
  desc "asg", "AutoScaling Group"
13
18
  def asg
14
19
  execute(Terraforming::Resource::AutoScalingGroup, options)
@@ -54,6 +59,11 @@ module Terraforming
54
59
  execute(Terraforming::Resource::EIP, options)
55
60
  end
56
61
 
62
+ desc "efs", "EFS File System"
63
+ def efs
64
+ execute(Terraforming::Resource::EFSFileSystem, options)
65
+ end
66
+
57
67
  desc "elb", "ELB"
58
68
  def elb
59
69
  execute(Terraforming::Resource::ELB, options)
@@ -0,0 +1,98 @@
1
+ module Terraforming
2
+ module Resource
3
+ class ALB
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::ElasticLoadBalancingV2::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::ElasticLoadBalancingV2::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/alb")
20
+ end
21
+
22
+ def tfstate
23
+ load_balancers.inject({}) do |resources, load_balancer|
24
+ load_balancer_attributes = load_balancer_attributes_of(load_balancer)
25
+ attributes = {
26
+ "dns_name" => load_balancer.dns_name,
27
+ "enable_deletion_protection" => load_balancer_attributes["deletion_protection.enabled"].to_s,
28
+ "id" => load_balancer.load_balancer_arn,
29
+ "idle_timeout" => load_balancer_attributes["idle_timeout.timeout_seconds"].to_s,
30
+ "internal" => internal?(load_balancer).to_s,
31
+ "name" => load_balancer.load_balancer_name,
32
+ "security_groups.#" => load_balancer.security_groups.length.to_s,
33
+ "subnets.#" => load_balancer.availability_zones.length.to_s,
34
+ "zone_id" => load_balancer.canonical_hosted_zone_id,
35
+ }
36
+
37
+ attributes.merge!(access_logs_attributes_of(load_balancer_attributes))
38
+ attributes.merge!(tag_attributes_of(load_balancer))
39
+
40
+ resources["aws_alb.#{module_name_of(load_balancer)}"] = {
41
+ "type" => "aws_alb",
42
+ "primary" => {
43
+ "id" => load_balancer.load_balancer_arn,
44
+ "attributes" => attributes
45
+ }
46
+ }
47
+
48
+ resources
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def access_logs_attributes_of(load_balancer_attributes)
55
+ {
56
+ "access_logs.#" => "1",
57
+ "access_logs.0.bucket" => load_balancer_attributes["access_logs.s3.bucket"],
58
+ "access_logs.0.enabled" => load_balancer_attributes["access_logs.s3.enabled"].to_s,
59
+ "access_logs.0.prefix" => load_balancer_attributes["access_logs.s3.prefix"],
60
+ }
61
+ end
62
+
63
+ def internal?(load_balancer)
64
+ load_balancer.scheme == "internal"
65
+ end
66
+
67
+ def load_balancers
68
+ @client.describe_load_balancers.load_balancers
69
+ end
70
+
71
+ def load_balancer_attributes_of(load_balancer)
72
+ @client.describe_load_balancer_attributes(load_balancer_arn: load_balancer.load_balancer_arn).attributes.inject({}) do |result, attribute|
73
+ result[attribute.key] = attribute.value
74
+ result
75
+ end
76
+ end
77
+
78
+ def module_name_of(load_balancer)
79
+ normalize_module_name(load_balancer.load_balancer_name)
80
+ end
81
+
82
+ def tag_attributes_of(load_balancer)
83
+ tags = tags_of(load_balancer)
84
+ attributes = { "tags.%" => tags.length.to_s }
85
+
86
+ tags.each do |tag|
87
+ attributes["tags.#{tag.key}"] = tag.value
88
+ end
89
+
90
+ attributes
91
+ end
92
+
93
+ def tags_of(load_balancer)
94
+ @client.describe_tags(resource_arns: [load_balancer.load_balancer_arn]).tag_descriptions.first.tags
95
+ end
96
+ end
97
+ end
98
+ end
@@ -26,7 +26,7 @@ module Terraforming
26
26
 
27
27
  attributes = {
28
28
  "ami" => instance.image_id,
29
- "associate_public_ip_address" => "true",
29
+ "associate_public_ip_address" => associate_public_ip?(instance).to_s,
30
30
  "availability_zone" => instance.placement.availability_zone,
31
31
  "ebs_block_device.#" => ebs_block_devices_in(block_devices, instance).length.to_s,
32
32
  "ebs_optimized" => instance.ebs_optimized.to_s,
@@ -96,6 +96,10 @@ module Terraforming
96
96
  (instance.subnet_id && instance.subnet_id != "" && instance.security_groups.empty?)
97
97
  end
98
98
 
99
+ def associate_public_ip?(instance)
100
+ !instance.public_ip_address.to_s.empty?
101
+ end
102
+
99
103
  def monitoring_state(instance)
100
104
  %w(enabled pending).include?(instance.monitoring.state)
101
105
  end
@@ -0,0 +1,56 @@
1
+ module Terraforming
2
+ module Resource
3
+ class EFSFileSystem
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::EFS::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::EFS::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/elastic_filesystem")
20
+ end
21
+
22
+ def tfstate
23
+ file_systems.inject({}) do |resources, efs|
24
+ attributes = {
25
+ "creation_token" => efs.creation_token,
26
+ "id" => efs.file_system_id,
27
+ "performance_mode" => efs.performance_mode,
28
+ "tags.%" => "1",
29
+ "tags.Name" => efs.name,
30
+ }
31
+
32
+ resources["aws_efs_file_system.#{efs.file_system_id}"] = {
33
+ "type" => "aws_efs_file_system",
34
+ "depends_on" => [],
35
+ "primary" => {
36
+ "id" => efs.file_system_id,
37
+ "attributes" => attributes,
38
+ "meta" => {},
39
+ "tainted" => false,
40
+ },
41
+ "deposed" => [],
42
+ "provider" => "aws",
43
+ }
44
+
45
+ resources
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def file_systems
52
+ @client.describe_file_systems.data.file_systems.flatten
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ <% load_balancers.each do |load_balancer| -%>
2
+ <%- load_balancer_attributes = load_balancer_attributes_of(load_balancer) -%>
3
+ <%- tags = tags_of(load_balancer) -%>
4
+ resource "aws_alb" "<%= module_name_of(load_balancer) %>" {
5
+ idle_timeout = <%= load_balancer_attributes["idle_timeout.timeout_seconds"] %>
6
+ internal = <%= internal?(load_balancer).to_s %>
7
+ name = "<%= load_balancer.load_balancer_name %>"
8
+ security_groups = <%= load_balancer.security_groups.inspect %>
9
+ subnets = <%= load_balancer.availability_zones.map { |az| az.subnet_id }.inspect %>
10
+
11
+ enable_deletion_protection = <%= load_balancer_attributes["deletion_protection.enabled"].to_s %>
12
+
13
+ <%- if load_balancer_attributes["access_logs.s3.enabled"] == "true" -%>
14
+ access_logs {
15
+ bucket = "<%= load_balancer_attributes["access_logs.s3.bucket"] %>"
16
+ enabled = <%= load_balancer_attributes["access_logs.s3.enabled"] %>
17
+ prefix = "<%= load_balancer_attributes["access_logs.s3.prefix"] %>"
18
+ }
19
+
20
+ <%- end -%>
21
+ tags {
22
+ <% tags.each do |tag| -%>
23
+ "<%= tag.key %>" = "<%= tag.value %>"
24
+ <% end -%>
25
+ }
26
+ }
27
+
28
+ <% end -%>
@@ -15,7 +15,7 @@ resource "aws_instance" "<%= module_name_of(instance) %>" {
15
15
  <%- else -%>
16
16
  security_groups = <%= instance.security_groups.map { |sg| sg.group_name }.inspect %>
17
17
  <%- end -%>
18
- associate_public_ip_address = true
18
+ associate_public_ip_address = <%= associate_public_ip?(instance) %>
19
19
  private_ip = "<%= instance.private_ip_address %>"
20
20
  <%- if instance.source_dest_check -%>
21
21
  source_dest_check = <%= instance.source_dest_check %>
@@ -0,0 +1,18 @@
1
+ <% file_systems.each_with_index do |efs, idx| -%>
2
+ resource "aws_efs_file_system" "<%= efs.file_system_id %>" {
3
+ <% if efs.creation_token -%>
4
+ creation_token = "<%= efs.creation_token %>"
5
+ <% end -%>
6
+ <% if efs.file_system_id -%>
7
+ file_system_id = "<%= efs.file_system_id %>"
8
+ <% end -%>
9
+ <% if efs.performance_mode -%>
10
+ performance_mode = "<%= efs.performance_mode %>"
11
+ <% end -%>
12
+ <% if efs.name -%>
13
+ tags {
14
+ Name = "<%= efs.name %>"
15
+ }
16
+ <% end -%>
17
+ }
18
+ <% end -%>
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.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.11.0
4
+ version: 0.12.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-11-14 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -146,12 +146,14 @@ files:
146
146
  - contrib/zsh-completion/_terraforming
147
147
  - lib/terraforming.rb
148
148
  - lib/terraforming/cli.rb
149
+ - lib/terraforming/resource/alb.rb
149
150
  - lib/terraforming/resource/auto_scaling_group.rb
150
151
  - lib/terraforming/resource/cloud_watch_alarm.rb
151
152
  - lib/terraforming/resource/db_parameter_group.rb
152
153
  - lib/terraforming/resource/db_security_group.rb
153
154
  - lib/terraforming/resource/db_subnet_group.rb
154
155
  - lib/terraforming/resource/ec2.rb
156
+ - lib/terraforming/resource/efs_file_system.rb
155
157
  - lib/terraforming/resource/eip.rb
156
158
  - lib/terraforming/resource/elasti_cache_cluster.rb
157
159
  - lib/terraforming/resource/elasti_cache_subnet_group.rb
@@ -183,6 +185,7 @@ files:
183
185
  - lib/terraforming/resource/subnet.rb
184
186
  - lib/terraforming/resource/vpc.rb
185
187
  - lib/terraforming/resource/vpn_gateway.rb
188
+ - lib/terraforming/template/tf/alb.erb
186
189
  - lib/terraforming/template/tf/auto_scaling_group.erb
187
190
  - lib/terraforming/template/tf/cloud_watch_alarm.erb
188
191
  - lib/terraforming/template/tf/db_parameter_group.erb
@@ -192,6 +195,7 @@ files:
192
195
  - lib/terraforming/template/tf/eip.erb
193
196
  - lib/terraforming/template/tf/elasti_cache_cluster.erb
194
197
  - lib/terraforming/template/tf/elasti_cache_subnet_group.erb
198
+ - lib/terraforming/template/tf/elastic_filesystem.erb
195
199
  - lib/terraforming/template/tf/elb.erb
196
200
  - lib/terraforming/template/tf/iam_group.erb
197
201
  - lib/terraforming/template/tf/iam_group_membership.erb
@@ -245,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
249
  version: '0'
246
250
  requirements: []
247
251
  rubyforge_project:
248
- rubygems_version: 2.5.1
252
+ rubygems_version: 2.5.2
249
253
  signing_key:
250
254
  specification_version: 4
251
255
  summary: Export existing AWS resources to Terraform style (tf, tfstate)