terraforming 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +12 -2
  4. data/lib/terraforming.rb +4 -0
  5. data/lib/terraforming/cli.rb +33 -20
  6. data/lib/terraforming/resource/db_parameter_group.rb +5 -5
  7. data/lib/terraforming/resource/db_security_group.rb +5 -5
  8. data/lib/terraforming/resource/db_subnet_group.rb +5 -5
  9. data/lib/terraforming/resource/ec2.rb +5 -5
  10. data/lib/terraforming/resource/elb.rb +9 -5
  11. data/lib/terraforming/resource/iam_group.rb +5 -5
  12. data/lib/terraforming/resource/iam_group_policy.rb +6 -6
  13. data/lib/terraforming/resource/iam_instance_profile.rb +52 -0
  14. data/lib/terraforming/resource/iam_policy.rb +6 -6
  15. data/lib/terraforming/resource/iam_role.rb +53 -0
  16. data/lib/terraforming/resource/iam_role_policy.rb +69 -0
  17. data/lib/terraforming/resource/iam_user.rb +5 -5
  18. data/lib/terraforming/resource/iam_user_policy.rb +6 -6
  19. data/lib/terraforming/resource/network_acl.rb +10 -5
  20. data/lib/terraforming/resource/rds.rb +5 -5
  21. data/lib/terraforming/resource/route53_record.rb +5 -5
  22. data/lib/terraforming/resource/route53_zone.rb +5 -5
  23. data/lib/terraforming/resource/s3.rb +5 -5
  24. data/lib/terraforming/resource/security_group.rb +86 -7
  25. data/lib/terraforming/resource/subnet.rb +5 -5
  26. data/lib/terraforming/resource/vpc.rb +5 -5
  27. data/lib/terraforming/template/tf/elb.erb +4 -1
  28. data/lib/terraforming/template/tf/iam_group_policy.erb +1 -1
  29. data/lib/terraforming/template/tf/iam_instance_profile.erb +8 -0
  30. data/lib/terraforming/template/tf/iam_policy.erb +1 -1
  31. data/lib/terraforming/template/tf/iam_role.erb +10 -0
  32. data/lib/terraforming/template/tf/iam_role_policy.erb +10 -0
  33. data/lib/terraforming/template/tf/iam_user_policy.erb +1 -1
  34. data/lib/terraforming/template/tf/network_acl.erb +2 -1
  35. data/lib/terraforming/template/tf/security_group.erb +11 -2
  36. data/lib/terraforming/util.rb +21 -6
  37. data/lib/terraforming/version.rb +1 -1
  38. data/terraforming.gemspec +1 -1
  39. metadata +11 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7a02d6cfb8ee138645ef72e09e2f1f785ad482a
4
- data.tar.gz: 75571c29e0dc1c7335df48c2842daf40d0487d04
3
+ metadata.gz: bc34e08ee4b6f0d0723edb9f2fc4be372b3892c2
4
+ data.tar.gz: c1d7da734fed9e4502ece8d0914b6283c2acc93a
5
5
  SHA512:
6
- metadata.gz: bae5fcdafee7f5616d4f1efa412b3b814aca328734a82852e256ddd8bf0f689328ade7701395ab31202c17258048448c4004a78cb6ed575ab1020101ce374ab5
7
- data.tar.gz: 6d61f42f177ece0a6a6d0553d4c7e400cb8e212a17bbc0c6363af623d531e91a7e9b7419bcac7fd621295488346bd3ab9f6e02de045c043f031880920b66af1a
6
+ metadata.gz: e4f61751c5ff99acda6d6b64cc7f56103b37e02aa59f0d26af7a6d36a628d78fe911b9b8e1a32f5e73ec9a7d32f46cfd846e5f9a3bdfb05867ac27aa2334220f
7
+ data.tar.gz: b8183e1c9dd3b21454f3fd5a1d422c4985db24a57d25f71409e0a8761ba80921bcf0538daace8a8d4bd8402b16a8e887ac403f0a1cc47d2da674c433bd0a9d68
data/CHANGELOG.md CHANGED
@@ -1,4 +1,19 @@
1
- # v0.1.0 (UNRELEASED)
1
+ # [v0.1.0](https://github.com/dtan4/terraforming/releases/tag/v0.1.0) (2015-06-20)
2
+
3
+ ### New feature
4
+
5
+ - `--merge TFSTATE_PATH` option: Merge generated tfstate to specified `terraform.tfstate`
6
+
7
+ ### Fixed
8
+
9
+ - ELB must include either AZs or Subnets
10
+ - Include AWS Network ACL subnet ids
11
+
12
+ ### Resource
13
+
14
+ - AWS IAM instance profile
15
+ - AWS IAM role
16
+ - AWS IAM role policy
2
17
 
3
18
  # [v0.0.5](https://github.com/dtan4/terraforming/releases/tag/v0.0.5) (2015-06-01)
4
19
 
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/dtan4/terraforming.svg?branch=master)](https://travis-ci.org/dtan4/terraforming)
4
4
  [![Code Climate](https://codeclimate.com/github/dtan4/terraforming/badges/gpa.svg)](https://codeclimate.com/github/dtan4/terraforming)
5
5
  [![Test Coverage](https://codeclimate.com/github/dtan4/terraforming/badges/coverage.svg)](https://codeclimate.com/github/dtan4/terraforming)
6
+ [![Dependency Status](https://gemnasium.com/dtan4/terraforming.svg)](https://gemnasium.com/dtan4/terraforming)
6
7
  [![Gem Version](https://badge.fury.io/rb/terraforming.svg)](http://badge.fury.io/rb/terraforming)
7
8
  [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
8
9
  [![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
@@ -45,11 +46,20 @@ Commands:
45
46
  terraforming dbsn # Database Subnet Group
46
47
  terraforming ec2 # EC2
47
48
  terraforming elb # ELB
48
- terraforming help [COMMAND] # Describe available commands or one specific command
49
+ terraforming iamg # IAM Group
50
+ terraforming iamgp # IAM Group Policy
51
+ terraforming iamip # IAM Instance Profile
52
+ terraforming iamp # IAM Policy
53
+ terraforming iamr # IAM Role
54
+ terraforming iamrp # IAM Role Policy
55
+ terraforming iamu # IAM User
56
+ terraforming iamup # IAM User Policy
49
57
  terraforming nacl # Network ACL
58
+ terraforming r53r # Route53 Record
59
+ terraforming r53z # Route53 Hosted Zone
50
60
  terraforming rds # RDS
51
61
  terraforming s3 # S3
52
- terraforming sg # SecurityGroup
62
+ terraforming sg # Security Group
53
63
  terraforming sn # Subnet
54
64
  terraforming vpc # VPC
55
65
  ```
data/lib/terraforming.rb CHANGED
@@ -5,6 +5,7 @@ require "aws-sdk-core"
5
5
  require "erb"
6
6
  require "json"
7
7
  require "thor"
8
+ require "zlib"
8
9
 
9
10
  require "terraforming/util"
10
11
  require "terraforming/version"
@@ -17,7 +18,10 @@ require "terraforming/resource/ec2"
17
18
  require "terraforming/resource/elb"
18
19
  require "terraforming/resource/iam_group"
19
20
  require "terraforming/resource/iam_group_policy"
21
+ require "terraforming/resource/iam_instance_profile"
20
22
  require "terraforming/resource/iam_policy"
23
+ require "terraforming/resource/iam_role"
24
+ require "terraforming/resource/iam_role_policy"
21
25
  require "terraforming/resource/iam_user"
22
26
  require "terraforming/resource/iam_user_policy"
23
27
  require "terraforming/resource/network_acl"
@@ -1,109 +1,109 @@
1
1
  module Terraforming
2
2
  class CLI < Thor
3
+ class_option :merge, type: :string, desc: "tfstate file to merge"
4
+ class_option :tfstate, type: :boolean, desc: "Generate tfstate"
5
+
3
6
  desc "dbpg", "Database Parameter Group"
4
- option :tfstate, type: :boolean
5
7
  def dbpg
6
8
  execute(Terraforming::Resource::DBParameterGroup, options)
7
9
  end
8
10
 
9
11
  desc "dbsg", "Database Security Group"
10
- option :tfstate, type: :boolean
11
12
  def dbsg
12
13
  execute(Terraforming::Resource::DBSecurityGroup, options)
13
14
  end
14
15
 
15
16
  desc "dbsn", "Database Subnet Group"
16
- option :tfstate, type: :boolean
17
17
  def dbsn
18
18
  execute(Terraforming::Resource::DBSubnetGroup, options)
19
19
  end
20
20
 
21
21
  desc "ec2", "EC2"
22
- option :tfstate, type: :boolean
23
22
  def ec2
24
23
  execute(Terraforming::Resource::EC2, options)
25
24
  end
26
25
 
27
26
  desc "elb", "ELB"
28
- option :tfstate, type: :boolean
29
27
  def elb
30
28
  execute(Terraforming::Resource::ELB, options)
31
29
  end
32
30
 
33
31
  desc "iamg", "IAM Group"
34
- option :tfstate, type: :boolean
35
32
  def iamg
36
33
  execute(Terraforming::Resource::IAMGroup, options)
37
34
  end
38
35
 
39
36
  desc "iamgp", "IAM Group Policy"
40
- option :tfstate, type: :boolean
41
37
  def iamgp
42
38
  execute(Terraforming::Resource::IAMGroupPolicy, options)
43
39
  end
44
40
 
41
+ desc "iamip", "IAM Instance Profile"
42
+ def iamip
43
+ execute(Terraforming::Resource::IAMInstanceProfile, options)
44
+ end
45
+
45
46
  desc "iamp", "IAM Policy"
46
- option :tfstate, type: :boolean
47
47
  def iamp
48
48
  execute(Terraforming::Resource::IAMPolicy, options)
49
49
  end
50
50
 
51
+ desc "iamr", "IAM Role"
52
+ def iamr
53
+ execute(Terraforming::Resource::IAMRole, options)
54
+ end
55
+
56
+ desc "iamrp", "IAM Role Policy"
57
+ def iamrp
58
+ execute(Terraforming::Resource::IAMRolePolicy, options)
59
+ end
60
+
51
61
  desc "iamu", "IAM User"
52
- option :tfstate, type: :boolean
53
62
  def iamu
54
63
  execute(Terraforming::Resource::IAMUser, options)
55
64
  end
56
65
 
57
66
  desc "iamup", "IAM User Policy"
58
- option :tfstate, type: :boolean
59
67
  def iamup
60
68
  execute(Terraforming::Resource::IAMUserPolicy, options)
61
69
  end
62
70
 
63
71
  desc "nacl", "Network ACL"
64
- option :tfstate, type: :boolean
65
72
  def nacl
66
73
  execute(Terraforming::Resource::NetworkACL, options)
67
74
  end
68
75
 
69
76
  desc "r53r", "Route53 Record"
70
- option :tfstate, type: :boolean
71
77
  def r53r
72
78
  execute(Terraforming::Resource::Route53Record, options)
73
79
  end
74
80
 
75
81
  desc "r53z", "Route53 Hosted Zone"
76
- option :tfstate, type: :boolean
77
82
  def r53z
78
83
  execute(Terraforming::Resource::Route53Zone, options)
79
84
  end
80
85
 
81
86
  desc "rds", "RDS"
82
- option :tfstate, type: :boolean
83
87
  def rds
84
88
  execute(Terraforming::Resource::RDS, options)
85
89
  end
86
90
 
87
91
  desc "s3", "S3"
88
- option :tfstate, type: :boolean
89
92
  def s3
90
93
  execute(Terraforming::Resource::S3, options)
91
94
  end
92
95
 
93
- desc "sg", "SecurityGroup"
94
- option :tfstate, type: :boolean
96
+ desc "sg", "Security Group"
95
97
  def sg
96
98
  execute(Terraforming::Resource::SecurityGroup, options)
97
99
  end
98
100
 
99
101
  desc "sn", "Subnet"
100
- option :tfstate, type: :boolean
101
102
  def sn
102
103
  execute(Terraforming::Resource::Subnet, options)
103
104
  end
104
105
 
105
106
  desc "vpc", "VPC"
106
- option :tfstate, type: :boolean
107
107
  def vpc
108
108
  execute(Terraforming::Resource::VPC, options)
109
109
  end
@@ -111,7 +111,20 @@ module Terraforming
111
111
  private
112
112
 
113
113
  def execute(klass, options)
114
- puts options[:tfstate] ? klass.tfstate : klass.tf
114
+ result = if options[:tfstate]
115
+ tfstate(klass, options[:merge])
116
+ else
117
+ klass.tf
118
+ end
119
+
120
+ puts result
121
+ end
122
+
123
+ def tfstate(klass, tfstate_path)
124
+ return klass.tfstate unless tfstate_path
125
+
126
+ base_tfstate = JSON.parse(open(tfstate_path).read)
127
+ klass.tfstate(tfstate_base: base_tfstate)
115
128
  end
116
129
  end
117
130
  end
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class DBParameterGroup
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::RDS::Client.new)
6
+ def self.tf(client: Aws::RDS::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::RDS::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::RDS::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/db_parameter_group")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = db_parameter_groups.inject({}) do |result, parameter_group|
24
24
  attributes = {
25
25
  "description" => parameter_group.description,
@@ -39,7 +39,7 @@ module Terraforming
39
39
  result
40
40
  end
41
41
 
42
- generate_tfstate(resources)
42
+ generate_tfstate(resources, tfstate_base)
43
43
  end
44
44
 
45
45
  private
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class DBSecurityGroup
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::RDS::Client.new)
6
+ def self.tf(client: Aws::RDS::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::RDS::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::RDS::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/db_security_group")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = db_security_groups.inject({}) do |result, security_group|
24
24
  attributes = {
25
25
  "db_subnet_group_name" => security_group.db_security_group_name,
@@ -38,7 +38,7 @@ module Terraforming
38
38
  result
39
39
  end
40
40
 
41
- generate_tfstate(resources)
41
+ generate_tfstate(resources, tfstate_base)
42
42
  end
43
43
 
44
44
  private
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class DBSubnetGroup
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::RDS::Client.new)
6
+ def self.tf(client: Aws::RDS::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::RDS::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::RDS::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/db_subnet_group")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = db_subnet_groups.inject({}) do |result, subnet_group|
24
24
  attributes = {
25
25
  "description" => subnet_group.db_subnet_group_description,
@@ -37,7 +37,7 @@ module Terraforming
37
37
  result
38
38
  end
39
39
 
40
- generate_tfstate(resources)
40
+ generate_tfstate(resources, tfstate_base)
41
41
  end
42
42
 
43
43
  private
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class EC2
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::EC2::Client.new)
6
+ def self.tf(client: Aws::EC2::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::EC2::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::EC2::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/ec2")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = instances.inject({}) do |result, instance|
24
24
  attributes = {
25
25
  "ami"=> instance.image_id,
@@ -54,7 +54,7 @@ module Terraforming
54
54
  result
55
55
  end
56
56
 
57
- generate_tfstate(resources)
57
+ generate_tfstate(resources, tfstate_base)
58
58
  end
59
59
 
60
60
  private
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class ELB
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::ElasticLoadBalancing::Client.new)
6
+ def self.tf(client: Aws::ElasticLoadBalancing::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::ElasticLoadBalancing::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::ElasticLoadBalancing::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/elb")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = load_balancers.inject({}) do |result, load_balancer|
24
24
  load_balancer_attributes = load_balancer_attributes_of(load_balancer)
25
25
  attributes = {
@@ -49,7 +49,7 @@ module Terraforming
49
49
  result
50
50
  end
51
51
 
52
- generate_tfstate(resources)
52
+ generate_tfstate(resources, tfstate_base)
53
53
  end
54
54
 
55
55
  def load_balancers
@@ -63,6 +63,10 @@ module Terraforming
63
63
  def module_name_of(load_balancer)
64
64
  normalize_module_name(load_balancer.load_balancer_name)
65
65
  end
66
+
67
+ def vpc_elb?(load_balancer)
68
+ load_balancer.vpc_id != ""
69
+ end
66
70
  end
67
71
  end
68
72
  end
@@ -3,12 +3,12 @@ module Terraforming
3
3
  class IAMGroup
4
4
  include Terraforming::Util
5
5
 
6
- def self.tf(client = Aws::IAM::Client.new)
6
+ def self.tf(client: Aws::IAM::Client.new)
7
7
  self.new(client).tf
8
8
  end
9
9
 
10
- def self.tfstate(client = Aws::IAM::Client.new)
11
- self.new(client).tfstate
10
+ def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
11
+ self.new(client).tfstate(tfstate_base)
12
12
  end
13
13
 
14
14
  def initialize(client)
@@ -19,7 +19,7 @@ module Terraforming
19
19
  apply_template(@client, "tf/iam_group")
20
20
  end
21
21
 
22
- def tfstate
22
+ def tfstate(tfstate_base)
23
23
  resources = iam_groups.inject({}) do |result, group|
24
24
  attributes = {
25
25
  "arn"=> group.arn,
@@ -39,7 +39,7 @@ module Terraforming
39
39
  result
40
40
  end
41
41
 
42
- generate_tfstate(resources)
42
+ generate_tfstate(resources, tfstate_base)
43
43
  end
44
44
 
45
45
  private