practice_terraforming 0.1.4 → 0.1.5
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/Gemfile.lock +1 -1
- data/README.md +68 -7
- data/lib/practice_terraforming.rb +1 -0
- data/lib/practice_terraforming/cli.rb +5 -0
- data/lib/practice_terraforming/resource/iam_group_policy_attachment.rb +78 -0
- data/lib/practice_terraforming/template/tf/iam_group_policy_attachment.erb +7 -0
- data/lib/practice_terraforming/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5c1c6917cacde37c98cd92a4a0586a9a2a3d64
|
4
|
+
data.tar.gz: afc1061b5d576f8ec3589dda72e173f1ba6df4a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d731812e269872c606f6fc4dfbe0635ef2477c60d81d8af1429e54192aeae49a8305b9d55dec083e7430b374c864ab3774d13b9ff551319e4dab408621b00303
|
7
|
+
data.tar.gz: 2c26afc9ea90d3d74be6a572495fa9b6041b3dfeecfa5663d20e3b85da699b2e9eb1ffe24fcf1c2a7d55ee232d8a933e48693e9afa74e5c1c9947020c6c54870
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -106,7 +106,7 @@ Wrote dependencies with `spec.add_dependency` and `spec.add_development_dependen
|
|
106
106
|
|
107
107
|
## Create Resource
|
108
108
|
|
109
|
-
|
109
|
+
1. generate templates with `script/generate`
|
110
110
|
|
111
111
|
```
|
112
112
|
script/generate iam_policy_attachment
|
@@ -145,9 +145,53 @@ Wrote dependencies with `spec.add_dependency` and `spec.add_development_dependen
|
|
145
145
|
```
|
146
146
|
|
147
147
|
1. As the message says, add those codes.
|
148
|
+
|
149
|
+
Need to chagnge a little bit
|
150
|
+
|
151
|
+
lib/practice_terraforming/cli.rb:
|
152
|
+
|
153
|
+
```diff
|
154
|
+
- desc "iam_policy_attachment", "Iam Policy Attachment"
|
155
|
+
- def iam_policy_attachment
|
156
|
+
- execute(PracticeTerraforming::Resource::IamPolicyAttachment, options)
|
157
|
+
+ desc "iampa", "Iam Policy Attachment"
|
158
|
+
+ def iampa
|
159
|
+
+ execute(PracticeTerraforming::Resource::IAMPolicyAttachment, options)
|
160
|
+
```
|
161
|
+
|
162
|
+
spec/lib/practice_terraforming/cli_spec.rb:
|
163
|
+
|
164
|
+
|
165
|
+
```diff
|
166
|
+
- describe "iam_policy_attachment" do
|
167
|
+
- let(:klass) { PracticeTerraforming::Resource::IamPolicyAttachment }
|
168
|
+
- let(:command) { :iam_policy_attachment }
|
169
|
+
+ describe "iampa" do
|
170
|
+
+ let(:klass) { PracticeTerraforming::Resource::IAMPolicyAttachment }
|
171
|
+
+ let(:command) { :iampa }
|
172
|
+
```
|
173
|
+
|
148
174
|
1. `lib/practice_terraforming/resource/iam_policy_attachment.rb`: Change Aws client and write logic in `tfstate` method
|
149
175
|
|
150
|
-
Use aws-sdk-<resource> to get the input data
|
176
|
+
Use aws-sdk-<resource> to get the input data
|
177
|
+
|
178
|
+
```diff
|
179
|
+
# TODO: Select appropriate Client class from here:
|
180
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
181
|
+
- def self.tf(client: Aws::SomeResource::Client.new)
|
182
|
+
+ def self.tf(client: Aws::IAM::Client.new)
|
183
|
+
self.new(client).tf
|
184
|
+
end
|
185
|
+
|
186
|
+
# TODO: Select appropriate Client class from here:
|
187
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
188
|
+
- def self.tfstate(client: Aws::SomeResource::Client.new)
|
189
|
+
+ def self.tfstate(client: Aws::IAM::Client.new)
|
190
|
+
self.new(client).tfstate
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
write the logic to generate tf/tfstate file.
|
151
195
|
1. tf -> only need to update the template file, which appears in the next step
|
152
196
|
2. tfstate -> get resource list using private method, format them into resources and return them
|
153
197
|
3. As for private methods:
|
@@ -172,19 +216,36 @@ Wrote dependencies with `spec.add_dependency` and `spec.add_development_dependen
|
|
172
216
|
|
173
217
|
1. `spec/lib/practice_terraforming/resource/iam_policy_attachment_spec.rb`: Change Aws client and write test for tf and tfstate
|
174
218
|
|
219
|
+
Change Aws client
|
220
|
+
|
221
|
+
```diff
|
222
|
+
module PracticeTerraforming
|
223
|
+
module Resource
|
224
|
+
- describe IamPolicyAttachment do
|
225
|
+
+ describe IAMPolicyAttachment do
|
226
|
+
let(:client) do
|
227
|
+
# TODO: Select appropriate Client class from here:
|
228
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
229
|
+
- Aws::SomeResource::Client.new(stub_responses: true)
|
230
|
+
+ Aws::IAM::Client.new(stub_responses: true)
|
231
|
+
end
|
232
|
+
|
233
|
+
describe ".tf" do
|
234
|
+
```
|
235
|
+
|
175
236
|
Test Perspective:
|
176
237
|
1. Create aws sdk result using stub.
|
177
238
|
2. Use the module to generate tf/tfstate.
|
178
239
|
3. Compare expected one and generated one.
|
179
240
|
|
180
|
-
```
|
241
|
+
```ruby
|
181
242
|
irb(main):007:0> client.list_policies.policies[0]
|
182
243
|
=> #<struct Aws::IAM::Types::Policy policy_name="test-policy", policy_id="ABCDEFG", arn="arn:aws:iam::123456789:policy/test-policy", path="/", default_version_id="v1", attachment_count=1, permissions_boundary_usage_count=0, is_attachable=true, description=nil, create_date=2019-01-01 00:00:00 UTC, update_date=2019-01-02 00:00:00 UTC>
|
183
244
|
irb(main):008:0> client.list_entities_for_policy(policy_arn: "arn:aws:iam::123456789:policy/test-policy")
|
184
245
|
=> #<struct Aws::IAM::Types::ListEntitiesForPolicyResponse policy_groups=[#<struct Aws::IAM::Types::PolicyGroup group_name="test-group", group_id="ABCDEFG">], policy_users=[], policy_roles=[], is_truncated=false, marker=nil>
|
185
246
|
```
|
186
247
|
|
187
|
-
```
|
248
|
+
```ruby
|
188
249
|
let(:policies) do
|
189
250
|
[
|
190
251
|
{
|
@@ -222,7 +283,7 @@ Wrote dependencies with `spec.add_dependency` and `spec.add_development_dependen
|
|
222
283
|
|
223
284
|
### Build
|
224
285
|
|
225
|
-
```
|
286
|
+
```bash
|
226
287
|
gem build practice_terraforming.gemspec
|
227
288
|
```
|
228
289
|
|
@@ -232,7 +293,7 @@ the above command will generate the `practice_terraforming-X.X.X.gem`
|
|
232
293
|
|
233
294
|
0.1.0 as an example
|
234
295
|
|
235
|
-
```
|
296
|
+
```bash
|
236
297
|
gem install practice_terraforming-0.1.0.gem
|
237
298
|
Successfully installed practice_terraforming-0.1.0
|
238
299
|
Parsing documentation for practice_terraforming-0.1.0
|
@@ -243,7 +304,7 @@ Done installing documentation for practice_terraforming after 0 seconds
|
|
243
304
|
|
244
305
|
### Check
|
245
306
|
|
246
|
-
```
|
307
|
+
```bash
|
247
308
|
practice_terraforming
|
248
309
|
Commands:
|
249
310
|
practice_terraforming help [COMMAND] # Describe available commands or one specific command
|
@@ -13,5 +13,6 @@ require "practice_terraforming/cli"
|
|
13
13
|
require "practice_terraforming/resource/iam_role"
|
14
14
|
require "practice_terraforming/resource/iam_role_policy_attachment"
|
15
15
|
require "practice_terraforming/resource/iam_user_policy_attachment"
|
16
|
+
require "practice_terraforming/resource/iam_group_policy_attachment"
|
16
17
|
require "practice_terraforming/resource/iam_policy_attachment"
|
17
18
|
require "practice_terraforming/resource/s3"
|
@@ -38,6 +38,11 @@ module PracticeTerraforming
|
|
38
38
|
execute(PracticeTerraforming::Resource::IAMUserPolicyAttachment, options)
|
39
39
|
end
|
40
40
|
|
41
|
+
desc "iamgpa", "Iam Group Policy Attachment"
|
42
|
+
def iamgpa
|
43
|
+
execute(PracticeTerraforming::Resource::IAMGroupPolicyAttachment, options)
|
44
|
+
end
|
45
|
+
|
41
46
|
private
|
42
47
|
|
43
48
|
def configure_aws(options)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PracticeTerraforming
|
4
|
+
module Resource
|
5
|
+
class IAMGroupPolicyAttachment
|
6
|
+
include PracticeTerraforming::Util
|
7
|
+
|
8
|
+
# TODO: Select appropriate Client class from here:
|
9
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
10
|
+
def self.tf(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tf
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO: Select appropriate Client class from here:
|
15
|
+
# http://docs.aws.amazon.com/sdkforruby/api/index.html
|
16
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
17
|
+
self.new(client).tfstate
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(client)
|
21
|
+
@client = client
|
22
|
+
end
|
23
|
+
|
24
|
+
def tf
|
25
|
+
apply_template(@client, "tf/iam_group_policy_attachment")
|
26
|
+
end
|
27
|
+
|
28
|
+
def tfstate
|
29
|
+
iam_group_policy_attachments.inject({}) do |resources, group_policy_attachment|
|
30
|
+
attributes = {
|
31
|
+
"id" => group_policy_attachment[:name],
|
32
|
+
"policy_arn" => group_policy_attachment[:policy_arn],
|
33
|
+
"group" => group_policy_attachment[:group]
|
34
|
+
}
|
35
|
+
resources["aws_iam_group_policy_attachment.#{module_name_of(group_policy_attachment)}"] = {
|
36
|
+
"type" => "aws_iam_group_policy_attachment",
|
37
|
+
"primary" => {
|
38
|
+
"id" => group_policy_attachment[:name],
|
39
|
+
"attributes" => attributes
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
resources
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def attachment_name_from(group, policy)
|
50
|
+
"#{group.group_name}-#{policy.policy_name}-attachment"
|
51
|
+
end
|
52
|
+
|
53
|
+
def iam_groups
|
54
|
+
@client.list_groups.map(&:groups).flatten
|
55
|
+
end
|
56
|
+
|
57
|
+
def policies_attached_to(group)
|
58
|
+
@client.list_attached_group_policies(group_name: group.group_name).attached_policies
|
59
|
+
end
|
60
|
+
|
61
|
+
def iam_group_policy_attachments
|
62
|
+
iam_groups.map do |group|
|
63
|
+
policies_attached_to(group).map do |policy|
|
64
|
+
{
|
65
|
+
group: group.group_name,
|
66
|
+
policy_arn: policy.policy_arn,
|
67
|
+
name: attachment_name_from(group, policy)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end.flatten
|
71
|
+
end
|
72
|
+
|
73
|
+
def module_name_of(group_policy_attachment)
|
74
|
+
normalize_module_name(group_policy_attachment[:name])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<% iam_group_policy_attachments.each do |group_policy_attachment| -%>
|
2
|
+
resource "aws_iam_group_policy_attachment" "<%= module_name_of(group_policy_attachment) %>" {
|
3
|
+
policy_arn = "<%= group_policy_attachment[:policy_arn] %>"
|
4
|
+
group = "<%= group_policy_attachment[:group] %>"
|
5
|
+
}
|
6
|
+
|
7
|
+
<% end -%>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: practice_terraforming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masatonaka
|
@@ -158,11 +158,13 @@ files:
|
|
158
158
|
- bin/practice_terraforming
|
159
159
|
- lib/practice_terraforming.rb
|
160
160
|
- lib/practice_terraforming/cli.rb
|
161
|
+
- lib/practice_terraforming/resource/iam_group_policy_attachment.rb
|
161
162
|
- lib/practice_terraforming/resource/iam_policy_attachment.rb
|
162
163
|
- lib/practice_terraforming/resource/iam_role.rb
|
163
164
|
- lib/practice_terraforming/resource/iam_role_policy_attachment.rb
|
164
165
|
- lib/practice_terraforming/resource/iam_user_policy_attachment.rb
|
165
166
|
- lib/practice_terraforming/resource/s3.rb
|
167
|
+
- lib/practice_terraforming/template/tf/iam_group_policy_attachment.erb
|
166
168
|
- lib/practice_terraforming/template/tf/iam_policy_attachment.erb
|
167
169
|
- lib/practice_terraforming/template/tf/iam_role.erb
|
168
170
|
- lib/practice_terraforming/template/tf/iam_role_policy_attachment.erb
|