terraforming 0.1.6 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +10 -3
- data/lib/terraforming/cli.rb +10 -1
- data/lib/terraforming/resource/db_security_group.rb +6 -2
- data/lib/terraforming/resource/route53_zone.rb +17 -5
- data/lib/terraforming/resource/s3.rb +10 -1
- data/lib/terraforming/template/tf/route53_zone.erb +6 -1
- data/lib/terraforming/version.rb +1 -1
- data/terraforming.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 579938c93e511511d9d81db6dc0832eee5300fea
|
4
|
+
data.tar.gz: 91c1d9a93cf0e2381cab45436c33d5ea4113708f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7ea11e17c9334bb607ae216ccc5429b9a7ee54b24d2f3322e5204f5a7b751af26ac9018edcfe174bc581b679fa6c860eb8d2ccf41eebfd3e48ca22fbbd9ea7b
|
7
|
+
data.tar.gz: c3f17f500258953ad9f5150b806ca0f5ecafee13edc25dcd7e96074e1334f32fed8045fe514205178b791f1bbf8362d94d8a2fda5550bf620b82e54b8442ebe1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# [v0.2.0](https://github.com/dtan4/terraforming/releases/tag/v0.2.0) (2015-08-22)
|
2
|
+
|
3
|
+
## New feature
|
4
|
+
|
5
|
+
- Add `--overwrite` option to overwrite existing `terraform.tfstate` #117
|
6
|
+
|
7
|
+
## Fixed
|
8
|
+
|
9
|
+
- Export S3 buckets only in the same region #121
|
10
|
+
- Exclude DB security group with empty ingress rules #120
|
11
|
+
- Include associated VPC parameters in Route53 hosted zone #119
|
12
|
+
- Support Route53 hosted zone with empty delegation set #118
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Stop including ElastiCache port at any time #112
|
17
|
+
|
1
18
|
# [v0.1.6](https://github.com/dtan4/terraforming/releases/tag/v0.1.6) (2015-08-10)
|
2
19
|
|
3
20
|
### Fixed
|
data/README.md
CHANGED
@@ -84,6 +84,10 @@ Commands:
|
|
84
84
|
|
85
85
|
### Export tf
|
86
86
|
|
87
|
+
```bash
|
88
|
+
$ terraforming <resource>
|
89
|
+
```
|
90
|
+
|
87
91
|
(e.g. S3 buckets):
|
88
92
|
|
89
93
|
```bash
|
@@ -104,7 +108,11 @@ resource "aws_s3_bucket" "fuga" {
|
|
104
108
|
|
105
109
|
### Export tfstate
|
106
110
|
|
107
|
-
|
111
|
+
```bash
|
112
|
+
$ terraforming <resource> --tfstate [--merge TFSTATE_PATH] [--overwrite]
|
113
|
+
```
|
114
|
+
|
115
|
+
(e.g. S3 buckets):
|
108
116
|
|
109
117
|
```bash
|
110
118
|
$ terraforming s3 --tfstate
|
@@ -149,8 +157,7 @@ $ terraforming s3 --tfstate
|
|
149
157
|
```
|
150
158
|
|
151
159
|
If you want to merge exported tfstate to existing `terraform.tfstate`, specify `--tfstate --merge=/path/to/terraform.tfstate` option.
|
152
|
-
|
153
|
-
You should copy output in stdout by hand or `pbcopy` command, and paste it to existing `terraform.tfstate`.
|
160
|
+
You can overwrite existing `terraform.tfstate` by specifying `--overwrite` option together.
|
154
161
|
|
155
162
|
Existing `terraform.tfstate`:
|
156
163
|
|
data/lib/terraforming/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Terraforming
|
2
2
|
class CLI < Thor
|
3
3
|
class_option :merge, type: :string, desc: "tfstate file to merge"
|
4
|
+
class_option :overwrite, type: :boolean, desc: "Overwrite existng tfstate"
|
4
5
|
class_option :tfstate, type: :boolean, desc: "Generate tfstate"
|
5
6
|
|
6
7
|
desc "dbpg", "Database Parameter Group"
|
@@ -127,7 +128,15 @@ module Terraforming
|
|
127
128
|
|
128
129
|
def execute(klass, options)
|
129
130
|
result = options[:tfstate] ? tfstate(klass, options[:merge]) : tf(klass)
|
130
|
-
|
131
|
+
|
132
|
+
if options[:tfstate] && options[:merge] && options[:overwrite]
|
133
|
+
open(options[:merge], "w+") do |f|
|
134
|
+
f.write(result)
|
135
|
+
f.flush
|
136
|
+
end
|
137
|
+
else
|
138
|
+
puts result
|
139
|
+
end
|
131
140
|
end
|
132
141
|
|
133
142
|
def tf(klass)
|
@@ -24,7 +24,7 @@ module Terraforming
|
|
24
24
|
attributes = {
|
25
25
|
"db_subnet_group_name" => security_group.db_security_group_name,
|
26
26
|
"id" => security_group.db_security_group_name,
|
27
|
-
"ingress.#" => (security_group.
|
27
|
+
"ingress.#" => ingresses_of(security_group).length.to_s,
|
28
28
|
"name" => security_group.db_security_group_name,
|
29
29
|
}
|
30
30
|
resources["aws_db_security_group.#{module_name_of(security_group)}"] = {
|
@@ -41,8 +41,12 @@ module Terraforming
|
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
+
def ingresses_of(security_group)
|
45
|
+
security_group.ec2_security_groups + security_group.ip_ranges
|
46
|
+
end
|
47
|
+
|
44
48
|
def db_security_groups
|
45
|
-
@client.describe_db_security_groups.db_security_groups
|
49
|
+
@client.describe_db_security_groups.db_security_groups.select { |sg| ingresses_of(sg).length > 0 }
|
46
50
|
end
|
47
51
|
|
48
52
|
def module_name_of(security_group)
|
@@ -22,12 +22,15 @@ module Terraforming
|
|
22
22
|
def tfstate
|
23
23
|
hosted_zones.inject({}) do |resources, hosted_zone|
|
24
24
|
zone_id = zone_id_of(hosted_zone)
|
25
|
+
vpc = vpc_of(hosted_zone)
|
25
26
|
|
26
27
|
attributes = {
|
27
28
|
"id"=> zone_id,
|
28
29
|
"name"=> name_of(hosted_zone),
|
29
30
|
"name_servers.#" => name_servers_of(hosted_zone).length.to_s,
|
30
31
|
"tags.#" => tags_of(hosted_zone).length.to_s,
|
32
|
+
"vpc_id" => vpc ? vpc.vpc_id : "",
|
33
|
+
"vpc_region" => vpc ? vpc.vpc_region : "",
|
31
34
|
"zone_id" => zone_id,
|
32
35
|
}
|
33
36
|
resources["aws_route53_zone.#{module_name_of(hosted_zone)}"] = {
|
@@ -45,7 +48,7 @@ module Terraforming
|
|
45
48
|
private
|
46
49
|
|
47
50
|
def hosted_zones
|
48
|
-
@client.list_hosted_zones.hosted_zones
|
51
|
+
@client.list_hosted_zones.hosted_zones.map { |hosted_zone| @client.get_hosted_zone(id: hosted_zone.id) }
|
49
52
|
end
|
50
53
|
|
51
54
|
def tags_of(hosted_zone)
|
@@ -53,19 +56,28 @@ module Terraforming
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def name_of(hosted_zone)
|
56
|
-
hosted_zone.name.gsub(/\.\z/, "")
|
59
|
+
hosted_zone.hosted_zone.name.gsub(/\.\z/, "")
|
57
60
|
end
|
58
61
|
|
59
62
|
def name_servers_of(hosted_zone)
|
60
|
-
|
63
|
+
delegation_set = hosted_zone.delegation_set
|
64
|
+
delegation_set ? delegation_set.name_servers : []
|
61
65
|
end
|
62
66
|
|
63
67
|
def module_name_of(hosted_zone)
|
64
|
-
normalize_module_name(name_of(hosted_zone))
|
68
|
+
normalize_module_name(name_of(hosted_zone)) << "-#{private_hosted_zone?(hosted_zone) ? 'private' : 'public'}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def private_hosted_zone?(hosted_zone)
|
72
|
+
hosted_zone.hosted_zone.config.private_zone
|
73
|
+
end
|
74
|
+
|
75
|
+
def vpc_of(hosted_zone)
|
76
|
+
hosted_zone.vp_cs[0]
|
65
77
|
end
|
66
78
|
|
67
79
|
def zone_id_of(hosted_zone)
|
68
|
-
hosted_zone.id.gsub(/\A\/hostedzone\//, "")
|
80
|
+
hosted_zone.hosted_zone.id.gsub(/\A\/hostedzone\//, "")
|
69
81
|
end
|
70
82
|
end
|
71
83
|
end
|
@@ -42,6 +42,10 @@ module Terraforming
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
+
def bucket_location_of(bucket)
|
46
|
+
@client.get_bucket_location(bucket: bucket.name).location_constraint
|
47
|
+
end
|
48
|
+
|
45
49
|
def bucket_policy_of(bucket)
|
46
50
|
@client.get_bucket_policy(bucket: bucket.name)
|
47
51
|
rescue Aws::S3::Errors::NoSuchBucketPolicy
|
@@ -49,12 +53,17 @@ module Terraforming
|
|
49
53
|
end
|
50
54
|
|
51
55
|
def buckets
|
52
|
-
@client.list_buckets.buckets
|
56
|
+
@client.list_buckets.buckets.select { |bucket| same_region?(bucket) }
|
53
57
|
end
|
54
58
|
|
55
59
|
def module_name_of(bucket)
|
56
60
|
normalize_module_name(bucket.name)
|
57
61
|
end
|
62
|
+
|
63
|
+
def same_region?(bucket)
|
64
|
+
bucket_location = bucket_location_of(bucket)
|
65
|
+
(bucket_location == @client.config.region) || (bucket_location == "" && @client.config.region == "us-east-1")
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
<% hosted_zones.each do |hosted_zone| -%>
|
2
2
|
resource "aws_route53_zone" "<%= module_name_of(hosted_zone) %>" {
|
3
|
-
name
|
3
|
+
name = "<%= name_of(hosted_zone) %>"
|
4
|
+
<%- if private_hosted_zone?(hosted_zone) -%>
|
5
|
+
<%- vpc = vpc_of(hosted_zone) -%>
|
6
|
+
vpc_id = "<%= vpc.vpc_id %>"
|
7
|
+
vpc_region = "<%= vpc.vpc_region %>"
|
8
|
+
<%- end -%>
|
4
9
|
|
5
10
|
tags {
|
6
11
|
<% tags_of(hosted_zone).each do |tag| -%>
|
data/lib/terraforming/version.rb
CHANGED
data/terraforming.gemspec
CHANGED
@@ -19,7 +19,7 @@ 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.1.
|
22
|
+
spec.add_dependency "aws-sdk", "~> 2.1.15"
|
23
23
|
spec.add_dependency "oj"
|
24
24
|
spec.add_dependency "ox"
|
25
25
|
spec.add_dependency "thor"
|
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.
|
4
|
+
version: 0.2.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-08-
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.1.
|
19
|
+
version: 2.1.15
|
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.1.
|
26
|
+
version: 2.1.15
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,8 +258,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
260
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.4.
|
261
|
+
rubygems_version: 2.4.7
|
262
262
|
signing_key:
|
263
263
|
specification_version: 4
|
264
264
|
summary: Export existing AWS resources to Terraform style (tf, tfstate)
|
265
265
|
test_files: []
|
266
|
+
has_rdoc:
|