terraforming 0.1.4 → 0.1.5

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: e0d4e58b3e575b0651e800cad36a2fb8c58780cc
4
- data.tar.gz: 12a4b4fb459f47b28089fcd063bad8b4e720b94f
3
+ metadata.gz: 456f41b8b7dace703db8fe006d3ba82789353a1a
4
+ data.tar.gz: deab4d92676649424ffbab582995085c098ac9de
5
5
  SHA512:
6
- metadata.gz: 0a56a65bff72645122cfd3191dd5354fb9c133528e4d3c4374e84a356ab8621bb31ec5d64d1371d8fa4294484f719f8f3981e9b6825c6f074bd0be105a861270
7
- data.tar.gz: 347f65090624c3eac681ed58a8e66dcd0c84a4d47606811e428261449dae95232037d48e2f19db3adba69ce6e0178978dce55ac17e404a53b9a53fd8470678c3
6
+ metadata.gz: 7d21bab80223eac19400fcca1c389a7b8cba2862a942afe4fe230c35e03c715c70be9733d8ab44bed849ab582c5df1bcbf5d617d95b31fe80b08539730ca85aa
7
+ data.tar.gz: 5d3347dcf189fb4468e147f722894ac664946fd915240a5f7af8e9b73675665889f0135f85e09293230633d954c23b7ce1223ff8da1b449cb77caa9fffef2b4b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [v0.1.5](https://github.com/dtan4/terraforming/releases/tag/v0.1.5) (2015-08-10)
2
+
3
+ ### Updated
4
+
5
+ - Support S3 bucket policy #110
6
+
1
7
  # [v0.1.4](https://github.com/dtan4/terraforming/releases/tag/v0.1.4) (2015-08-07)
2
8
 
3
9
  ### Fixed
@@ -25,7 +25,7 @@ module Terraforming
25
25
  "group" => policy.group_name,
26
26
  "id" => iam_group_policy_id_of(policy),
27
27
  "name" => policy.policy_name,
28
- "policy" => prettify_policy(policy.policy_document, true)
28
+ "policy" => prettify_policy(policy.policy_document, breakline: true, unescape: true)
29
29
  }
30
30
  resources["aws_iam_group_policy.#{policy.policy_name}"] = {
31
31
  "type" => "aws_iam_group_policy",
@@ -26,7 +26,7 @@ module Terraforming
26
26
  "id" => policy.arn,
27
27
  "name" => policy.policy_name,
28
28
  "path" => policy.path,
29
- "policy" => prettify_policy(version.document, true),
29
+ "policy" => prettify_policy(version.document, breakline: true, unescape: true),
30
30
  }
31
31
  resources["aws_iam_policy.#{policy.policy_name}"] = {
32
32
  "type" => "aws_iam_policy",
@@ -23,7 +23,8 @@ module Terraforming
23
23
  iam_roles.inject({}) do |resources, role|
24
24
  attributes = {
25
25
  "arn" => role.arn,
26
- "assume_role_policy" => prettify_policy(role.assume_role_policy_document, true),
26
+ "assume_role_policy" =>
27
+ prettify_policy(role.assume_role_policy_document, breakline: true, unescape: true),
27
28
  "id" => role.role_name,
28
29
  "name" => role.role_name,
29
30
  "path" => role.path,
@@ -24,7 +24,7 @@ module Terraforming
24
24
  attributes = {
25
25
  "id" => iam_role_policy_id_of(policy),
26
26
  "name" => policy.policy_name,
27
- "policy" => prettify_policy(policy.policy_document, true),
27
+ "policy" => prettify_policy(policy.policy_document, breakline: true, unescape: true),
28
28
  "role" => policy.role_name,
29
29
  }
30
30
  resources["aws_iam_role_policy.#{policy.policy_name}"] = {
@@ -24,7 +24,7 @@ module Terraforming
24
24
  attributes = {
25
25
  "id" => iam_user_policy_id_of(policy),
26
26
  "name" => policy.policy_name,
27
- "policy" => prettify_policy(policy.policy_document, true),
27
+ "policy" => prettify_policy(policy.policy_document, breakline: true, unescape: true),
28
28
  "user" => policy.user_name,
29
29
  }
30
30
  resources["aws_iam_user_policy.#{policy.policy_name}"] = {
@@ -21,6 +21,7 @@ module Terraforming
21
21
 
22
22
  def tfstate
23
23
  buckets.inject({}) do |resources, bucket|
24
+ bucket_policy = bucket_policy_of(bucket)
24
25
  resources["aws_s3_bucket.#{module_name_of(bucket)}"] = {
25
26
  "type" => "aws_s3_bucket",
26
27
  "primary" => {
@@ -28,7 +29,9 @@ module Terraforming
28
29
  "attributes" => {
29
30
  "acl" => "private",
30
31
  "bucket" => bucket.name,
31
- "id" => bucket.name
32
+ "force_destroy" => "false",
33
+ "id" => bucket.name,
34
+ "policy" => bucket_policy ? bucket_policy.policy.read : "",
32
35
  }
33
36
  }
34
37
  }
@@ -39,6 +42,12 @@ module Terraforming
39
42
 
40
43
  private
41
44
 
45
+ def bucket_policy_of(bucket)
46
+ @client.get_bucket_policy(bucket: bucket.name)
47
+ rescue Aws::S3::Errors::NoSuchBucketPolicy
48
+ nil
49
+ end
50
+
42
51
  def buckets
43
52
  @client.list_buckets.buckets
44
53
  end
@@ -3,7 +3,7 @@ resource "aws_iam_group_policy" "<%= policy.policy_name %>" {
3
3
  name = "<%= policy.policy_name %>"
4
4
  group = "<%= policy.group_name %>"
5
5
  policy = <<POLICY
6
- <%= prettify_policy(policy.policy_document) %>
6
+ <%= prettify_policy(policy.policy_document, unescape: true) %>
7
7
  POLICY
8
8
  }
9
9
 
@@ -4,7 +4,7 @@ resource "aws_iam_policy" "<%= policy.policy_name %>" {
4
4
  name = "<%= policy.policy_name %>"
5
5
  path = "<%= policy.path %>"
6
6
  policy = <<POLICY
7
- <%= prettify_policy(version.document) %>
7
+ <%= prettify_policy(version.document, unescape: true) %>
8
8
  POLICY
9
9
  }
10
10
 
@@ -3,7 +3,7 @@ resource "aws_iam_role" "<%= role.role_name %>" {
3
3
  name = "<%= role.role_name %>"
4
4
  path = "<%= role.path %>"
5
5
  assume_role_policy = <<POLICY
6
- <%= prettify_policy(role.assume_role_policy_document) %>
6
+ <%= prettify_policy(role.assume_role_policy_document, unescape: true) %>
7
7
  POLICY
8
8
  }
9
9
 
@@ -3,7 +3,7 @@ resource "aws_iam_role_policy" "<%= policy.policy_name %>" {
3
3
  name = "<%= policy.policy_name %>"
4
4
  role = "<%= policy.role_name %>"
5
5
  policy = <<POLICY
6
- <%= prettify_policy(policy.policy_document) %>
6
+ <%= prettify_policy(policy.policy_document, unescape: true) %>
7
7
  POLICY
8
8
  }
9
9
 
@@ -3,7 +3,7 @@ resource "aws_iam_user_policy" "<%= policy.policy_name %>" {
3
3
  name = "<%= policy.policy_name %>"
4
4
  user = "<%= policy.user_name %>"
5
5
  policy = <<POLICY
6
- <%= prettify_policy(policy.policy_document) %>
6
+ <%= prettify_policy(policy.policy_document, unescape: true) %>
7
7
  POLICY
8
8
  }
9
9
 
@@ -2,6 +2,11 @@
2
2
  resource "aws_s3_bucket" "<%= module_name_of(bucket) %>" {
3
3
  bucket = "<%= bucket.name %>"
4
4
  acl = "private"
5
+ <%- unless (policy = bucket_policy_of(bucket)).nil? -%>
6
+ policy = <<POLICY
7
+ <%= prettify_policy(policy.policy.read) %>
8
+ POLICY
9
+ <%- end -%>
5
10
  }
6
11
 
7
12
  <% end -%>
@@ -17,8 +17,8 @@ module Terraforming
17
17
  File.join(File.expand_path(File.dirname(__FILE__)), "template", template_name) << ".erb"
18
18
  end
19
19
 
20
- def prettify_policy(policy_document, breakline = false)
21
- json = JSON.pretty_generate(JSON.parse(CGI.unescape(policy_document)))
20
+ def prettify_policy(document, breakline: false, unescape: false)
21
+ json = JSON.pretty_generate(JSON.parse(unescape ? CGI.unescape(document) : document))
22
22
 
23
23
  if breakline
24
24
  json[-1] != "\n" ? json << "\n" : json
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
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-06 00:00:00.000000000 Z
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -258,9 +258,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubyforge_project:
261
- rubygems_version: 2.4.7
261
+ rubygems_version: 2.4.5
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: