terraforming 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -0
- data/README.md +26 -1
- data/lib/terraforming.rb +7 -0
- data/lib/terraforming/cli.rb +42 -0
- data/lib/terraforming/resource/elb.rb +10 -0
- data/lib/terraforming/resource/iam_group.rb +52 -0
- data/lib/terraforming/resource/iam_group_policy.rb +69 -0
- data/lib/terraforming/resource/iam_policy.rb +56 -0
- data/lib/terraforming/resource/iam_user.rb +52 -0
- data/lib/terraforming/resource/iam_user_policy.rb +69 -0
- data/lib/terraforming/resource/network_acl.rb +11 -3
- data/lib/terraforming/resource/route53_record.rb +88 -0
- data/lib/terraforming/resource/route53_zone.rb +74 -0
- data/lib/terraforming/template/tf/elb.erb +10 -5
- data/lib/terraforming/template/tf/iam_group.erb +7 -0
- data/lib/terraforming/template/tf/iam_group_policy.erb +10 -0
- data/lib/terraforming/template/tf/iam_policy.erb +11 -0
- data/lib/terraforming/template/tf/iam_user.erb +7 -0
- data/lib/terraforming/template/tf/iam_user_policy.erb +10 -0
- data/lib/terraforming/template/tf/route53_record.erb +30 -0
- data/lib/terraforming/template/tf/route53_zone.erb +12 -0
- data/lib/terraforming/version.rb +1 -1
- data/{scripts → script}/console +0 -0
- data/{scripts → script}/setup +0 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d57472a2d8992db0599ae5a1111b1c648f76f8e5
|
4
|
+
data.tar.gz: c50702794d78467502ff68dab56f2e0749bb57de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3082ae845101d88a318b4b926013b9035c4e5732cbcbfadb88c7a5c8115cba2ae0b53845b67e5be8fe7afb276a6289243b2a8273dbd4368281b9190ff4151f75
|
7
|
+
data.tar.gz: 2c55b45bee3f6ede00e547862e440d1baf23443de54d0fd3de39524f1a349873a25579e4fa18da37da044f49957d5696010897c52a9739793ea88ca9a7266ddc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# [v0.0.3](https://github.com/dtan4/terraforming/releases/tag/v0.0.3) (2015-05-26)
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- Include AWS ELB additional attributes #39
|
6
|
+
|
7
|
+
### Resource
|
8
|
+
|
9
|
+
- AWS IAM group
|
10
|
+
- AWS IAM group policy
|
11
|
+
- AWS IAM policy
|
12
|
+
- AWS IAM user
|
13
|
+
- AWS IAM user policy
|
14
|
+
- AWS Route53 hosted zone
|
15
|
+
- AWS Route53 record
|
16
|
+
|
17
|
+
# [v0.0.2](https://github.com/dtan4/terraforming/releases/tag/v0.0.2) (2015-05-09)
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Nested module declation #35
|
22
|
+
- raised NameError exception #34
|
23
|
+
|
24
|
+
### Resource
|
25
|
+
|
26
|
+
- AWS Network ACL
|
27
|
+
|
28
|
+
# [v0.0.1](https://github.com/dtan4/terraforming/releases/tag/v0.0.1) (2015-04-23)
|
29
|
+
|
30
|
+
Initial release.
|
31
|
+
|
32
|
+
### Resource
|
33
|
+
|
34
|
+
- AWS Database Parameter Group
|
35
|
+
- AWS Database Security Group
|
36
|
+
- AWS Subnet Group
|
37
|
+
- AWS EC2 instances
|
38
|
+
- AWS ELB
|
39
|
+
- AWS RDS instances
|
40
|
+
- AWS S3 buckets
|
41
|
+
- AWS SecurityGroup
|
42
|
+
- AWS Subnet
|
43
|
+
- AWS VPC
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
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
6
|
[![Gem Version](https://badge.fury.io/rb/terraforming.svg)](http://badge.fury.io/rb/terraforming)
|
7
|
+
[![Docker Repository on Quay.io](https://quay.io/repository/dtan4/terraforming/status "Docker Repository on Quay.io")](https://quay.io/repository/dtan4/terraforming)
|
7
8
|
|
8
9
|
Import existing AWS resources into [Terraform](https://terraform.io/) style (tf, tfstate)
|
9
10
|
|
@@ -116,9 +117,33 @@ $ terraforming s3 --tfstate
|
|
116
117
|
|
117
118
|
(Probably you have to modify the output to add it to existing `terraforming.tfstate`)
|
118
119
|
|
120
|
+
## 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)
|
121
|
+
|
122
|
+
Terraforming Docker Image is available at [quay.io/dtan4/terraforming](https://quay.io/repository/dtan4/terraforming) and developed at [dtan4/dockerfile-terraforming](https://github.com/dtan4/dockerfile-terraforming).
|
123
|
+
|
124
|
+
Pull the Docker image:
|
125
|
+
|
126
|
+
```bash
|
127
|
+
$ docker pull quay.io/dtan4/terraforming:latest
|
128
|
+
```
|
129
|
+
|
130
|
+
And then run Terraforming as a Docker container:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
$ docker run \
|
134
|
+
--rm \
|
135
|
+
--name terraforming \
|
136
|
+
-v /path/to/tf-files-dir:/app \
|
137
|
+
-e AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX \
|
138
|
+
-e AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
|
139
|
+
-e AWS_DEFAULT_REGION=xx-yyyy-0 \
|
140
|
+
quay.io/dtan4/terraforming:latest \
|
141
|
+
terraforming s3
|
142
|
+
```
|
143
|
+
|
119
144
|
## Development
|
120
145
|
|
121
|
-
After checking out the repo, run `
|
146
|
+
After checking out the repo, run `script/setup` to install dependencies. Then, run `script/console` for an interactive prompt that will allow you to experiment.
|
122
147
|
|
123
148
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
124
149
|
|
data/lib/terraforming.rb
CHANGED
@@ -15,8 +15,15 @@ require "terraforming/resource/db_security_group"
|
|
15
15
|
require "terraforming/resource/db_subnet_group"
|
16
16
|
require "terraforming/resource/ec2"
|
17
17
|
require "terraforming/resource/elb"
|
18
|
+
require "terraforming/resource/iam_group"
|
19
|
+
require "terraforming/resource/iam_group_policy"
|
20
|
+
require "terraforming/resource/iam_policy"
|
21
|
+
require "terraforming/resource/iam_user"
|
22
|
+
require "terraforming/resource/iam_user_policy"
|
18
23
|
require "terraforming/resource/network_acl"
|
19
24
|
require "terraforming/resource/rds"
|
25
|
+
require "terraforming/resource/route53_record"
|
26
|
+
require "terraforming/resource/route53_zone"
|
20
27
|
require "terraforming/resource/s3"
|
21
28
|
require "terraforming/resource/security_group"
|
22
29
|
require "terraforming/resource/subnet"
|
data/lib/terraforming/cli.rb
CHANGED
@@ -30,12 +30,54 @@ module Terraforming
|
|
30
30
|
execute(Terraforming::Resource::ELB, options)
|
31
31
|
end
|
32
32
|
|
33
|
+
desc "iamg", "IAM Group"
|
34
|
+
option :tfstate, type: :boolean
|
35
|
+
def iamg
|
36
|
+
execute(Terraforming::Resource::IAMGroup, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "iamgp", "IAM Group Policy"
|
40
|
+
option :tfstate, type: :boolean
|
41
|
+
def iamgp
|
42
|
+
execute(Terraforming::Resource::IAMGroupPolicy, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "iamp", "IAM Policy"
|
46
|
+
option :tfstate, type: :boolean
|
47
|
+
def iamp
|
48
|
+
execute(Terraforming::Resource::IAMPolicy, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "iamu", "IAM User"
|
52
|
+
option :tfstate, type: :boolean
|
53
|
+
def iamu
|
54
|
+
execute(Terraforming::Resource::IAMUser, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "iamup", "IAM User Policy"
|
58
|
+
option :tfstate, type: :boolean
|
59
|
+
def iamup
|
60
|
+
execute(Terraforming::Resource::IAMUserPolicy, options)
|
61
|
+
end
|
62
|
+
|
33
63
|
desc "nacl", "Network ACL"
|
34
64
|
option :tfstate, type: :boolean
|
35
65
|
def nacl
|
36
66
|
execute(Terraforming::Resource::NetworkACL, options)
|
37
67
|
end
|
38
68
|
|
69
|
+
desc "r53r", "Route53 Record"
|
70
|
+
option :tfstate, type: :boolean
|
71
|
+
def r53r
|
72
|
+
execute(Terraforming::Resource::Route53Record, options)
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "r53z", "Route53 Hosted Zone"
|
76
|
+
option :tfstate, type: :boolean
|
77
|
+
def r53z
|
78
|
+
execute(Terraforming::Resource::Route53Zone, options)
|
79
|
+
end
|
80
|
+
|
39
81
|
desc "rds", "RDS"
|
40
82
|
option :tfstate, type: :boolean
|
41
83
|
def rds
|
@@ -21,15 +21,21 @@ module Terraforming
|
|
21
21
|
|
22
22
|
def tfstate
|
23
23
|
resources = load_balancers.inject({}) do |result, load_balancer|
|
24
|
+
load_balancer_attributes = load_balancer_attributes_of(load_balancer)
|
24
25
|
attributes = {
|
25
26
|
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
|
27
|
+
"connection_draining" => load_balancer_attributes.connection_draining.enabled.to_s,
|
28
|
+
"connection_draining_timeout" => load_balancer_attributes.connection_draining.timeout.to_s,
|
29
|
+
"cross_zone_load_balancing" => load_balancer_attributes.cross_zone_load_balancing.enabled.to_s,
|
26
30
|
"dns_name" => load_balancer.dns_name,
|
27
31
|
"health_check.#" => "1",
|
28
32
|
"id" => load_balancer.load_balancer_name,
|
33
|
+
"idle_timeout" => load_balancer_attributes.connection_settings.idle_timeout.to_s,
|
29
34
|
"instances.#" => load_balancer.instances.length.to_s,
|
30
35
|
"listener.#" => load_balancer.listener_descriptions.length.to_s,
|
31
36
|
"name" => load_balancer.load_balancer_name,
|
32
37
|
"security_groups.#" => load_balancer.security_groups.length.to_s,
|
38
|
+
"source_security_group" => load_balancer.source_security_group.group_name,
|
33
39
|
"subnets.#" => load_balancer.subnets.length.to_s,
|
34
40
|
}
|
35
41
|
result["aws_elb.#{module_name_of(load_balancer)}"] = {
|
@@ -50,6 +56,10 @@ module Terraforming
|
|
50
56
|
@client.describe_load_balancers.load_balancer_descriptions
|
51
57
|
end
|
52
58
|
|
59
|
+
def load_balancer_attributes_of(load_balancer)
|
60
|
+
@client.describe_load_balancer_attributes(load_balancer_name: load_balancer.load_balancer_name).load_balancer_attributes
|
61
|
+
end
|
62
|
+
|
53
63
|
def module_name_of(load_balancer)
|
54
64
|
normalize_module_name(load_balancer.load_balancer_name)
|
55
65
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMGroup
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::IAM::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/iam_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = iam_groups.inject({}) do |result, group|
|
24
|
+
attributes = {
|
25
|
+
"arn"=> group.arn,
|
26
|
+
"id" => group.group_name,
|
27
|
+
"name" => group.group_name,
|
28
|
+
"path" => group.path,
|
29
|
+
"unique_id" => group.group_id,
|
30
|
+
}
|
31
|
+
result["aws_iam_group.#{group.group_name}"] = {
|
32
|
+
"type" => "aws_iam_group",
|
33
|
+
"primary" => {
|
34
|
+
"id" => group.group_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_tfstate(resources)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def iam_groups
|
48
|
+
@client.list_groups.groups
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMGroupPolicy
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::IAM::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/iam_group_policy")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = iam_group_policies.inject({}) do |result, policy|
|
24
|
+
attributes = {
|
25
|
+
"group" => policy.group_name,
|
26
|
+
"id" => iam_group_policy_id_of(policy),
|
27
|
+
"name" => policy.policy_name,
|
28
|
+
"policy" => CGI.unescape(policy.policy_document)
|
29
|
+
}
|
30
|
+
result["aws_iam_group_policy.#{policy.policy_name}"] = {
|
31
|
+
"type" => "aws_iam_group_policy",
|
32
|
+
"primary" => {
|
33
|
+
"id" => iam_group_policy_id_of(policy),
|
34
|
+
"attributes" => attributes
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
generate_tfstate(resources)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def iam_groups
|
47
|
+
@client.list_groups.groups
|
48
|
+
end
|
49
|
+
|
50
|
+
def iam_group_policy_id_of(policy)
|
51
|
+
"#{policy.group_name}:#{policy.policy_name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def iam_group_policy_names_in(group)
|
55
|
+
@client.list_group_policies(group_name: group.group_name).policy_names
|
56
|
+
end
|
57
|
+
|
58
|
+
def iam_group_policy_of(group, policy_name)
|
59
|
+
@client.get_group_policy(group_name: group.group_name, policy_name: policy_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def iam_group_policies
|
63
|
+
iam_groups.map do |group|
|
64
|
+
iam_group_policy_names_in(group).map { |policy_name| iam_group_policy_of(group, policy_name) }
|
65
|
+
end.flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMPolicy
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::IAM::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/iam_policy")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = iam_policies.inject({}) do |result, policy|
|
24
|
+
version = iam_policy_version_of(policy)
|
25
|
+
attributes = {
|
26
|
+
"id" => policy.arn,
|
27
|
+
"name" => policy.policy_name,
|
28
|
+
"path" => policy.path,
|
29
|
+
"policy" => CGI.unescape(version.document),
|
30
|
+
}
|
31
|
+
result["aws_iam_policy.#{policy.policy_name}"] = {
|
32
|
+
"type" => "aws_iam_policy",
|
33
|
+
"primary" => {
|
34
|
+
"id" => policy.arn,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_tfstate(resources)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def iam_policies
|
48
|
+
@client.list_policies(scope: "Local").policies
|
49
|
+
end
|
50
|
+
|
51
|
+
def iam_policy_version_of(policy)
|
52
|
+
@client.get_policy_version(policy_arn: policy.arn, version_id: policy.default_version_id).policy_version
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMUser
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::IAM::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/iam_user")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = iam_users.inject({}) do |result, user|
|
24
|
+
attributes = {
|
25
|
+
"arn"=> user.arn,
|
26
|
+
"id" => user.user_name,
|
27
|
+
"name" => user.user_name,
|
28
|
+
"path" => user.path,
|
29
|
+
"unique_id" => user.user_id,
|
30
|
+
}
|
31
|
+
result["aws_iam_user.#{user.user_name}"] = {
|
32
|
+
"type" => "aws_iam_user",
|
33
|
+
"primary" => {
|
34
|
+
"id" => user.user_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_tfstate(resources)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def iam_users
|
48
|
+
@client.list_users.users
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMUserPolicy
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::IAM::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/iam_user_policy")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = iam_user_policies.inject({}) do |result, policy|
|
24
|
+
attributes = {
|
25
|
+
"id" => iam_user_policy_id_of(policy),
|
26
|
+
"name" => policy.policy_name,
|
27
|
+
"policy" => CGI.unescape(policy.policy_document),
|
28
|
+
"user" => policy.user_name,
|
29
|
+
}
|
30
|
+
result["aws_iam_user_policy.#{policy.policy_name}"] = {
|
31
|
+
"type" => "aws_iam_user_policy",
|
32
|
+
"primary" => {
|
33
|
+
"id" => iam_user_policy_id_of(policy),
|
34
|
+
"attributes" => attributes
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
generate_tfstate(resources)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def iam_users
|
47
|
+
@client.list_users.users
|
48
|
+
end
|
49
|
+
|
50
|
+
def iam_user_policy_id_of(policy)
|
51
|
+
"#{policy.user_name}:#{policy.policy_name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def iam_user_policy_names_in(user)
|
55
|
+
@client.list_user_policies(user_name: user.user_name).policy_names
|
56
|
+
end
|
57
|
+
|
58
|
+
def iam_user_policy_of(user, policy_name)
|
59
|
+
@client.get_user_policy(user_name: user.user_name, policy_name: policy_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def iam_user_policies
|
63
|
+
iam_users.map do |user|
|
64
|
+
iam_user_policy_names_in(user).map { |policy_name| iam_user_policy_of(user, policy_name) }
|
65
|
+
end.flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -44,8 +44,16 @@ module Terraforming
|
|
44
44
|
|
45
45
|
private
|
46
46
|
|
47
|
+
def default_entry?(entry)
|
48
|
+
entry.rule_number == default_rule_number
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_rule_number
|
52
|
+
32767
|
53
|
+
end
|
54
|
+
|
47
55
|
def egresses_of(network_acl)
|
48
|
-
network_acl.entries.select { |entry| entry.egress }
|
56
|
+
network_acl.entries.select { |entry| entry.egress && !default_entry?(entry) }
|
49
57
|
end
|
50
58
|
|
51
59
|
def from_port_of(entry)
|
@@ -53,7 +61,7 @@ module Terraforming
|
|
53
61
|
end
|
54
62
|
|
55
63
|
def ingresses_of(network_acl)
|
56
|
-
network_acl.entries.select { |entry| !entry.egress }
|
64
|
+
network_acl.entries.select { |entry| !entry.egress && !default_entry?(entry) }
|
57
65
|
end
|
58
66
|
|
59
67
|
def module_name_of(network_acl)
|
@@ -65,7 +73,7 @@ module Terraforming
|
|
65
73
|
end
|
66
74
|
|
67
75
|
def to_port_of(entry)
|
68
|
-
entry.port_range ? entry.port_range.to :
|
76
|
+
entry.port_range ? entry.port_range.to : 0
|
69
77
|
end
|
70
78
|
end
|
71
79
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class Route53Record
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::Route53::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::Route53::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/route53_record")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = records.inject({}) do |result, r|
|
24
|
+
record, zone_id = r[:record], r[:zone_id]
|
25
|
+
record_id = record_id_of(record, zone_id)
|
26
|
+
|
27
|
+
attributes = {
|
28
|
+
"id"=> record_id,
|
29
|
+
"name"=> name_of(record.name),
|
30
|
+
"type" => record.type,
|
31
|
+
"zone_id" => zone_id,
|
32
|
+
}
|
33
|
+
|
34
|
+
attributes["alias.#"] = "1" if record.alias_target
|
35
|
+
attributes["records.#"] = record.resource_records.length.to_s unless record.resource_records.empty?
|
36
|
+
attributes["ttl"] = record.ttl.to_s if record.ttl
|
37
|
+
attributes["weight"] = record.weight.to_s if record.weight
|
38
|
+
attributes["set_identifier"] = record.set_identifier if record.set_identifier
|
39
|
+
|
40
|
+
result["aws_route53_record.#{module_name_of(record)}"] = {
|
41
|
+
"type" => "aws_route53_record",
|
42
|
+
"primary" => {
|
43
|
+
"id" => record_id,
|
44
|
+
"attributes" => attributes,
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
generate_tfstate(resources)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def hosted_zones
|
57
|
+
@client.list_hosted_zones.hosted_zones
|
58
|
+
end
|
59
|
+
|
60
|
+
def record_id_of(record, zone_id)
|
61
|
+
"#{zone_id}_#{name_of(record.name)}_#{record.type}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def record_sets_of(hosted_zone)
|
65
|
+
@client.list_resource_record_sets(hosted_zone_id: zone_id_of(hosted_zone)).resource_record_sets
|
66
|
+
end
|
67
|
+
|
68
|
+
def records
|
69
|
+
hosted_zones.map do |hosted_zone|
|
70
|
+
record_sets_of(hosted_zone).map { |record| { record: record, zone_id: zone_id_of(hosted_zone) } }
|
71
|
+
end.flatten
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO(dtan4): change method name...
|
75
|
+
def name_of(dns_name)
|
76
|
+
dns_name.gsub(/\.\z/, "")
|
77
|
+
end
|
78
|
+
|
79
|
+
def module_name_of(record)
|
80
|
+
normalize_module_name(name_of(record.name))
|
81
|
+
end
|
82
|
+
|
83
|
+
def zone_id_of(hosted_zone)
|
84
|
+
hosted_zone.id.gsub(/\A\/hostedzone\//, "")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class Route53Zone
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client = Aws::Route53::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client = Aws::Route53::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/route53_zone")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = hosted_zones.inject({}) do |result, hosted_zone|
|
24
|
+
zone_id = zone_id_of(hosted_zone)
|
25
|
+
|
26
|
+
attributes = {
|
27
|
+
"id"=> zone_id,
|
28
|
+
"name"=> name_of(hosted_zone),
|
29
|
+
"name_servers.#" => name_servers_of(hosted_zone).length.to_s,
|
30
|
+
"tags.#" => tags_of(hosted_zone).length.to_s,
|
31
|
+
"zone_id" => zone_id,
|
32
|
+
}
|
33
|
+
result["aws_route53_zone.#{module_name_of(hosted_zone)}"] = {
|
34
|
+
"type" => "aws_route53_zone",
|
35
|
+
"primary" => {
|
36
|
+
"id" => zone_id,
|
37
|
+
"attributes" => attributes,
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
generate_tfstate(resources)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def hosted_zones
|
50
|
+
@client.list_hosted_zones.hosted_zones
|
51
|
+
end
|
52
|
+
|
53
|
+
def tags_of(hosted_zone)
|
54
|
+
@client.list_tags_for_resource(resource_type: "hostedzone", resource_id: zone_id_of(hosted_zone)).resource_tag_set.tags
|
55
|
+
end
|
56
|
+
|
57
|
+
def name_of(hosted_zone)
|
58
|
+
hosted_zone.name.gsub(/\.\z/, "")
|
59
|
+
end
|
60
|
+
|
61
|
+
def name_servers_of(hosted_zone)
|
62
|
+
@client.get_hosted_zone(id: hosted_zone.id).delegation_set.name_servers
|
63
|
+
end
|
64
|
+
|
65
|
+
def module_name_of(hosted_zone)
|
66
|
+
normalize_module_name(name_of(hosted_zone))
|
67
|
+
end
|
68
|
+
|
69
|
+
def zone_id_of(hosted_zone)
|
70
|
+
hosted_zone.id.gsub(/\A\/hostedzone\//, "")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
<% load_balancers.each do |load_balancer| -%>
|
2
|
+
<%- load_balancer_attributes = load_balancer_attributes_of(load_balancer) -%>
|
2
3
|
resource "aws_elb" "<%= module_name_of(load_balancer) %>" {
|
3
|
-
name
|
4
|
-
availability_zones
|
5
|
-
subnets
|
6
|
-
security_groups
|
7
|
-
instances
|
4
|
+
name = "<%= load_balancer.load_balancer_name %>"
|
5
|
+
availability_zones = <%= load_balancer.availability_zones.inspect %>
|
6
|
+
subnets = <%= load_balancer.subnets.inspect %>
|
7
|
+
security_groups = <%= load_balancer.security_groups.inspect %>
|
8
|
+
instances = <%= load_balancer.instances.map { |instance| instance.instance_id }.inspect %>
|
9
|
+
cross_zone_load_balancing = <%= load_balancer_attributes.cross_zone_load_balancing.enabled %>
|
10
|
+
idle_timeout = <%= load_balancer_attributes.connection_settings.idle_timeout %>
|
11
|
+
connection_draining = <%= load_balancer_attributes.connection_draining.enabled %>
|
12
|
+
connection_draining_timeout = <%= load_balancer_attributes.connection_draining.timeout %>
|
8
13
|
|
9
14
|
<% load_balancer.listener_descriptions.map { |ld| ld.listener }.map do |listener| -%>
|
10
15
|
listener {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% iam_group_policies.each do |policy| -%>
|
2
|
+
resource "aws_iam_group_policy" "<%= policy.policy_name %>" {
|
3
|
+
name = "<%= policy.policy_name %>"
|
4
|
+
group = "<%= policy.group_name %>"
|
5
|
+
policy = <<POLICY
|
6
|
+
<%= CGI.unescape(policy.policy_document).strip %>
|
7
|
+
POLICY
|
8
|
+
}
|
9
|
+
|
10
|
+
<% end -%>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<% iam_policies.each do |policy| -%>
|
2
|
+
<%- version = iam_policy_version_of(policy) -%>
|
3
|
+
resource "aws_iam_policy" "<%= policy.policy_name %>" {
|
4
|
+
name = "<%= policy.policy_name %>"
|
5
|
+
path = "<%= policy.path %>"
|
6
|
+
policy = <<POLICY
|
7
|
+
<%= CGI.unescape(version.document).strip %>
|
8
|
+
POLICY
|
9
|
+
}
|
10
|
+
|
11
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% iam_user_policies.each do |policy| -%>
|
2
|
+
resource "aws_iam_user_policy" "<%= policy.policy_name %>" {
|
3
|
+
name = "<%= policy.policy_name %>"
|
4
|
+
user = "<%= policy.user_name %>"
|
5
|
+
policy = <<POLICY
|
6
|
+
<%= CGI.unescape(policy.policy_document).strip %>
|
7
|
+
POLICY
|
8
|
+
}
|
9
|
+
|
10
|
+
<% end -%>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<% records.each do |r| -%>
|
2
|
+
<%- record, zone_id = r[:record], r[:zone_id] -%>
|
3
|
+
resource "aws_route53_record" "<%= module_name_of(record) %>" {
|
4
|
+
zone_id = "<%= zone_id %>"
|
5
|
+
name = "<%= name_of(record.name) %>"
|
6
|
+
type = "<%= record.type %>"
|
7
|
+
<%- unless record.resource_records.empty? -%>
|
8
|
+
records = <%= record.resource_records.map(&:value).to_s %>
|
9
|
+
<%- end -%>
|
10
|
+
<%- if record.ttl -%>
|
11
|
+
ttl = "<%= record.ttl %>"
|
12
|
+
<%- end -%>
|
13
|
+
<%- if record.weight -%>
|
14
|
+
weight = <%= record.weight %>
|
15
|
+
<%- end -%>
|
16
|
+
<%- if record.set_identifier -%>
|
17
|
+
set_identifier = "<%= record.set_identifier %>"
|
18
|
+
<%- end -%>
|
19
|
+
|
20
|
+
<%- if record.alias_target -%>
|
21
|
+
alias {
|
22
|
+
name = "<%= name_of(record.alias_target.dns_name)
|
23
|
+
%>"
|
24
|
+
zone_id = "<%= record.alias_target.hosted_zone_id %>"
|
25
|
+
evaluate_target_health = <%= record.alias_target.evaluate_target_health %>
|
26
|
+
}
|
27
|
+
<%- end -%>
|
28
|
+
}
|
29
|
+
|
30
|
+
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% hosted_zones.each do |hosted_zone| -%>
|
2
|
+
resource "aws_route53_zone" "<%= module_name_of(hosted_zone) %>" {
|
3
|
+
name = "<%= name_of(hosted_zone) %>"
|
4
|
+
|
5
|
+
tags {
|
6
|
+
<% tags_of(hosted_zone).each do |tag| -%>
|
7
|
+
<%= tag.key %> = "<%= tag.value %>"
|
8
|
+
<% end -%>
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
<% end -%>
|
data/lib/terraforming/version.rb
CHANGED
data/{scripts → script}/console
RENAMED
File without changes
|
data/{scripts → script}/setup
RENAMED
File without changes
|
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.0.
|
4
|
+
version: 0.0.3
|
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-05-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- ".gitignore"
|
182
182
|
- ".rspec"
|
183
183
|
- ".travis.yml"
|
184
|
+
- CHANGELOG.md
|
184
185
|
- CODE_OF_CONDUCT.md
|
185
186
|
- Gemfile
|
186
187
|
- Guardfile
|
@@ -195,8 +196,15 @@ files:
|
|
195
196
|
- lib/terraforming/resource/db_subnet_group.rb
|
196
197
|
- lib/terraforming/resource/ec2.rb
|
197
198
|
- lib/terraforming/resource/elb.rb
|
199
|
+
- lib/terraforming/resource/iam_group.rb
|
200
|
+
- lib/terraforming/resource/iam_group_policy.rb
|
201
|
+
- lib/terraforming/resource/iam_policy.rb
|
202
|
+
- lib/terraforming/resource/iam_user.rb
|
203
|
+
- lib/terraforming/resource/iam_user_policy.rb
|
198
204
|
- lib/terraforming/resource/network_acl.rb
|
199
205
|
- lib/terraforming/resource/rds.rb
|
206
|
+
- lib/terraforming/resource/route53_record.rb
|
207
|
+
- lib/terraforming/resource/route53_zone.rb
|
200
208
|
- lib/terraforming/resource/s3.rb
|
201
209
|
- lib/terraforming/resource/security_group.rb
|
202
210
|
- lib/terraforming/resource/subnet.rb
|
@@ -206,16 +214,23 @@ files:
|
|
206
214
|
- lib/terraforming/template/tf/db_subnet_group.erb
|
207
215
|
- lib/terraforming/template/tf/ec2.erb
|
208
216
|
- lib/terraforming/template/tf/elb.erb
|
217
|
+
- lib/terraforming/template/tf/iam_group.erb
|
218
|
+
- lib/terraforming/template/tf/iam_group_policy.erb
|
219
|
+
- lib/terraforming/template/tf/iam_policy.erb
|
220
|
+
- lib/terraforming/template/tf/iam_user.erb
|
221
|
+
- lib/terraforming/template/tf/iam_user_policy.erb
|
209
222
|
- lib/terraforming/template/tf/network_acl.erb
|
210
223
|
- lib/terraforming/template/tf/rds.erb
|
224
|
+
- lib/terraforming/template/tf/route53_record.erb
|
225
|
+
- lib/terraforming/template/tf/route53_zone.erb
|
211
226
|
- lib/terraforming/template/tf/s3.erb
|
212
227
|
- lib/terraforming/template/tf/security_group.erb
|
213
228
|
- lib/terraforming/template/tf/subnet.erb
|
214
229
|
- lib/terraforming/template/tf/vpc.erb
|
215
230
|
- lib/terraforming/util.rb
|
216
231
|
- lib/terraforming/version.rb
|
217
|
-
-
|
218
|
-
-
|
232
|
+
- script/console
|
233
|
+
- script/setup
|
219
234
|
- terraforming.gemspec
|
220
235
|
homepage: https://github.com/dtan4/terraforming
|
221
236
|
licenses:
|
@@ -237,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
252
|
version: '0'
|
238
253
|
requirements: []
|
239
254
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.4.
|
255
|
+
rubygems_version: 2.4.7
|
241
256
|
signing_key:
|
242
257
|
specification_version: 4
|
243
258
|
summary: Import existing AWS resources into Terraform style (tf, tfstate)
|