terraforming 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +12 -1
- data/CONTRIBUTING.md +38 -0
- data/README.md +11 -6
- data/lib/terraforming/cli.rb +10 -0
- data/lib/terraforming/resource/efs_file_system.rb +5 -1
- data/lib/terraforming/resource/eip.rb +5 -1
- data/lib/terraforming/resource/elasti_cache_cluster.rb +5 -1
- data/lib/terraforming/resource/elasti_cache_subnet_group.rb +5 -1
- data/lib/terraforming/resource/iam_group.rb +5 -1
- data/lib/terraforming/resource/iam_group_membership.rb +5 -1
- data/lib/terraforming/resource/iam_group_policy.rb +1 -1
- data/lib/terraforming/resource/iam_instance_profile.rb +5 -1
- data/lib/terraforming/resource/iam_policy.rb +5 -1
- data/lib/terraforming/resource/iam_policy_attachment.rb +5 -1
- data/lib/terraforming/resource/iam_role.rb +5 -1
- data/lib/terraforming/resource/iam_role_policy.rb +1 -1
- data/lib/terraforming/resource/iam_user_policy.rb +1 -1
- data/lib/terraforming/resource/kms_alias.rb +55 -0
- data/lib/terraforming/resource/kms_key.rb +84 -0
- data/lib/terraforming/template/tf/eip.erb +1 -1
- data/lib/terraforming/template/tf/elasti_cache_cluster.erb +1 -1
- data/lib/terraforming/template/tf/elasti_cache_subnet_group.erb +1 -1
- data/lib/terraforming/template/tf/elastic_filesystem.erb +1 -1
- data/lib/terraforming/template/tf/iam_group.erb +1 -1
- data/lib/terraforming/template/tf/iam_group_membership.erb +1 -1
- data/lib/terraforming/template/tf/iam_instance_profile.erb +1 -1
- data/lib/terraforming/template/tf/iam_policy.erb +1 -1
- data/lib/terraforming/template/tf/iam_policy_attachment.erb +1 -1
- data/lib/terraforming/template/tf/iam_role.erb +1 -1
- data/lib/terraforming/template/tf/kms_alias.erb +7 -0
- data/lib/terraforming/template/tf/kms_key.erb +13 -0
- data/lib/terraforming/template/tf/redshift.erb +1 -1
- data/lib/terraforming/version.rb +1 -1
- data/lib/terraforming.rb +2 -0
- data/script/generate +97 -0
- data/templates/resource.erb.erb +3 -0
- data/templates/resource.rb.erb +31 -0
- data/templates/resource_spec.rb.erb +39 -0
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56b10bc1416e5223ef01c3c49a00f6108ae1a5f3
|
4
|
+
data.tar.gz: 395f5e9a6496791ef2b33301931351d1f5d6cf10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d217dc1d609b1afed2681887af7f7a9590c33d9f7812d7d50fd84cc09e09b338675806048fed7138a1e8428b478c5ad2242c7f17014c9271e8f3f0f9c6066cb5
|
7
|
+
data.tar.gz: 64f11e97d09bf707ec52a525b19daa8277be537dd9ecc8859783978f03a44b4869c325f61b9d1e2b3c55fcdae5919a90a20312dad79f656650041d1da6f7c8c1
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
# [v0.
|
1
|
+
# [v0.13.0](https://github.com/dtan4/terraforming/releases/tag/v0.13.0) (2017-01-12)
|
2
|
+
|
3
|
+
## Resource
|
4
|
+
|
5
|
+
- AWS KMS Key Alias [#300](https://github.com/dtan4/terraforming/pull/300)
|
6
|
+
- AWS KMS Key [#299](https://github.com/dtan4/terraforming/pull/299)
|
7
|
+
|
8
|
+
## Fixed / Updated
|
9
|
+
|
10
|
+
- Normalize all resource names in tf and tfstate files [#296](https://github.com/dtan4/terraforming/pull/296) (thanks @nabarunchatterjee)
|
11
|
+
|
12
|
+
# [v0.12.0](https://github.com/dtan4/terraforming/releases/tag/v0.12.0) (2016-12-20)
|
2
13
|
|
3
14
|
## Resource
|
4
15
|
|
data/CONTRIBUTING.md
CHANGED
@@ -22,3 +22,41 @@ I love pull requests from everyone! By the way, I have a favor to ask you with y
|
|
22
22
|
- Command name should be abbreviation.
|
23
23
|
- e.g. `aws_iam_group_membership`: `iamgp`
|
24
24
|
- Please check generation result by executing `terraform plan` with real resources. There should be NO diff with generated `.tf` and `.tfstate`.
|
25
|
+
|
26
|
+
`script/generate` generates new resource code / test skeletons.
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ script/generate ec2
|
30
|
+
==> Generate ec2.rb
|
31
|
+
==> Generate ec2_spec.rb
|
32
|
+
==> Generate ec2.erb
|
33
|
+
|
34
|
+
Add below code by hand.
|
35
|
+
|
36
|
+
lib/terraforming.rb:
|
37
|
+
|
38
|
+
require "terraforming/resource/ec2"
|
39
|
+
|
40
|
+
lib/terraforming/cli.rb:
|
41
|
+
|
42
|
+
module Terraforming
|
43
|
+
class CLI < Thor
|
44
|
+
|
45
|
+
# Subcommand name should be acronym.
|
46
|
+
desc "ec2", "Ec2"
|
47
|
+
def ec2
|
48
|
+
execute(Terraforming::Resource::Ec2, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
spec/lib/terraforming/cli_spec.rb:
|
52
|
+
|
53
|
+
module Terraforming
|
54
|
+
describe CLI do
|
55
|
+
context "resources" do
|
56
|
+
describe "ec2" do
|
57
|
+
let(:klass) { Terraforming::Resource::Ec2
|
58
|
+
let(:command) { :ec2 }
|
59
|
+
|
60
|
+
it_behaves_like "CLI examples"
|
61
|
+
end
|
62
|
+
```
|
data/README.md
CHANGED
@@ -100,6 +100,8 @@ Commands:
|
|
100
100
|
terraforming iamu # IAM User
|
101
101
|
terraforming iamup # IAM User Policy
|
102
102
|
terraforming igw # Internet Gateway
|
103
|
+
terraforming kmsa # KMS Key Alias
|
104
|
+
terraforming kmsk # KMS Key
|
103
105
|
terraforming lc # Launch Configuration
|
104
106
|
terraforming nacl # Network ACL
|
105
107
|
terraforming nat # NAT Gateway
|
@@ -118,11 +120,12 @@ Commands:
|
|
118
120
|
terraforming vpc # VPC
|
119
121
|
|
120
122
|
Options:
|
121
|
-
[--merge=MERGE]
|
122
|
-
[--overwrite], [--no-overwrite]
|
123
|
-
[--tfstate], [--no-tfstate]
|
124
|
-
[--profile=PROFILE]
|
125
|
-
[--region=REGION]
|
123
|
+
[--merge=MERGE] # tfstate file to merge
|
124
|
+
[--overwrite], [--no-overwrite] # Overwrite existng tfstate
|
125
|
+
[--tfstate], [--no-tfstate] # Generate tfstate
|
126
|
+
[--profile=PROFILE] # AWS credentials profile
|
127
|
+
[--region=REGION] # AWS region
|
128
|
+
[--use-bundled-cert], [--no-use-bundled-cert] # Use the bundled CA certificate from AWS SDK
|
126
129
|
```
|
127
130
|
|
128
131
|
### Export tf
|
@@ -137,7 +140,7 @@ $ terraforming <resource> [--profile PROFILE]
|
|
137
140
|
$ terraforming s3
|
138
141
|
```
|
139
142
|
|
140
|
-
```
|
143
|
+
```hcl
|
141
144
|
resource "aws_s3_bucket" "hoge" {
|
142
145
|
bucket = "hoge"
|
143
146
|
acl = "private"
|
@@ -375,6 +378,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
375
378
|
|
376
379
|
## Contributing
|
377
380
|
|
381
|
+
Please read [Contribution Guide](CONTRIBUTING.md) at first.
|
382
|
+
|
378
383
|
1. Fork it ( https://github.com/dtan4/terraforming/fork )
|
379
384
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
380
385
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/lib/terraforming/cli.rb
CHANGED
@@ -119,6 +119,16 @@ module Terraforming
|
|
119
119
|
execute(Terraforming::Resource::IAMUserPolicy, options)
|
120
120
|
end
|
121
121
|
|
122
|
+
desc "kmsa", "KMS Key Alias"
|
123
|
+
def kmsa
|
124
|
+
execute(Terraforming::Resource::KMSAlias, options)
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "kmsk", "KMS Key"
|
128
|
+
def kmsk
|
129
|
+
execute(Terraforming::Resource::KMSKey, options)
|
130
|
+
end
|
131
|
+
|
122
132
|
desc "lc", "Launch Configuration"
|
123
133
|
def lc
|
124
134
|
execute(Terraforming::Resource::LaunchConfiguration, options)
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"tags.Name" => efs.name,
|
30
30
|
}
|
31
31
|
|
32
|
-
resources["aws_efs_file_system.#{efs
|
32
|
+
resources["aws_efs_file_system.#{module_name_of(efs)}"] = {
|
33
33
|
"type" => "aws_efs_file_system",
|
34
34
|
"depends_on" => [],
|
35
35
|
"primary" => {
|
@@ -51,6 +51,10 @@ module Terraforming
|
|
51
51
|
def file_systems
|
52
52
|
@client.describe_file_systems.data.file_systems.flatten
|
53
53
|
end
|
54
|
+
|
55
|
+
def module_name_of(efs)
|
56
|
+
normalize_module_name(efs.file_system_id)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -32,7 +32,7 @@ module Terraforming
|
|
32
32
|
"vpc" => vpc?(addr).to_s,
|
33
33
|
}
|
34
34
|
attributes.delete_if { |_k, v| v.nil? }
|
35
|
-
resources["aws_eip.#{addr
|
35
|
+
resources["aws_eip.#{module_name_of(addr)}"] = {
|
36
36
|
"type" => "aws_eip",
|
37
37
|
"primary" => {
|
38
38
|
"id" => addr.allocation_id,
|
@@ -53,6 +53,10 @@ module Terraforming
|
|
53
53
|
def vpc?(addr)
|
54
54
|
addr.domain.eql?("vpc")
|
55
55
|
end
|
56
|
+
|
57
|
+
def module_name_of(addr)
|
58
|
+
normalize_module_name(addr.allocation_id)
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -42,7 +42,7 @@ module Terraforming
|
|
42
42
|
cache_cluster.cache_nodes[0].endpoint.port.to_s
|
43
43
|
end
|
44
44
|
|
45
|
-
resources["aws_elasticache_cluster.#{cache_cluster
|
45
|
+
resources["aws_elasticache_cluster.#{module_name_of(cache_cluster)}"] = {
|
46
46
|
"type" => "aws_elasticache_cluster",
|
47
47
|
"primary" => {
|
48
48
|
"id" => cache_cluster.cache_cluster_id,
|
@@ -71,6 +71,10 @@ module Terraforming
|
|
71
71
|
def security_group_names_of(cache_cluster)
|
72
72
|
cache_cluster.cache_security_groups.map { |sg| sg.cache_security_group_name }
|
73
73
|
end
|
74
|
+
|
75
|
+
def module_name_of(cache_cluster)
|
76
|
+
normalize_module_name(cache_cluster.cache_cluster_id)
|
77
|
+
end
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
@@ -26,7 +26,7 @@ module Terraforming
|
|
26
26
|
"name" => cache_subnet_group.cache_subnet_group_name,
|
27
27
|
"subnet_ids.#" => subnet_ids_of(cache_subnet_group).length.to_s,
|
28
28
|
}
|
29
|
-
resources["aws_elasticache_subnet_group.#{cache_subnet_group
|
29
|
+
resources["aws_elasticache_subnet_group.#{module_name_of(cache_subnet_group)}"] = {
|
30
30
|
"type" => "aws_elasticache_subnet_group",
|
31
31
|
"primary" => {
|
32
32
|
"id" => cache_subnet_group.cache_subnet_group_name,
|
@@ -47,6 +47,10 @@ module Terraforming
|
|
47
47
|
def subnet_ids_of(cache_subnet_group)
|
48
48
|
cache_subnet_group.subnets.map { |sn| sn.subnet_identifier }
|
49
49
|
end
|
50
|
+
|
51
|
+
def module_name_of(cache_subnet_group)
|
52
|
+
normalize_module_name(cache_subnet_group.cache_subnet_group_name)
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => group.path,
|
29
29
|
"unique_id" => group.group_id,
|
30
30
|
}
|
31
|
-
resources["aws_iam_group.#{group
|
31
|
+
resources["aws_iam_group.#{module_name_of(group)}"] = {
|
32
32
|
"type" => "aws_iam_group",
|
33
33
|
"primary" => {
|
34
34
|
"id" => group.group_name,
|
@@ -45,6 +45,10 @@ module Terraforming
|
|
45
45
|
def iam_groups
|
46
46
|
@client.list_groups.map(&:groups).flatten
|
47
47
|
end
|
48
|
+
|
49
|
+
def module_name_of(group)
|
50
|
+
normalize_module_name(group.group_name)
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"name" => membership_name,
|
30
30
|
"users.#" => group_members_of(group).length.to_s,
|
31
31
|
}
|
32
|
-
resources["aws_iam_group_membership.#{group
|
32
|
+
resources["aws_iam_group_membership.#{module_name_of(group)}"] = {
|
33
33
|
"type" => "aws_iam_group_membership",
|
34
34
|
"primary" => {
|
35
35
|
"id" => membership_name,
|
@@ -54,6 +54,10 @@ module Terraforming
|
|
54
54
|
def membership_name_of(group)
|
55
55
|
"#{group.group_name}-group-membership"
|
56
56
|
end
|
57
|
+
|
58
|
+
def module_name_of(group)
|
59
|
+
normalize_module_name(group.group_name)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => profile.path,
|
29
29
|
"roles.#" => profile.roles.length.to_s,
|
30
30
|
}
|
31
|
-
resources["aws_iam_instance_profile.#{profile
|
31
|
+
resources["aws_iam_instance_profile.#{module_name_of(profile)}"] = {
|
32
32
|
"type" => "aws_iam_instance_profile",
|
33
33
|
"primary" => {
|
34
34
|
"id" => profile.instance_profile_name,
|
@@ -45,6 +45,10 @@ module Terraforming
|
|
45
45
|
def iam_instance_profiles
|
46
46
|
@client.list_instance_profiles.map(&:instance_profiles).flatten
|
47
47
|
end
|
48
|
+
|
49
|
+
def module_name_of(profile)
|
50
|
+
normalize_module_name(profile.instance_profile_name)
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"description" => iam_policy_description(policy),
|
30
30
|
"policy" => prettify_policy(version.document, breakline: true, unescape: true),
|
31
31
|
}
|
32
|
-
resources["aws_iam_policy.#{policy
|
32
|
+
resources["aws_iam_policy.#{module_name_of(policy)}"] = {
|
33
33
|
"type" => "aws_iam_policy",
|
34
34
|
"primary" => {
|
35
35
|
"id" => policy.arn,
|
@@ -54,6 +54,10 @@ module Terraforming
|
|
54
54
|
def iam_policy_version_of(policy)
|
55
55
|
@client.get_policy_version(policy_arn: policy.arn, version_id: policy.default_version_id).policy_version
|
56
56
|
end
|
57
|
+
|
58
|
+
def module_name_of(policy)
|
59
|
+
normalize_module_name(policy.policy_name)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"users.#" => policy_attachment[:entities].policy_users.length.to_s,
|
30
30
|
"roles.#" => policy_attachment[:entities].policy_roles.length.to_s,
|
31
31
|
}
|
32
|
-
resources["aws_iam_policy_attachment.#{policy_attachment
|
32
|
+
resources["aws_iam_policy_attachment.#{module_name_of(policy_attachment)}"] = {
|
33
33
|
"type" => "aws_iam_policy_attachment",
|
34
34
|
"primary" => {
|
35
35
|
"id" => policy_attachment[:name],
|
@@ -77,6 +77,10 @@ module Terraforming
|
|
77
77
|
}
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
def module_name_of(policy_attachment)
|
82
|
+
normalize_module_name(policy_attachment[:name])
|
83
|
+
end
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
@@ -30,7 +30,7 @@ module Terraforming
|
|
30
30
|
"path" => role.path,
|
31
31
|
"unique_id" => role.role_id,
|
32
32
|
}
|
33
|
-
resources["aws_iam_role.#{role
|
33
|
+
resources["aws_iam_role.#{module_name_of(role)}"] = {
|
34
34
|
"type" => "aws_iam_role",
|
35
35
|
"primary" => {
|
36
36
|
"id" => role.role_name,
|
@@ -47,6 +47,10 @@ module Terraforming
|
|
47
47
|
def iam_roles
|
48
48
|
@client.list_roles.map(&:roles).flatten
|
49
49
|
end
|
50
|
+
|
51
|
+
def module_name_of(role)
|
52
|
+
normalize_module_name(role.role_name)
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class KMSAlias
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::KMS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::KMS::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/kms_alias")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
aliases.inject({}) do |resources, als|
|
24
|
+
resources["aws_kms_alias.#{module_name_of(als)}"] = {
|
25
|
+
"type" => "aws_kms_alias",
|
26
|
+
"primary" => {
|
27
|
+
"id" => als.alias_name,
|
28
|
+
"attributes" => {
|
29
|
+
"arn" => als.alias_arn,
|
30
|
+
"id" => als.alias_name,
|
31
|
+
"name" => als.alias_name,
|
32
|
+
"target_key_id" => als.target_key_id,
|
33
|
+
},
|
34
|
+
},
|
35
|
+
}
|
36
|
+
resources
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def aliases
|
43
|
+
@client.list_aliases.aliases.reject { |als| managed_master_key_alias?(als) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def managed_master_key_alias?(als)
|
47
|
+
als.alias_name =~ %r{\Aalias/aws/}
|
48
|
+
end
|
49
|
+
|
50
|
+
def module_name_of(als)
|
51
|
+
normalize_module_name(als.alias_name.gsub(%r{\Aalias/}, ""))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class KMSKey
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::KMS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::KMS::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/kms_key")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
keys.inject({}) do |resources, key|
|
24
|
+
resources["aws_kms_key.#{module_name_of(key)}"] = {
|
25
|
+
"type" => "aws_kms_key",
|
26
|
+
"primary" => {
|
27
|
+
"id" => key.key_id,
|
28
|
+
"attributes" => {
|
29
|
+
"arn" => key.arn,
|
30
|
+
"description" => key.description,
|
31
|
+
"enable_key_rotation" => key_rotation_status_of(key).key_rotation_enabled.to_s,
|
32
|
+
"id" => key.key_id,
|
33
|
+
"is_enabled" => key.enabled.to_s,
|
34
|
+
"key_id" => key.key_id,
|
35
|
+
"key_usage" => key_usage_of(key),
|
36
|
+
"policy" => key_policy_of(key),
|
37
|
+
},
|
38
|
+
},
|
39
|
+
}
|
40
|
+
resources
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def aliases
|
47
|
+
@aliases ||= @client.list_aliases.aliases
|
48
|
+
end
|
49
|
+
|
50
|
+
def keys
|
51
|
+
@client
|
52
|
+
.list_keys
|
53
|
+
.keys
|
54
|
+
.reject { |key| managed_master_key?(key) }
|
55
|
+
.map { |key| @client.describe_key(key_id: key.key_id) }
|
56
|
+
.map(&:key_metadata)
|
57
|
+
end
|
58
|
+
|
59
|
+
def key_policy_of(key)
|
60
|
+
policies = @client.list_key_policies(key_id: key.key_id).policy_names
|
61
|
+
|
62
|
+
return "" if policies.empty?
|
63
|
+
|
64
|
+
@client.get_key_policy(key_id: key.key_id, policy_name: policies[0]).policy
|
65
|
+
end
|
66
|
+
|
67
|
+
def key_rotation_status_of(key)
|
68
|
+
@client.get_key_rotation_status(key_id: key.key_id)
|
69
|
+
end
|
70
|
+
|
71
|
+
def key_usage_of(key)
|
72
|
+
key.key_usage.tr("_", "/")
|
73
|
+
end
|
74
|
+
|
75
|
+
def managed_master_key?(key)
|
76
|
+
!aliases.select { |a| a.target_key_id == key.key_id && a.alias_name =~ %r{\Aalias/aws/} }.empty?
|
77
|
+
end
|
78
|
+
|
79
|
+
def module_name_of(key)
|
80
|
+
normalize_module_name(key.key_id)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% cache_clusters.each do |cache_cluster| -%>
|
2
|
-
resource "aws_elasticache_cluster" "<%= cache_cluster
|
2
|
+
resource "aws_elasticache_cluster" "<%= module_name_of(cache_cluster) %>" {
|
3
3
|
cluster_id = "<%= cache_cluster.cache_cluster_id %>"
|
4
4
|
engine = "<%= cache_cluster.engine %>"
|
5
5
|
engine_version = "<%= cache_cluster.engine_version %>"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% cache_subnet_groups.each do |cache_subnet_group| -%>
|
2
|
-
resource "aws_elasticache_subnet_group" "<%= cache_subnet_group
|
2
|
+
resource "aws_elasticache_subnet_group" "<%= module_name_of(cache_subnet_group) %>" {
|
3
3
|
name = "<%= cache_subnet_group.cache_subnet_group_name %>"
|
4
4
|
description = "<%= cache_subnet_group.cache_subnet_group_description %>"
|
5
5
|
subnet_ids = <%= subnet_ids_of(cache_subnet_group).inspect %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% iam_groups.each do |group| -%>
|
2
|
-
resource "aws_iam_group_membership" "<%= group
|
2
|
+
resource "aws_iam_group_membership" "<%= module_name_of(group) %>" {
|
3
3
|
name = "<%= membership_name_of(group) %>"
|
4
4
|
users = <%= group_members_of(group).inspect %>
|
5
5
|
group = "<%= group.group_name %>"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% iam_instance_profiles.each do |profile| -%>
|
2
|
-
resource "aws_iam_instance_profile" "<%= profile
|
2
|
+
resource "aws_iam_instance_profile" "<%= module_name_of(profile) %>" {
|
3
3
|
name = "<%= profile.instance_profile_name %>"
|
4
4
|
path = "<%= profile.path %>"
|
5
5
|
roles = <%= profile.roles.map { |role| role.role_name }.inspect %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% iam_policies.each do |policy| -%>
|
2
2
|
<%- version = iam_policy_version_of(policy) -%>
|
3
|
-
resource "aws_iam_policy" "<%= policy
|
3
|
+
resource "aws_iam_policy" "<%= module_name_of(policy) %>" {
|
4
4
|
name = "<%= policy.policy_name %>"
|
5
5
|
path = "<%= policy.path %>"
|
6
6
|
description = "<%= iam_policy_description(policy) %>"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% iam_policy_attachments.each do |policy_attachment| -%>
|
2
|
-
resource "aws_iam_policy_attachment" "<%= policy_attachment
|
2
|
+
resource "aws_iam_policy_attachment" "<%= module_name_of(policy_attachment) %>" {
|
3
3
|
name = "<%= policy_attachment[:name] %>"
|
4
4
|
policy_arn = "<%= policy_attachment[:arn] %>"
|
5
5
|
groups = <%= policy_attachment[:entities].policy_groups.map(&:group_name).inspect %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% keys.each do |key| -%>
|
2
|
+
resource "aws_kms_key" "<%= module_name_of(key) %>" {
|
3
|
+
description = "<%= key.description %>"
|
4
|
+
key_usage = "<%= key_usage_of(key) %>"
|
5
|
+
is_enabled = <%= key.enabled %>
|
6
|
+
enable_key_rotation = <%= key_rotation_status_of(key).key_rotation_enabled %>
|
7
|
+
|
8
|
+
policy = <<POLICY
|
9
|
+
<%= key_policy_of(key).strip %>
|
10
|
+
POLICY
|
11
|
+
}
|
12
|
+
|
13
|
+
<% end -%>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% clusters.each do |cluster| -%>
|
2
|
-
resource "aws_redshift_cluster" "<%= cluster
|
2
|
+
resource "aws_redshift_cluster" "<%= module_name_of(cluster) %>" {
|
3
3
|
cluster_identifier = "<%= cluster.cluster_identifier %>"
|
4
4
|
<%- if cluster.db_name -%>
|
5
5
|
database_name = "<%= cluster.db_name %>"
|
data/lib/terraforming/version.rb
CHANGED
data/lib/terraforming.rb
CHANGED
@@ -30,6 +30,8 @@ require "terraforming/resource/iam_role"
|
|
30
30
|
require "terraforming/resource/iam_role_policy"
|
31
31
|
require "terraforming/resource/iam_user"
|
32
32
|
require "terraforming/resource/iam_user_policy"
|
33
|
+
require "terraforming/resource/kms_alias"
|
34
|
+
require "terraforming/resource/kms_key"
|
33
35
|
require "terraforming/resource/launch_configuration"
|
34
36
|
require "terraforming/resource/internet_gateway"
|
35
37
|
require "terraforming/resource/nat_gateway"
|
data/script/generate
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
USAGE = <<-EOS
|
6
|
+
Usage: script/generate RESOURCE
|
7
|
+
RESOURCE must be snake_case
|
8
|
+
|
9
|
+
Example:
|
10
|
+
script/generate EC2
|
11
|
+
EOS
|
12
|
+
|
13
|
+
def camelize(string)
|
14
|
+
string
|
15
|
+
.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
16
|
+
.gsub(%r{(?:_|(/))([a-z\d]*)}i) { "#{$1}#{$2.capitalize}" }
|
17
|
+
.gsub('/'.freeze, '::'.freeze)
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_resource_erb(resource)
|
21
|
+
template = File.join("templates", "resource.erb.erb")
|
22
|
+
ERB.new(open(template).read, nil, "-").result(binding)
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_resource_rb(resource)
|
26
|
+
template = File.expand_path(File.join("templates", "resource.rb.erb"))
|
27
|
+
ERB.new(open(template).read, nil, "-").result(binding)
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_resource_spec_rb(resource)
|
31
|
+
template = File.join("templates", "resource_spec.rb.erb")
|
32
|
+
ERB.new(open(template).read, nil, "-").result(binding)
|
33
|
+
end
|
34
|
+
|
35
|
+
def humanize(string)
|
36
|
+
string
|
37
|
+
.sub(/\A_+/, ''.freeze)
|
38
|
+
.sub(/_id\z/, ''.freeze)
|
39
|
+
.tr('_'.freeze, ' '.freeze)
|
40
|
+
.gsub(/([a-z\d]*)/i) { |match| match.downcase }
|
41
|
+
.split(" ")
|
42
|
+
.map { |w| w[0].upcase + w[1..-1] }
|
43
|
+
.join(" ")
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
if ARGV.length != 1
|
49
|
+
$stderr.puts USAGE
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
resource = ARGV[0]
|
54
|
+
|
55
|
+
puts "==> Generate #{resource}.rb"
|
56
|
+
resource_rb = generate_resource_rb(resource)
|
57
|
+
File.open(File.join("lib", "terraforming", "resource", "#{resource}.rb"), "w+") { |f| f.write(resource_rb) }
|
58
|
+
|
59
|
+
puts "==> Generate #{resource}_spec.rb"
|
60
|
+
resource_spec_rb = generate_resource_spec_rb(resource)
|
61
|
+
File.open(File.join("spec", "lib", "terraforming", "resource", "#{resource}_spec.rb"), "w+") { |f| f.write(resource_spec_rb) }
|
62
|
+
|
63
|
+
puts "==> Generate #{resource}.erb"
|
64
|
+
resource_erb = generate_resource_erb(resource)
|
65
|
+
File.open(File.join("lib", "terraforming", "template", "tf", "#{resource}.erb"), "w+") { |f| f.write(resource_erb) }
|
66
|
+
|
67
|
+
puts <<-EOS
|
68
|
+
|
69
|
+
Add below code by hand.
|
70
|
+
|
71
|
+
lib/terraforming.rb:
|
72
|
+
|
73
|
+
require "terraforming/resource/#{resource}"
|
74
|
+
|
75
|
+
lib/terraforming/cli.rb:
|
76
|
+
|
77
|
+
module Terraforming
|
78
|
+
class CLI < Thor
|
79
|
+
|
80
|
+
# Subcommand name should be acronym.
|
81
|
+
desc "#{resource}", "#{humanize(resource)}"
|
82
|
+
def #{resource}
|
83
|
+
execute(Terraforming::Resource::#{camelize(resource)}, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
spec/lib/terraforming/cli_spec.rb:
|
87
|
+
|
88
|
+
module Terraforming
|
89
|
+
describe CLI do
|
90
|
+
context "resources" do
|
91
|
+
describe "#{resource}" do
|
92
|
+
let(:klass) { Terraforming::Resource::#{camelize(resource)} }
|
93
|
+
let(:command) { :#{resource} }
|
94
|
+
|
95
|
+
it_behaves_like "CLI examples"
|
96
|
+
end
|
97
|
+
EOS
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class <%= camelize(resource) %>
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
# TODO: Select appropriate Client class from here:
|
7
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
8
|
+
def self.tf(client: Aws::SomeResource::Client.new)
|
9
|
+
self.new(client).tf
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO: Select appropriate Client class from here:
|
13
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
14
|
+
def self.tfstate(client: Aws::SomeResource::Client.new)
|
15
|
+
self.new(client).tfstate
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(client)
|
19
|
+
@client = client
|
20
|
+
end
|
21
|
+
|
22
|
+
def tf
|
23
|
+
apply_template(@client, "tf/<%= resource %>")
|
24
|
+
end
|
25
|
+
|
26
|
+
def tfstate
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Terraforming
|
4
|
+
module Resource
|
5
|
+
describe <%= camelize(resource) %> do
|
6
|
+
let(:client) do
|
7
|
+
# TODO: Select appropriate Client class from here:
|
8
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
9
|
+
Aws::SomeResource::Client.new(stub_responses: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".tf" do
|
13
|
+
xit "should generate tf" do
|
14
|
+
expect(described_class.tf(client: client)).to eq <<-EOS
|
15
|
+
resource "aws_<%= resource %>" "resource_name" {
|
16
|
+
|
17
|
+
}
|
18
|
+
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".tfstate" do
|
24
|
+
xit "should generate tfstate" do
|
25
|
+
expect(described_class.tfstate(client: client)).to eq({
|
26
|
+
"aws_<%= resource %>.resource_name" => {
|
27
|
+
"type" => "aws_<%= resource %>",
|
28
|
+
"primary" => {
|
29
|
+
"id" => "",
|
30
|
+
"attributes" => {
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 0.13.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:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -169,6 +169,8 @@ files:
|
|
169
169
|
- lib/terraforming/resource/iam_user.rb
|
170
170
|
- lib/terraforming/resource/iam_user_policy.rb
|
171
171
|
- lib/terraforming/resource/internet_gateway.rb
|
172
|
+
- lib/terraforming/resource/kms_alias.rb
|
173
|
+
- lib/terraforming/resource/kms_key.rb
|
172
174
|
- lib/terraforming/resource/launch_configuration.rb
|
173
175
|
- lib/terraforming/resource/nat_gateway.rb
|
174
176
|
- lib/terraforming/resource/network_acl.rb
|
@@ -208,6 +210,8 @@ files:
|
|
208
210
|
- lib/terraforming/template/tf/iam_user.erb
|
209
211
|
- lib/terraforming/template/tf/iam_user_policy.erb
|
210
212
|
- lib/terraforming/template/tf/internet_gateway.erb
|
213
|
+
- lib/terraforming/template/tf/kms_alias.erb
|
214
|
+
- lib/terraforming/template/tf/kms_key.erb
|
211
215
|
- lib/terraforming/template/tf/launch_configuration.erb
|
212
216
|
- lib/terraforming/template/tf/nat_gateway.erb
|
213
217
|
- lib/terraforming/template/tf/network_acl.erb
|
@@ -227,7 +231,11 @@ files:
|
|
227
231
|
- lib/terraforming/util.rb
|
228
232
|
- lib/terraforming/version.rb
|
229
233
|
- script/console
|
234
|
+
- script/generate
|
230
235
|
- script/setup
|
236
|
+
- templates/resource.erb.erb
|
237
|
+
- templates/resource.rb.erb
|
238
|
+
- templates/resource_spec.rb.erb
|
231
239
|
- terraforming.gemspec
|
232
240
|
homepage: https://github.com/dtan4/terraforming
|
233
241
|
licenses:
|
@@ -249,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
257
|
version: '0'
|
250
258
|
requirements: []
|
251
259
|
rubyforge_project:
|
252
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.6.8
|
253
261
|
signing_key:
|
254
262
|
specification_version: 4
|
255
263
|
summary: Export existing AWS resources to Terraform style (tf, tfstate)
|