geoengineer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +8 -6
  5. data/lib/geoengineer.rb +2 -0
  6. data/lib/geoengineer/cli/geo_cli.rb +1 -4
  7. data/lib/geoengineer/cli/terraform_commands.rb +4 -2
  8. data/lib/geoengineer/environment.rb +14 -1
  9. data/lib/geoengineer/provider.rb +38 -0
  10. data/lib/geoengineer/resource.rb +29 -15
  11. data/lib/geoengineer/resources/api_gateway/helpers.rb +107 -0
  12. data/lib/geoengineer/resources/aws_alb.rb +39 -0
  13. data/lib/geoengineer/resources/aws_alb_listener.rb +39 -0
  14. data/lib/geoengineer/resources/aws_alb_listener_rule.rb +42 -0
  15. data/lib/geoengineer/resources/aws_alb_target_group.rb +30 -0
  16. data/lib/geoengineer/resources/aws_api_gateway_account.rb +18 -0
  17. data/lib/geoengineer/resources/aws_api_gateway_api_key.rb +20 -0
  18. data/lib/geoengineer/resources/aws_api_gateway_authorizer.rb +20 -0
  19. data/lib/geoengineer/resources/aws_api_gateway_base_path_mapping.rb +20 -0
  20. data/lib/geoengineer/resources/aws_api_gateway_client_certificate.rb +24 -0
  21. data/lib/geoengineer/resources/aws_api_gateway_deployment.rb +65 -0
  22. data/lib/geoengineer/resources/aws_api_gateway_domain_name.rb +27 -0
  23. data/lib/geoengineer/resources/aws_api_gateway_integration.rb +58 -0
  24. data/lib/geoengineer/resources/aws_api_gateway_integration_response.rb +68 -0
  25. data/lib/geoengineer/resources/aws_api_gateway_method.rb +59 -0
  26. data/lib/geoengineer/resources/aws_api_gateway_method_response.rb +69 -0
  27. data/lib/geoengineer/resources/aws_api_gateway_model.rb +19 -0
  28. data/lib/geoengineer/resources/aws_api_gateway_resource.rb +47 -0
  29. data/lib/geoengineer/resources/aws_api_gateway_rest_api.rb +79 -0
  30. data/lib/geoengineer/resources/aws_api_gateway_usage_plan.rb +27 -0
  31. data/lib/geoengineer/resources/aws_cloudfront_distribution.rb +25 -0
  32. data/lib/geoengineer/resources/aws_cloudtrail.rb +2 -2
  33. data/lib/geoengineer/resources/aws_cloudwatch_event_rule.rb +12 -3
  34. data/lib/geoengineer/resources/aws_cloudwatch_event_target.rb +2 -2
  35. data/lib/geoengineer/resources/aws_cloudwatch_metric_alarm.rb +10 -8
  36. data/lib/geoengineer/resources/aws_customer_gateway.rb +4 -2
  37. data/lib/geoengineer/resources/aws_db_instance.rb +2 -2
  38. data/lib/geoengineer/resources/aws_db_parameter_group.rb +4 -2
  39. data/lib/geoengineer/resources/aws_dynamodb_table.rb +2 -2
  40. data/lib/geoengineer/resources/aws_eip.rb +2 -2
  41. data/lib/geoengineer/resources/aws_elasticache_cluster.rb +2 -2
  42. data/lib/geoengineer/resources/aws_elasticache_parameter_group.rb +2 -2
  43. data/lib/geoengineer/resources/aws_elasticache_replication_group.rb +2 -2
  44. data/lib/geoengineer/resources/aws_elasticache_subnet_group.rb +2 -2
  45. data/lib/geoengineer/resources/aws_elasticsearch_domain.rb +2 -2
  46. data/lib/geoengineer/resources/aws_elb.rb +4 -2
  47. data/lib/geoengineer/resources/aws_iam_account_password_policy.rb +2 -1
  48. data/lib/geoengineer/resources/aws_iam_group.rb +2 -2
  49. data/lib/geoengineer/resources/aws_iam_group_membership.rb +1 -1
  50. data/lib/geoengineer/resources/aws_iam_instance_profile.rb +3 -3
  51. data/lib/geoengineer/resources/aws_iam_policy.rb +6 -4
  52. data/lib/geoengineer/resources/aws_iam_policy_attachment.rb +1 -1
  53. data/lib/geoengineer/resources/aws_iam_role.rb +2 -2
  54. data/lib/geoengineer/resources/aws_iam_role_policy.rb +10 -9
  55. data/lib/geoengineer/resources/aws_iam_user.rb +4 -4
  56. data/lib/geoengineer/resources/aws_instance.rb +3 -3
  57. data/lib/geoengineer/resources/aws_internet_gateway.rb +3 -2
  58. data/lib/geoengineer/resources/aws_kinesis_stream.rb +4 -4
  59. data/lib/geoengineer/resources/aws_kms_key.rb +5 -3
  60. data/lib/geoengineer/resources/aws_lambda_alias.rb +7 -7
  61. data/lib/geoengineer/resources/aws_lambda_event_source_mapping.rb +2 -2
  62. data/lib/geoengineer/resources/aws_lambda_function.rb +2 -2
  63. data/lib/geoengineer/resources/aws_lambda_permission.rb +9 -8
  64. data/lib/geoengineer/resources/aws_lb_cookie_stickiness_policy.rb +47 -0
  65. data/lib/geoengineer/resources/aws_load_balancer_backend_server_policy.rb +2 -2
  66. data/lib/geoengineer/resources/aws_load_balancer_policy.rb +5 -5
  67. data/lib/geoengineer/resources/aws_main_route_table_association.rb +2 -2
  68. data/lib/geoengineer/resources/aws_nat_gateway.rb +2 -2
  69. data/lib/geoengineer/resources/aws_network_acl.rb +2 -2
  70. data/lib/geoengineer/resources/aws_network_acl_rule.rb +2 -2
  71. data/lib/geoengineer/resources/aws_proxy_protocol_policy.rb +1 -1
  72. data/lib/geoengineer/resources/aws_redshift_cluster.rb +2 -2
  73. data/lib/geoengineer/resources/aws_route.rb +2 -2
  74. data/lib/geoengineer/resources/aws_route53_record.rb +6 -6
  75. data/lib/geoengineer/resources/aws_route53_zone.rb +2 -2
  76. data/lib/geoengineer/resources/aws_route_table.rb +2 -2
  77. data/lib/geoengineer/resources/aws_route_table_association.rb +2 -2
  78. data/lib/geoengineer/resources/aws_s3_bucket.rb +2 -2
  79. data/lib/geoengineer/resources/aws_s3_bucket_notification.rb +38 -0
  80. data/lib/geoengineer/resources/aws_security_group.rb +2 -2
  81. data/lib/geoengineer/resources/aws_ses_receipt_rule.rb +2 -2
  82. data/lib/geoengineer/resources/aws_ses_receipt_rule_set.rb +2 -2
  83. data/lib/geoengineer/resources/aws_sns_topic.rb +2 -2
  84. data/lib/geoengineer/resources/aws_sns_topic_subscription.rb +5 -5
  85. data/lib/geoengineer/resources/aws_sqs_queue.rb +2 -2
  86. data/lib/geoengineer/resources/aws_subnet.rb +2 -2
  87. data/lib/geoengineer/resources/aws_vpc.rb +2 -2
  88. data/lib/geoengineer/resources/aws_vpc_dhcp_options.rb +2 -2
  89. data/lib/geoengineer/resources/aws_vpc_dhcp_options_association.rb +2 -2
  90. data/lib/geoengineer/resources/aws_vpc_endpoint.rb +2 -2
  91. data/lib/geoengineer/resources/aws_vpc_peering_connection.rb +2 -2
  92. data/lib/geoengineer/resources/aws_vpn_connection.rb +3 -2
  93. data/lib/geoengineer/resources/aws_vpn_connection_route.rb +2 -2
  94. data/lib/geoengineer/resources/aws_vpn_gateway.rb +2 -2
  95. data/lib/geoengineer/resources/aws_vpn_gateway_attachment.rb +2 -2
  96. data/lib/geoengineer/template.rb +3 -1
  97. data/lib/geoengineer/templates/json_rest_api.rb +197 -0
  98. data/lib/geoengineer/utils/aws_clients.rb +129 -38
  99. data/lib/geoengineer/utils/has_templates.rb +1 -1
  100. data/lib/geoengineer/version.rb +1 -1
  101. data/spec/environment_spec.rb +1 -1
  102. data/spec/resource_spec.rb +24 -10
  103. data/spec/resources/aws_alb_listener_rule_spec.rb +45 -0
  104. data/spec/resources/aws_alb_listener_spec.rb +33 -0
  105. data/spec/resources/aws_alb_spec.rb +33 -0
  106. data/spec/resources/aws_alb_target_group_spec.rb +35 -0
  107. data/spec/resources/aws_api_gateway_account_spec.rb +6 -0
  108. data/spec/resources/aws_api_gateway_api_key_spec.rb +6 -0
  109. data/spec/resources/aws_api_gateway_authorizer_spec.rb +6 -0
  110. data/spec/resources/aws_api_gateway_base_path_mapping_spec.rb +6 -0
  111. data/spec/resources/aws_api_gateway_client_certificate_spec.rb +6 -0
  112. data/spec/resources/aws_api_gateway_deployment_spec.rb +6 -0
  113. data/spec/resources/aws_api_gateway_domain_name_spec.rb +6 -0
  114. data/spec/resources/aws_api_gateway_integration_response_spec.rb +6 -0
  115. data/spec/resources/aws_api_gateway_integration_spec.rb +6 -0
  116. data/spec/resources/aws_api_gateway_method_response_spec.rb +6 -0
  117. data/spec/resources/aws_api_gateway_method_spec.rb +6 -0
  118. data/spec/resources/aws_api_gateway_model_spec.rb +6 -0
  119. data/spec/resources/aws_api_gateway_resource_spec.rb +6 -0
  120. data/spec/resources/aws_api_gateway_rest_api_spec.rb +6 -0
  121. data/spec/resources/aws_cloudfront_distribution_spec.rb +50 -0
  122. data/spec/resources/aws_cloudtrail_spec.rb +3 -3
  123. data/spec/resources/aws_cloudwatch_event_rule_spec.rb +3 -3
  124. data/spec/resources/aws_cloudwatch_event_target_spec.rb +4 -6
  125. data/spec/resources/aws_cloudwatch_metric_alarm_spec.rb +3 -6
  126. data/spec/resources/aws_customer_gateway_spec.rb +4 -3
  127. data/spec/resources/aws_db_instance_spec.rb +3 -3
  128. data/spec/resources/aws_db_parameter_group_spec.rb +3 -3
  129. data/spec/resources/aws_dynamodb_table_spec.rb +3 -3
  130. data/spec/resources/aws_eip_spec.rb +3 -3
  131. data/spec/resources/aws_elasticache_replication_group_spec.rb +3 -6
  132. data/spec/resources/aws_elasticache_subnet_group_spec.rb +4 -6
  133. data/spec/resources/aws_elasticcache_cluster_spec.rb +3 -3
  134. data/spec/resources/aws_elasticcache_parameter_group_spec.rb +3 -6
  135. data/spec/resources/aws_elasticsearch_domain_spec.rb +3 -3
  136. data/spec/resources/aws_elb_spec.rb +3 -3
  137. data/spec/resources/aws_iam_account_password_policy_spec.rb +2 -6
  138. data/spec/resources/aws_iam_group_membership_spec.rb +2 -6
  139. data/spec/resources/aws_iam_group_spec.rb +3 -3
  140. data/spec/resources/aws_iam_instance_profile_spec.rb +3 -6
  141. data/spec/resources/aws_iam_policy_attachment_spec.rb +2 -6
  142. data/spec/resources/aws_iam_policy_spec.rb +3 -5
  143. data/spec/resources/aws_iam_role_spec.rb +3 -4
  144. data/spec/resources/aws_iam_rule_policy_spec.rb +2 -5
  145. data/spec/resources/aws_iam_user_spec.rb +3 -4
  146. data/spec/resources/aws_instance_spec.rb +3 -3
  147. data/spec/resources/aws_internet_gateway_spec.rb +3 -3
  148. data/spec/resources/aws_kinesis_stream_spec.rb +3 -4
  149. data/spec/resources/aws_kms_key_spec.rb +3 -3
  150. data/spec/resources/aws_lambda_alias_spec.rb +2 -3
  151. data/spec/resources/aws_lambda_event_source_mapping_spec.rb +2 -5
  152. data/spec/resources/aws_lambda_function_spec.rb +3 -4
  153. data/spec/resources/aws_lambda_permission_spec.rb +1 -1
  154. data/spec/resources/aws_lb_cookie_stickiness_policy_spec.rb +38 -0
  155. data/spec/resources/aws_load_balancer_backend_server_policy_spec.rb +2 -3
  156. data/spec/resources/aws_load_balancer_policy_spec.rb +3 -4
  157. data/spec/resources/aws_main_route_table_association_spec.rb +2 -5
  158. data/spec/resources/aws_nat_gateway_spec.rb +3 -4
  159. data/spec/resources/aws_network_acl_rule_spec.rb +2 -3
  160. data/spec/resources/aws_network_acl_spec.rb +3 -3
  161. data/spec/resources/aws_proxy_protocol_policy_spec.rb +2 -2
  162. data/spec/resources/aws_redshift_cluster_spec.rb +3 -3
  163. data/spec/resources/aws_route53_record_spec.rb +3 -4
  164. data/spec/resources/aws_route53_zone_spec.rb +3 -4
  165. data/spec/resources/aws_route_spec.rb +3 -6
  166. data/spec/resources/aws_route_table_association_spec.rb +4 -6
  167. data/spec/resources/aws_route_table_spec.rb +3 -3
  168. data/spec/resources/aws_s3_bucket_notification_spec.rb +4 -0
  169. data/spec/resources/aws_s3_bucket_spec.rb +3 -3
  170. data/spec/resources/aws_security_group_spec.rb +5 -5
  171. data/spec/resources/aws_ses_receipt_rule_set_spec.rb +3 -4
  172. data/spec/resources/aws_ses_receipt_rule_spec.rb +3 -4
  173. data/spec/resources/aws_sns_topic_spec.rb +10 -6
  174. data/spec/resources/aws_sns_topic_subscription_spec.rb +8 -7
  175. data/spec/resources/aws_sqs_queue_spec.rb +3 -3
  176. data/spec/resources/aws_subnet_spec.rb +3 -3
  177. data/spec/resources/aws_vpc_dhcp_options_association_spec.rb +3 -6
  178. data/spec/resources/aws_vpc_dhcp_options_spec.rb +3 -3
  179. data/spec/resources/aws_vpc_endpoint_spec.rb +3 -6
  180. data/spec/resources/aws_vpc_peering_connection_spec.rb +4 -6
  181. data/spec/resources/aws_vpc_spec.rb +3 -3
  182. data/spec/resources/aws_vpn_connection_route_spec.rb +3 -6
  183. data/spec/resources/aws_vpn_connection_spec.rb +3 -3
  184. data/spec/resources/aws_vpn_gateway_attachment_spec.rb +4 -6
  185. data/spec/resources/aws_vpn_gateway_spec.rb +3 -3
  186. data/spec/spec_helper.rb +3 -1
  187. data/spec/support/normalize_indent.rb +12 -0
  188. metadata +92 -22
  189. metadata.gz.sig +0 -0
@@ -0,0 +1,19 @@
1
+ require_relative "./api_gateway/helpers"
2
+
3
+ ########################################################################
4
+ # AwsCloudTrail is the +api_gatewat_rest_api+ terrform resource,
5
+ #
6
+ # {https://www.terraform.io/docs/providers/aws/r/api_gateway_model.html}
7
+ ########################################################################
8
+ class GeoEngineer::Resources::AwsApiGatewayModel < GeoEngineer::Resource
9
+ include GeoEngineer::ApiGatewayHelpers
10
+
11
+ validate -> { validate_required_attributes([:rest_api_id, :name, :content_type, :schema]) }
12
+
13
+ after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
14
+ after :initialize, -> { _geo_id -> { rand(36**20).to_s(36) } }
15
+
16
+ def support_tags?
17
+ false
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "./api_gateway/helpers"
2
+
3
+ ########################################################################
4
+ # AwsCloudTrail is the +api_gatewat_rest_api+ terrform resource,
5
+ #
6
+ # {https://www.terraform.io/docs/providers/aws/r/api_gateway_resource.html}
7
+ ########################################################################
8
+ class GeoEngineer::Resources::AwsApiGatewayResource < GeoEngineer::Resource
9
+ include GeoEngineer::ApiGatewayHelpers
10
+
11
+ # The Rest API resource object and the parent resource object must be passed
12
+ validate -> { validate_required_attributes([:rest_api_id, :parent_id, :path_part]) }
13
+
14
+ after :initialize, -> { self.rest_api_id = _rest_api.to_ref }
15
+ after :initialize, -> { _rest_api.api_resources[self.type][self.id] = self }
16
+
17
+ # Parent is a resource (the default being the root resource of the rest_api '/')
18
+ # At the moment we only support rest_api being the root resource
19
+ after :initialize, -> { self.parent_id = _rest_api.to_ref("root_resource_id") }
20
+
21
+ after :initialize, -> { depends_on [_rest_api.terraform_name] }
22
+
23
+ after :initialize, -> { _geo_id -> { "#{_rest_api._geo_id}::#{path_part}" } }
24
+
25
+ after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
26
+ after :initialize, -> { _id -> { _terraform_id } }
27
+
28
+ def to_terraform_state
29
+ tfstate = super
30
+ tfstate[:primary][:attributes] = {
31
+ "rest_api_id" => _rest_api._terraform_id
32
+ }
33
+ tfstate
34
+ end
35
+
36
+ def support_tags?
37
+ false
38
+ end
39
+
40
+ def self._fetch_remote_resources(provider)
41
+ rest_api_resources = []
42
+ _remote_rest_api_resource(provider) do |rr, res|
43
+ rest_api_resources << res
44
+ end
45
+ rest_api_resources
46
+ end
47
+ end
@@ -0,0 +1,79 @@
1
+ require_relative "./api_gateway/helpers"
2
+
3
+ ########################################################################
4
+ # AwsCloudTrail is the +api_gatewat_rest_api+ terrform resource,
5
+ #
6
+ # {https://www.terraform.io/docs/providers/aws/r/api_gateway_rest_api.html}
7
+ ########################################################################
8
+ class GeoEngineer::Resources::AwsApiGatewayRestApi < GeoEngineer::Resource
9
+ include GeoEngineer::ApiGatewayHelpers
10
+
11
+ # Validations
12
+ validate -> { validate_required_attributes([:name]) }
13
+
14
+ after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
15
+ after :initialize, -> { _geo_id -> { name } }
16
+
17
+ # API Resource Methods
18
+ attr_accessor :api_resources
19
+ after :initialize, :initialize_children_resources
20
+
21
+ def initialize_children_resources
22
+ # { <class_name> : { <resource_id> : <resource>}
23
+ @api_resources = {
24
+ "aws_api_gateway_authorizer" => {},
25
+ "aws_api_gateway_base_path_mapping" => {},
26
+ "aws_api_gateway_deployment" => {},
27
+ "aws_api_gateway_integration" => {},
28
+ "aws_api_gateway_integration_response" => {},
29
+ "aws_api_gateway_method" => {},
30
+ "aws_api_gateway_method_response" => {},
31
+ "aws_api_gateway_model" => {},
32
+ "aws_api_gateway_resource" => {}
33
+ }
34
+ end
35
+
36
+ def all_api_resources
37
+ [self, @api_resources.values.map(&:values)].flatten
38
+ end
39
+
40
+ def all_core_api_resources
41
+ [
42
+ self,
43
+ @api_resources["aws_api_gateway_integration"].values,
44
+ @api_resources["aws_api_gateway_integration_response"].values,
45
+ @api_resources["aws_api_gateway_method"].values,
46
+ @api_resources["aws_api_gateway_method_response"].values,
47
+ @api_resources["aws_api_gateway_model"].values,
48
+ @api_resources["aws_api_gateway_resource"].values
49
+ ].flatten
50
+ end
51
+
52
+ # End of API Resource Methods
53
+ def support_tags?
54
+ false
55
+ end
56
+
57
+ def root_resource_id
58
+ NullObject.maybe(remote_resource).root_resource_id
59
+ end
60
+
61
+ def to_terraform_state
62
+ tfstate = super
63
+ tfstate[:primary][:attributes] = {
64
+ "root_resource_id" => root_resource_id
65
+ }
66
+ tfstate
67
+ end
68
+
69
+ # This method will tag for deletion all remote resources that are not codeified
70
+ def delete_uncodified_children_resoures
71
+ # Find all remote resources for this rest_api
72
+ # Compare with api_resources hash
73
+ # create resource in project tagged with deletion (this will only add them to tfstate)
74
+ end
75
+
76
+ def self._fetch_remote_resources(provider)
77
+ _fetch_remote_rest_apis(provider)
78
+ end
79
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "./api_gateway/helpers"
2
+
3
+ ########################################################################
4
+ # AwsCloudTrail is the +api_gatewat_rest_api+ terrform resource,
5
+ #
6
+ # {https://www.terraform.io/docs/providers/aws/r/api_gateway_usage_plan.html}
7
+ ########################################################################
8
+ class GeoEngineer::Resources::AwsApiGatewayUsagePlan < GeoEngineer::Resource
9
+ include GeoEngineer::ApiGatewayHelpers
10
+
11
+ validate -> { validate_required_attributes([:name, :description]) }
12
+
13
+ after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
14
+ after :initialize, -> { _geo_id -> { name } }
15
+
16
+ def support_tags?
17
+ false
18
+ end
19
+
20
+ def self._fetch_remote_resources(provider)
21
+ AwsClients.api_gateway(provider).get_usage_plans['items'].map(&:to_h).map do |api|
22
+ api[:_terraform_id] = api[:id]
23
+ api[:_geo_id] = api[:name]
24
+ api
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ ########################################################################
2
+ # AwsCloudfrontDistribution is the +aws_cloudfront_distribution+
3
+ # terraform resource,
4
+ #
5
+ # {https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html}
6
+ ########################################################################
7
+ class GeoEngineer::Resources::AwsCloudfrontDistribution < GeoEngineer::Resource
8
+ after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
9
+ after :initialize, -> { _geo_id -> { comment } }
10
+ after :initialize, -> { _arn -> { NullObject.maybe(remote_resource)._arn } }
11
+
12
+ def self._fetch_remote_resources(provider)
13
+ AwsClients.cloudfront(provider).list_distributions[:distribution_list][:items].map do |item|
14
+ item.to_h.tap do |i|
15
+ i[:_terraform_id] = item.id
16
+ i[:_arn] = item.arn
17
+ i[:_geo_id] = item[:comment]
18
+ end
19
+ end
20
+ end
21
+
22
+ def support_tags?
23
+ true
24
+ end
25
+ end
@@ -8,8 +8,8 @@ class GeoEngineer::Resources::AwsCloudtrail < GeoEngineer::Resource
8
8
 
9
9
  after :initialize, -> { _terraform_id -> { name } }
10
10
 
11
- def self._fetch_remote_resources
12
- cloudtrails = AwsClients.cloudtrail.describe_trails["trail_list"].map(&:to_h)
11
+ def self._fetch_remote_resources(provider)
12
+ cloudtrails = AwsClients.cloudtrail(provider).describe_trails["trail_list"].map(&:to_h)
13
13
 
14
14
  cloudtrails.map do |ct|
15
15
  ct[:_terraform_id] = ct[:name]
@@ -4,7 +4,14 @@
4
4
  # {https://www.terraform.io/docs/providers/aws/r/cloudwatch_event_rule.html Terraform Docs}
5
5
  ########################################################################
6
6
  class GeoEngineer::Resources::AwsCloudwatchEventRule < GeoEngineer::Resource
7
- validate -> { validate_required_attributes([:name, :schedule_expression]) }
7
+ validate -> { validate_required_attributes([:name]) }
8
+ validate -> { validate_schedule_or_event }
9
+
10
+ def validate_schedule_or_event
11
+ return if !self[:schedule_expression] && self[:event_pattern]
12
+ return if self[:schedule_expression] && !self[:event_pattern]
13
+ ["#{self.id}: Need either schedule_expression or event_pattern defined"]
14
+ end
8
15
 
9
16
  after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
10
17
  after :initialize, -> { _geo_id -> { self[:name] } }
@@ -13,8 +20,10 @@ class GeoEngineer::Resources::AwsCloudwatchEventRule < GeoEngineer::Resource
13
20
  false
14
21
  end
15
22
 
16
- def self._fetch_remote_resources
17
- AwsClients.cloudwatchevents.list_rules.rules.map(&:to_h).map do |cloudwatch_event_rule|
23
+ def self._fetch_remote_resources(provider)
24
+ AwsClients
25
+ .cloudwatchevents(provider)
26
+ .list_rules.rules.map(&:to_h).map do |cloudwatch_event_rule|
18
27
  cloudwatch_event_rule.merge(
19
28
  {
20
29
  _terraform_id: cloudwatch_event_rule[:name],
@@ -22,9 +22,9 @@ class GeoEngineer::Resources::AwsCloudwatchEventTarget < GeoEngineer::Resource
22
22
  false
23
23
  end
24
24
 
25
- def self._fetch_remote_resources
25
+ def self._fetch_remote_resources(provider)
26
26
  AwsClients
27
- .cloudwatchevents
27
+ .cloudwatchevents(provider)
28
28
  .list_rules
29
29
  .rules
30
30
  .map(&:to_h)
@@ -23,8 +23,8 @@ class GeoEngineer::Resources::AwsCloudwatchMetricAlarm < GeoEngineer::Resource
23
23
  false
24
24
  end
25
25
 
26
- def self._fetch_remote_resources
27
- _get_all_alarms.map { |alarm|
26
+ def self._fetch_remote_resources(provider)
27
+ _get_all_alarms(provider).map { |alarm|
28
28
  {
29
29
  _terraform_id: alarm[:alarm_name],
30
30
  _geo_id: alarm[:alarm_name],
@@ -33,14 +33,16 @@ class GeoEngineer::Resources::AwsCloudwatchMetricAlarm < GeoEngineer::Resource
33
33
  }
34
34
  end
35
35
 
36
- def self._get_all_alarms
37
- alarm_page = AwsClients.cloudwatch.describe_alarms({ max_records: 100 })
36
+ def self._get_all_alarms(provider)
37
+ alarm_page = AwsClients.cloudwatch(provider).describe_alarms({ max_records: 100 })
38
38
  alarms = alarm_page.metric_alarms.map(&:to_h)
39
39
  while alarm_page.next_token
40
- alarm_page = AwsClients.cloudwatch.describe_alarms({
41
- max_records: 100,
42
- next_token: alarm_page.next_token
43
- })
40
+ alarm_page = AwsClients
41
+ .cloudwatch(provider)
42
+ .describe_alarms({
43
+ max_records: 100,
44
+ next_token: alarm_page.next_token
45
+ })
44
46
  alarms.concat alarm_page.metric_alarms.map(&:to_h)
45
47
  end
46
48
  alarms
@@ -10,8 +10,10 @@ class GeoEngineer::Resources::AwsCustomerGateway < GeoEngineer::Resource
10
10
  after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
11
11
  after :initialize, -> { _geo_id -> { NullObject.maybe(tags)[:Name] } }
12
12
 
13
- def self._fetch_remote_resources
14
- AwsClients.ec2.describe_customer_gateways['customer_gateways'].map(&:to_h).map do |gateway|
13
+ def self._fetch_remote_resources(provider)
14
+ AwsClients.ec2(provider)
15
+ .describe_customer_gateways['customer_gateways']
16
+ .map(&:to_h).map do |gateway|
15
17
  gateway.merge(
16
18
  {
17
19
  _terraform_id: gateway[:customer_gateway_id],
@@ -39,8 +39,8 @@ class GeoEngineer::Resources::AwsDbInstance < GeoEngineer::Resource
39
39
  "db"
40
40
  end
41
41
 
42
- def self._fetch_remote_resources
43
- AwsClients.rds.describe_db_instances['db_instances'].map(&:to_h).map do |rds|
42
+ def self._fetch_remote_resources(provider)
43
+ AwsClients.rds(provider).describe_db_instances['db_instances'].map(&:to_h).map do |rds|
44
44
  rds[:_terraform_id] = rds[:db_instance_identifier]
45
45
  rds[:_geo_id] = rds[:db_instance_identifier]
46
46
  rds[:identifier] = rds[:db_instance_identifier]
@@ -14,8 +14,10 @@ class GeoEngineer::Resources::AwsDbParameterGroup < GeoEngineer::Resource
14
14
  "dbpg"
15
15
  end
16
16
 
17
- def self._fetch_remote_resources
18
- AwsClients.rds.describe_db_parameter_groups['db_parameter_groups'].map(&:to_h).map do |pg|
17
+ def self._fetch_remote_resources(provider)
18
+ AwsClients.rds(provider)
19
+ .describe_db_parameter_groups['db_parameter_groups']
20
+ .map(&:to_h).map do |pg|
19
21
  pg[:_terraform_id] = pg[:db_parameter_group_name]
20
22
  pg[:_geo_id] = pg[:db_parameter_group_name]
21
23
  pg[:name] = pg[:db_parameter_group_name]
@@ -12,8 +12,8 @@ class GeoEngineer::Resources::AwsDynamodbTable < GeoEngineer::Resource
12
12
  false
13
13
  end
14
14
 
15
- def self._fetch_remote_resources
16
- AwsClients.dynamo.list_tables['table_names'].map { |name|
15
+ def self._fetch_remote_resources(provider)
16
+ AwsClients.dynamo(provider).list_tables['table_names'].map { |name|
17
17
  {
18
18
  name: name,
19
19
  _geo_id: name,
@@ -33,8 +33,8 @@ class GeoEngineer::Resources::AwsEip < GeoEngineer::Resource
33
33
  true
34
34
  end
35
35
 
36
- def self._fetch_remote_resources
37
- AwsClients.ec2.describe_addresses['addresses'].map(&:to_h).map do |address|
36
+ def self._fetch_remote_resources(provider)
37
+ AwsClients.ec2(provider).describe_addresses['addresses'].map(&:to_h).map do |address|
38
38
  address[:_terraform_id] = address[:allocation_id]
39
39
  address[:_geo_id] = address[:public_ip]
40
40
  address
@@ -45,9 +45,9 @@ class GeoEngineer::Resources::AwsElasticacheCluster < GeoEngineer::Resource
45
45
  "ec"
46
46
  end
47
47
 
48
- def self._fetch_remote_resources
48
+ def self._fetch_remote_resources(provider)
49
49
  AwsClients
50
- .elasticache
50
+ .elasticache(provider)
51
51
  .describe_cache_clusters['cache_clusters']
52
52
  .map(&:to_h)
53
53
  .select { |ec| ec[:replication_group_id].nil? }
@@ -18,8 +18,8 @@ class GeoEngineer::Resources::AwsElasticacheParameterGroup < GeoEngineer::Resour
18
18
  "ecpg"
19
19
  end
20
20
 
21
- def self._fetch_remote_resources
22
- ec = AwsClients.elasticache
21
+ def self._fetch_remote_resources(provider)
22
+ ec = AwsClients.elasticache(provider)
23
23
  ec.describe_cache_parameter_groups['cache_parameter_groups'].map(&:to_h).map do |pg|
24
24
  pg[:_terraform_id] = pg[:cache_parameter_group_name]
25
25
  pg[:_geo_id] = pg[:cache_parameter_group_name]
@@ -33,8 +33,8 @@ class GeoEngineer::Resources::AwsElasticacheReplicationGroup < GeoEngineer::Reso
33
33
  tfstate
34
34
  end
35
35
 
36
- def self._fetch_remote_resources
37
- ec = AwsClients.elasticache
36
+ def self._fetch_remote_resources(provider)
37
+ ec = AwsClients.elasticache(provider)
38
38
  ec.describe_replication_groups['replication_groups'].map(&:to_h).map do |rg|
39
39
  rg[:_terraform_id] = rg[:replication_group_id]
40
40
  rg[:_geo_id] = rg[:replication_group_id]
@@ -12,8 +12,8 @@ class GeoEngineer::Resources::AwsElasticacheSubnetGroup < GeoEngineer::Resource
12
12
  false
13
13
  end
14
14
 
15
- def self._fetch_remote_resources
16
- cache_subnet_groups = AwsClients.elasticache.describe_cache_subnet_groups
15
+ def self._fetch_remote_resources(provider)
16
+ cache_subnet_groups = AwsClients.elasticache(provider).describe_cache_subnet_groups
17
17
 
18
18
  cache_subnet_groups['cache_subnet_groups'].map(&:to_h).map do |csg|
19
19
  csg[:name] = csg[:cache_subnet_group_name]
@@ -26,8 +26,8 @@ class GeoEngineer::Resources::AwsElasticsearchDomain < GeoEngineer::Resource
26
26
  "es"
27
27
  end
28
28
 
29
- def self._fetch_remote_resources
30
- AwsClients.elasticsearch.list_domain_names['domain_names'].map(&:to_h).map do |esd|
29
+ def self._fetch_remote_resources(provider)
30
+ AwsClients.elasticsearch(provider).list_domain_names['domain_names'].map(&:to_h).map do |esd|
31
31
  esd[:_geo_id] = esd[:domain_name]
32
32
  esd
33
33
  end
@@ -46,8 +46,10 @@ class GeoEngineer::Resources::AwsElb < GeoEngineer::Resource
46
46
  "elb"
47
47
  end
48
48
 
49
- def self._fetch_remote_resources
50
- AwsClients.elb.describe_load_balancers['load_balancer_descriptions'].map(&:to_h).map do |elb|
49
+ def self._fetch_remote_resources(provider)
50
+ AwsClients.elb(provider)
51
+ .describe_load_balancers['load_balancer_descriptions']
52
+ .map(&:to_h).map do |elb|
51
53
  elb[:_terraform_id] = elb[:load_balancer_name]
52
54
  elb[:_geo_id] = elb[:load_balancer_name]
53
55
  elb[:name] = elb[:load_balancer_name]
@@ -24,7 +24,8 @@ class GeoEngineer::Resources::AwsIamAccountPasswordPolicy < GeoEngineer::Resourc
24
24
  end
25
25
 
26
26
  def remote_resource_params
27
- password_policy = AwsClients.iam.get_account_password_policy.password_policy.to_h
27
+ password_policy = AwsClients.iam(fetch_provider)
28
+ .get_account_password_policy.password_policy.to_h
28
29
  password_policy.merge({ _geo_id: SINGLETON_ID, _terraform_id: SINGLETON_ID })
29
30
  rescue Aws::IAM::Errors::NoSuchEntity
30
31
  {}
@@ -13,8 +13,8 @@ class GeoEngineer::Resources::AwsIamGroup < GeoEngineer::Resource
13
13
  false
14
14
  end
15
15
 
16
- def self._fetch_remote_resources
17
- groups = AwsClients.iam.list_groups['groups'].map(&:to_h)
16
+ def self._fetch_remote_resources(provider)
17
+ groups = AwsClients.iam(provider).list_groups['groups'].map(&:to_h)
18
18
 
19
19
  groups.map do |g|
20
20
  g[:name] = g[:group_name]