geoengineer 0.1.0 → 0.1.1

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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +5 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +5 -5
  5. data/lib/geoengineer/cli/geo_cli.rb +4 -5
  6. data/lib/geoengineer/cli/status_command.rb +7 -1
  7. data/lib/geoengineer/environment.rb +53 -51
  8. data/lib/geoengineer/project.rb +5 -24
  9. data/lib/geoengineer/resource.rb +89 -20
  10. data/lib/geoengineer/resources/aws_customer_gateway.rb +23 -0
  11. data/lib/geoengineer/resources/aws_eip.rb +43 -0
  12. data/lib/geoengineer/resources/aws_iam_group.rb +26 -0
  13. data/lib/geoengineer/resources/aws_iam_group_membership.rb +50 -0
  14. data/lib/geoengineer/resources/aws_iam_policy.rb +12 -4
  15. data/lib/geoengineer/resources/aws_iam_policy_attachment.rb +95 -0
  16. data/lib/geoengineer/resources/aws_iam_role.rb +45 -0
  17. data/lib/geoengineer/resources/aws_instance.rb +7 -4
  18. data/lib/geoengineer/resources/aws_internet_gateway.rb +23 -0
  19. data/lib/geoengineer/resources/aws_lambda_alias.rb +50 -0
  20. data/lib/geoengineer/resources/aws_lambda_event_source_mapping.rb +47 -0
  21. data/lib/geoengineer/resources/aws_lambda_function.rb +30 -0
  22. data/lib/geoengineer/resources/aws_lambda_permission.rb +74 -0
  23. data/lib/geoengineer/resources/aws_main_route_table_association.rb +51 -0
  24. data/lib/geoengineer/resources/aws_nat_gateway.rb +29 -0
  25. data/lib/geoengineer/resources/aws_network_acl.rb +38 -0
  26. data/lib/geoengineer/resources/aws_network_acl_rule.rb +50 -0
  27. data/lib/geoengineer/resources/aws_route.rb +47 -0
  28. data/lib/geoengineer/resources/aws_route53_record.rb +4 -0
  29. data/lib/geoengineer/resources/aws_route_table.rb +26 -0
  30. data/lib/geoengineer/resources/aws_route_table_association.rb +45 -0
  31. data/lib/geoengineer/resources/aws_security_group.rb +8 -5
  32. data/lib/geoengineer/resources/aws_subnet.rb +24 -0
  33. data/lib/geoengineer/resources/aws_vpc.rb +24 -0
  34. data/lib/geoengineer/resources/aws_vpc_dhcp_options.rb +29 -0
  35. data/lib/geoengineer/resources/aws_vpc_dhcp_options_association.rb +40 -0
  36. data/lib/geoengineer/resources/aws_vpc_endpoint.rb +26 -0
  37. data/lib/geoengineer/resources/aws_vpc_peering_connection.rb +29 -0
  38. data/lib/geoengineer/resources/aws_vpn_connection.rb +23 -0
  39. data/lib/geoengineer/resources/aws_vpn_connection_route.rb +35 -0
  40. data/lib/geoengineer/resources/aws_vpn_gateway.rb +22 -0
  41. data/lib/geoengineer/resources/aws_vpn_gateway_attachment.rb +41 -0
  42. data/lib/geoengineer/template.rb +20 -4
  43. data/lib/geoengineer/utils/aws_clients.rb +4 -0
  44. data/lib/geoengineer/utils/crc32.rb +61 -0
  45. data/lib/geoengineer/utils/has_attributes.rb +25 -11
  46. data/lib/geoengineer/utils/has_projects.rb +21 -0
  47. data/lib/geoengineer/utils/has_resources.rb +17 -4
  48. data/lib/geoengineer/utils/has_templates.rb +31 -0
  49. data/lib/geoengineer/utils/has_validations.rb +18 -3
  50. data/lib/geoengineer/version.rb +1 -1
  51. data/spec/environment_spec.rb +40 -19
  52. data/spec/project_spec.rb +2 -2
  53. data/spec/resource_spec.rb +87 -6
  54. data/spec/resources/aws_customer_gateway_spec.rb +24 -0
  55. data/spec/resources/aws_eip_spec.rb +29 -0
  56. data/spec/resources/aws_iam_group_membership_spec.rb +83 -0
  57. data/spec/resources/aws_iam_group_spec.rb +43 -0
  58. data/spec/resources/aws_iam_policy_attachment_spec.rb +80 -0
  59. data/spec/resources/{aws_iam_policy.rb → aws_iam_policy_spec.rb} +6 -5
  60. data/spec/resources/aws_iam_role_spec.rb +45 -0
  61. data/spec/resources/aws_internet_gateway_spec.rb +24 -0
  62. data/spec/resources/aws_lambda_alias_spec.rb +39 -0
  63. data/spec/resources/aws_lambda_event_source_mapping_spec.rb +53 -0
  64. data/spec/resources/aws_lambda_function_spec.rb +29 -0
  65. data/spec/resources/aws_lambda_permission_spec.rb +90 -0
  66. data/spec/resources/aws_main_route_table_association_spec.rb +57 -0
  67. data/spec/resources/aws_nat_gateway_spec.rb +31 -0
  68. data/spec/resources/aws_network_acl_rule_spec.rb +73 -0
  69. data/spec/resources/aws_network_acl_spec.rb +31 -0
  70. data/spec/resources/aws_route53_record_spec.rb +5 -0
  71. data/spec/resources/aws_route_spec.rb +47 -0
  72. data/spec/resources/aws_route_table_association_spec.rb +47 -0
  73. data/spec/resources/aws_route_table_spec.rb +24 -0
  74. data/spec/resources/aws_security_group_spec.rb +36 -2
  75. data/spec/resources/aws_subnet_spec.rb +24 -0
  76. data/spec/resources/aws_vpc_dhcp_options_association_spec.rb +43 -0
  77. data/spec/resources/aws_vpc_dhcp_options_spec.rb +24 -0
  78. data/spec/resources/aws_vpc_endpoint_spec.rb +41 -0
  79. data/spec/resources/aws_vpc_peering_connection_spec.rb +33 -0
  80. data/spec/resources/aws_vpc_spec.rb +24 -0
  81. data/spec/resources/aws_vpn_connection_route_spec.rb +43 -0
  82. data/spec/resources/aws_vpn_connection_spec.rb +41 -0
  83. data/spec/resources/aws_vpn_gateway_attachment_spec.rb +41 -0
  84. data/spec/resources/aws_vpn_gateway_spec.rb +39 -0
  85. data/spec/spec_helper.rb +3 -1
  86. data/spec/utils/crc32_spec.rb +14 -0
  87. data/spec/utils/has_attributes_spec.rb +22 -0
  88. data/spec/utils/has_resources_spec.rb +4 -0
  89. data/spec/utils/has_validations_spec.rb +45 -0
  90. metadata +117 -6
  91. metadata.gz.sig +1 -0
@@ -0,0 +1,21 @@
1
+ ########################################################################
2
+ # HasProjects provides methods for a class to contain and query a set of projects
3
+ ########################################################################
4
+ module HasProjects
5
+ def projects
6
+ @_projects ||= {}
7
+ end
8
+
9
+ # Factory for creating projects
10
+ def create_project(org, name, &block)
11
+ # do not add the project a second time
12
+ repository = "#{org}/#{name}"
13
+ return projects[repository] if projects.key?(repository)
14
+
15
+ GeoEngineer::Project.new(org, name, self, &block)
16
+ end
17
+
18
+ def all_project_resources
19
+ projects.values.map(&:all_resources).flatten
20
+ end
21
+ end
@@ -21,9 +21,10 @@ module HasResources
21
21
  @_resources
22
22
  end
23
23
 
24
- # Overridden By Project and Environment
24
+ # Overridden By Template, Project and Environment,
25
+ # requires explicit override to avoid easy mistakes
25
26
  def all_resources
26
- resources
27
+ raise NotImplementedError, "Including class must override this method"
27
28
  end
28
29
 
29
30
  def find_resource(type, id)
@@ -37,8 +38,9 @@ module HasResources
37
38
  find_resource(type, name)
38
39
  end
39
40
 
40
- def resources_grouped_by
41
- all_resources.each_with_object({}) do |r, c|
41
+ # Returns: { value1: [ ], value2: [ ] }
42
+ def resources_grouped_by(resources_to_group = all_resources)
43
+ resources_to_group.each_with_object({}) do |r, c|
42
44
  value = yield r
43
45
  c[value] ||= []
44
46
  c[value] << r
@@ -46,6 +48,17 @@ module HasResources
46
48
  end
47
49
  end
48
50
 
51
+ # Returns: { type1: { value1: [ ] }, type2: { value2: [ ] } }
52
+ def resources_of_type_grouped_by(&block)
53
+ grouped = resources_grouped_by(all_resources, &:type)
54
+
55
+ grouped_arr = grouped.map do |type, grouped_resources|
56
+ [type, resources_grouped_by(grouped_resources, &block)]
57
+ end
58
+
59
+ grouped_arr.to_h
60
+ end
61
+
49
62
  def resources_of_type(type)
50
63
  all_resources.select { |r| r.type == type }
51
64
  end
@@ -0,0 +1,31 @@
1
+ ########################################################################
2
+ # HasTemplates provides methods for a class to contain and query a set of templates
3
+ ########################################################################
4
+ module HasTemplates
5
+ def templates
6
+ @_templates ||= {}
7
+ end
8
+
9
+ # Templating Methods
10
+ def find_template(type)
11
+ clazz_name = type.split('_').collect(&:capitalize).join
12
+ return Object.const_get(clazz_name) if Object.const_defined? clazz_name
13
+
14
+ module_clazz = "GeoEngineer::Templates::#{clazz_name}"
15
+ return Object.const_get(module_clazz) if Object.const_defined? module_clazz
16
+
17
+ throw "undefined template '#{type}' for '#{clazz_name}' or 'GeoEngineer::#{clazz_name}'"
18
+ end
19
+
20
+ def from_template(type, name, parameters = {}, &block)
21
+ throw "Template '#{name}' already defined" if templates[name]
22
+ clazz = find_template(type)
23
+ template = clazz.new(name, self, parameters)
24
+ template.instance_exec(*template.template_resources, &block) if block_given?
25
+ templates[name] = template
26
+ end
27
+
28
+ def all_template_resources
29
+ templates.values.map(&:all_resources).flatten
30
+ end
31
+ end
@@ -49,9 +49,24 @@ module HasValidations
49
49
  # Validates CIDR block format
50
50
  # Returns error when argument fails validation
51
51
  def validate_cidr_block(cidr_block)
52
- parsed_cidr = NetAddr::CIDR.create(cidr_block)
53
- return [parsed_cidr, nil]
52
+ return if NetAddr::CIDR.create(cidr_block)
54
53
  rescue NetAddr::ValidationError
55
- return [nil, "Bad cidr block \"#{cidr_block}\" #{for_resource}"]
54
+ return "Bad cidr block \"#{cidr_block}\" #{for_resource}"
55
+ end
56
+
57
+ # Validates that at least one of the specified attributes is present
58
+ def validate_at_least_one_present(attributes)
59
+ errs = []
60
+ present = attributes.select { |attribute| !self[attribute].nil? }.count
61
+ errs << "At least one of #{attributes.join(', ')} must be defined" unless present.positive?
62
+ errs
63
+ end
64
+
65
+ # Validates that ONLY one of the specified attributes is present
66
+ def validate_only_one_present(attributes)
67
+ errs = []
68
+ present = attributes.select { |attribute| !self[attribute].nil? }.count
69
+ errs << "Only one of #{attributes.join(', ')} can be defined" unless present == 1
70
+ errs
56
71
  end
57
72
  end
@@ -1,3 +1,3 @@
1
1
  module GeoEngineer
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -1,12 +1,15 @@
1
1
  require_relative './spec_helper'
2
2
 
3
- describe("GeoEngineer::Environment") do
3
+ describe GeoEngineer::Environment do
4
+ let(:env) do
5
+ GeoEngineer::Environment.new("test") {
6
+ region "us-west-1"
7
+ account_id 1
8
+ }
9
+ end
10
+
4
11
  describe 'validations' do
5
12
  it 'should have unique terrform id' do
6
- env = GeoEngineer::Environment.new("test") {
7
- region "us-west-1"
8
- account_id 1
9
- }
10
13
  env.resource('type', 'id1') {
11
14
  _terraform_id "tid"
12
15
  _geo_id 'gid1'
@@ -20,10 +23,6 @@ describe("GeoEngineer::Environment") do
20
23
  end
21
24
 
22
25
  it 'should have unique geo_id' do
23
- env = GeoEngineer::Environment.new("test") {
24
- region "us-west-1"
25
- account_id 1
26
- }
27
26
  env.resource('type', 'id1') {
28
27
  _terraform_id "tid1"
29
28
  _geo_id 'gid'
@@ -37,10 +36,6 @@ describe("GeoEngineer::Environment") do
37
36
  end
38
37
 
39
38
  it 'should have unique type and ids' do
40
- env = GeoEngineer::Environment.new("test") {
41
- region "us-west-1"
42
- account_id 1
43
- }
44
39
  env.resource('type', 'id1') {
45
40
  _terraform_id "tid1"
46
41
  _geo_id 'gid1'
@@ -62,10 +57,10 @@ describe("GeoEngineer::Environment") do
62
57
  end
63
58
  end
64
59
 
65
- env = GeoEngineer::Environment.new("test")
66
60
  env.resource('codified_resource', 'id1') {
67
61
  _terraform_id "geo_id1"
68
62
  }
63
+
69
64
  expect(env.codified_resources('codified_resource').length).to eq 1
70
65
  expect(env.uncodified_resources('codified_resource').length).to eq 1
71
66
  end
@@ -73,7 +68,6 @@ describe("GeoEngineer::Environment") do
73
68
 
74
69
  describe '#to_terraform_state' do
75
70
  it 'should return state of resources' do
76
- env = GeoEngineer::Environment.new("test")
77
71
  env.resource('type', 'id1') {
78
72
  _terraform_id "tid"
79
73
  _geo_id 'gid1'
@@ -85,7 +79,6 @@ describe("GeoEngineer::Environment") do
85
79
 
86
80
  describe '#to_terraform_json' do
87
81
  it 'should return terraform of all resources' do
88
- env = GeoEngineer::Environment.new("test")
89
82
  env.resource('type', 'id1') {
90
83
  _terraform_id "tid"
91
84
  _geo_id 'gid1'
@@ -97,7 +90,6 @@ describe("GeoEngineer::Environment") do
97
90
 
98
91
  describe '#project' do
99
92
  it 'should create a project with this as environment' do
100
- env = GeoEngineer::Environment.new("test")
101
93
  env.project("org", "name") {
102
94
  environments 'test'
103
95
  }
@@ -105,7 +97,6 @@ describe("GeoEngineer::Environment") do
105
97
  end
106
98
 
107
99
  it 'should only load projects in the environment' do
108
- env = GeoEngineer::Environment.new("test")
109
100
  p0 = env.project("org", "0") {
110
101
  environments 'test'
111
102
  }
@@ -121,7 +112,6 @@ describe("GeoEngineer::Environment") do
121
112
 
122
113
  describe '#all_resources' do
123
114
  it 'should include local and project resources (if project in env)' do
124
- env = GeoEngineer::Environment.new("test")
125
115
  env.resource('type', 'id0') { x 2 }
126
116
 
127
117
  p0 = env.project("org", "0") {
@@ -137,4 +127,35 @@ describe("GeoEngineer::Environment") do
137
127
  expect(env.all_resources.length).to eq 2
138
128
  end
139
129
  end
130
+
131
+ describe '::HasTemplates' do
132
+ let!(:example_template) do
133
+ class Example < GeoEngineer::Template
134
+ def initialize(name, parent, parameters = {})
135
+ super(name, parent, parameters)
136
+ resource('aws_vpc', 'example') {
137
+ cidr_block('10.123.0.0/16')
138
+ }
139
+ end
140
+ end
141
+ end
142
+
143
+ describe '#from_template' do
144
+ it 'allows environments to create resources from templates' do
145
+ expect {
146
+ env.from_template('example', 'example_template')
147
+ }.to_not raise_error
148
+ end
149
+
150
+ it 'includes template resources in #all_resources' do
151
+ env.from_template('example', 'example_template')
152
+ expect(env.all_resources.count).to eq(1)
153
+ end
154
+
155
+ it 'adds a reference to the environment on each resource created' do
156
+ env.from_template('example', 'example_template')
157
+ expect(env.all_resources.first.environment).to eq(env)
158
+ end
159
+ end
160
+ end
140
161
  end
@@ -50,8 +50,8 @@ describe("GeoEngineer::Project") do
50
50
  project = GeoEngineer::Project.new('org', "project_name", nil)
51
51
  temp1 = project.from_template('in_module_template', 'in')
52
52
  temp2 = project.from_template('out_module_template', 'out')
53
- expect(temp1.template_resources.length).to eq 0
54
- expect(temp2.template_resources.length).to eq 2
53
+ expect(temp1.resources.length).to eq 0
54
+ expect(temp2.resources.length).to eq 2
55
55
  end
56
56
 
57
57
  it 'should error if the template is not found' do
@@ -1,13 +1,13 @@
1
1
  require_relative './spec_helper'
2
2
 
3
+ class GeoEngineer::RemoteResources < GeoEngineer::Resource
4
+ def self._fetch_remote_resources
5
+ [{ _geo_id: "geo_id1" }, { _geo_id: "geo_id2" }, { _geo_id: "geo_id2" }]
6
+ end
7
+ end
8
+
3
9
  describe("GeoEngineer::Resource") do
4
10
  describe '#remote_resource' do
5
- class GeoEngineer::RemoteResources < GeoEngineer::Resource
6
- def self._fetch_remote_resources
7
- [{ _geo_id: "geo_id1" }, { _geo_id: "geo_id2" }, { _geo_id: "geo_id2" }]
8
- end
9
- end
10
-
11
11
  it 'should return a list of resources' do
12
12
  rem_res = GeoEngineer::RemoteResources.new('rem', 'id') {
13
13
  _geo_id "geo_id1"
@@ -153,6 +153,87 @@ describe("GeoEngineer::Resource") do
153
153
  end
154
154
  end
155
155
 
156
+ describe '#validate_tag_merge' do
157
+ it 'should combine resource and project tags' do
158
+ project = GeoEngineer::Project.new('org', 'project_name', 'test') {
159
+ tags {
160
+ a '1'
161
+ }
162
+ }
163
+ resource = project.resource('type', '1') {
164
+ tags {
165
+ d '4'
166
+ }
167
+ }
168
+ resource.merge_project_tags
169
+ expect(resource.tags.attributes).to eq({ 'a' => '1', 'd' => '4' })
170
+ end
171
+
172
+ it 'should give priority to resource tags' do
173
+ project = GeoEngineer::Project.new('org', 'project_name', 'test') {
174
+ tags {
175
+ a 'project_value'
176
+ }
177
+ }
178
+ resource = project.resource('type', '1') {
179
+ tags {
180
+ a 'resource_value'
181
+ }
182
+ }
183
+ resource.merge_project_tags
184
+ expect(resource.tags.attributes).to eq({ 'a' => 'resource_value' })
185
+ end
186
+
187
+ it 'should return project tags if there are no resource tags' do
188
+ project = GeoEngineer::Project.new('org', 'project_name', 'test') {
189
+ tags {
190
+ a '1'
191
+ b '2'
192
+ }
193
+ }
194
+ resource = project.resource('type', '1') {}
195
+ resource.merge_project_tags
196
+ expect(resource.tags.attributes).to eq({ 'a' => '1', 'b' => '2' })
197
+ end
198
+
199
+ it 'should return resource tags if there are no project tags' do
200
+ project = GeoEngineer::Project.new('org', 'project_name', 'test') {}
201
+ resource = project.resource('type', '1') {
202
+ tags {
203
+ c '3'
204
+ d '4'
205
+ }
206
+ }
207
+ resource.merge_project_tags
208
+ expect(resource.tags.attributes).to eq({ 'c' => '3', 'd' => '4' })
209
+ end
210
+ end
211
+
212
+ describe '#reset' do
213
+ let(:subject) do
214
+ GeoEngineer::RemoteResources.new('resource', 'id') {
215
+ tags {
216
+ Name "foo"
217
+ }
218
+ _geo_id -> { tags['Name'] }
219
+ }
220
+ end
221
+
222
+ it 'resets lazily computed attributes' do
223
+ expect(subject._geo_id).to eq('foo')
224
+ subject.tags['Name'] = 'bar'
225
+ subject.reset
226
+ expect(subject._geo_id).to eq('bar')
227
+ end
228
+
229
+ it 'resets remote resource' do
230
+ expect(subject.remote_resource).to be_nil
231
+ subject.tags['Name'] = "geo_id1"
232
+ subject.reset
233
+ expect(subject.remote_resource).to_not be_nil
234
+ end
235
+ end
236
+
156
237
  describe 'class method' do
157
238
  describe('#type_from_class_name') do
158
239
  it 'should return resource' do
@@ -0,0 +1,24 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe("GeoEngineer::Resources::AwsCustomerGateway") do
4
+ common_resource_tests(GeoEngineer::Resources::AwsCustomerGateway, 'aws_customer_gateway')
5
+ name_tag_geo_id_tests(GeoEngineer::Resources::AwsCustomerGateway)
6
+
7
+ describe "#_fetch_remote_resources" do
8
+ it 'should create list of hashes from returned AWS SDK' do
9
+ ec2 = AwsClients.ec2
10
+ stub = ec2.stub_data(
11
+ :describe_customer_gateways,
12
+ {
13
+ customer_gateways: [
14
+ { customer_gateway_id: 'name1', tags: [{ key: 'Name', value: 'one' }] },
15
+ { customer_gateway_id: 'name2', tags: [{ key: 'Name', value: 'two' }] }
16
+ ]
17
+ }
18
+ )
19
+ ec2.stub_responses(:describe_customer_gateways, stub)
20
+ remote_resources = GeoEngineer::Resources::AwsCustomerGateway._fetch_remote_resources
21
+ expect(remote_resources.length).to eq(2)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "GeoEngineer::Resources::AwsEip" do
4
+ let(:aws_client) { AwsClients.ec2 }
5
+
6
+ common_resource_tests(GeoEngineer::Resources::AwsEip, 'aws_eip')
7
+
8
+ describe '#_fetch_remote_resources' do
9
+ before do
10
+ aws_client.stub_responses(
11
+ :describe_addresses, {
12
+ addresses: [
13
+ { public_ip: '99.0.0.0', allocation_id: "eipalloc-xxxxxxxx" },
14
+ { public_ip: '99.0.0.1', allocation_id: "eipalloc-xxxxxxxy" }
15
+ ]
16
+ }
17
+ )
18
+ end
19
+
20
+ it 'should create an array of hashes from the AWS response' do
21
+ resources = GeoEngineer::Resources::AwsEip._fetch_remote_resources
22
+ expect(resources.count).to eql 2
23
+
24
+ test_eip = resources.first
25
+ expect(test_eip[:_terraform_id]).to eql "eipalloc-xxxxxxxx"
26
+ expect(test_eip[:_geo_id]).to eql "99.0.0.0"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "GeoEngineer::Resources::AwsIamGroupMembership" do
4
+ let(:aws_client) { AwsClients.iam }
5
+
6
+ let!(:iam_user) do
7
+ GeoEngineer::Resources::AwsIamUser.new('aws_iam_user', 'fake-iam-user') {
8
+ name 'fake-iam-user'
9
+ }
10
+ end
11
+
12
+ let!(:iam_group) do
13
+ GeoEngineer::Resources::AwsIamGroup.new('aws_iam_group', 'fake-iam-group') {
14
+ name 'fake-iam-group'
15
+ }
16
+ end
17
+
18
+ let(:iam_group_membership) do
19
+ group = iam_group
20
+ user = iam_user
21
+
22
+ GeoEngineer::Resources::AwsIamGroupMembership
23
+ .new('aws_iam_group_membership', 'fake-iam-group-membership') {
24
+ name 'fake-iam-group-membership'
25
+ _group group
26
+ users [user]
27
+ }
28
+ end
29
+
30
+ common_resource_tests(
31
+ GeoEngineer::Resources::AwsIamGroupMembership,
32
+ 'aws_iam_group_membership',
33
+ false
34
+ )
35
+
36
+ before do
37
+ aws_client.stub_responses(
38
+ :list_groups, {
39
+ 'groups': [
40
+ {
41
+ group_name: 'fake-iam-group',
42
+ path: '/',
43
+ arn: 'arn:aws:iam::aws:iam-group/xyv/FakeAwsARN',
44
+ create_date: Time.parse("2016-12-13 11:54:59 -0800"),
45
+ group_id: '12345'
46
+ }
47
+ ]
48
+ }
49
+ )
50
+
51
+ aws_client.stub_responses(
52
+ :get_group, {
53
+ 'group': {
54
+ group_name: 'fake-iam-group',
55
+ path: '/',
56
+ arn: 'arn:aws:iam::aws:iam-group/xyv/FakeAwsARN',
57
+ create_date: Time.parse("2016-12-13 11:54:59 -0800"),
58
+ group_id: '12345'
59
+ },
60
+ 'users': [
61
+ {
62
+ path: '/',
63
+ user_name: 'fake-iam-user',
64
+ user_id: '1234',
65
+ arn: 'arn:aws:iam::aws:iam-user/xyv/FakeAwsARN',
66
+ create_date: Time.parse("2016-12-14 11:54:59 -0800")
67
+ }
68
+ ]
69
+ }
70
+ )
71
+ end
72
+
73
+ describe '#remote_resource_params' do
74
+ it 'should create a hash of params for the remote resources' do
75
+ remote_resource_params = iam_group_membership.remote_resource_params
76
+
77
+ expect(remote_resource_params[:name]).to eql("fake-iam-group")
78
+ expect(remote_resource_params[:_terraform_id]).to eql("fake-iam-group-membership")
79
+ expect(remote_resource_params[:_geo_id]).to eql("fake-iam-group-membership")
80
+ expect(remote_resource_params[:users]).to eql(["fake-iam-user"])
81
+ end
82
+ end
83
+ end