geoengineer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +5 -0
- data.tar.gz.sig +0 -0
- data/README.md +5 -5
- data/lib/geoengineer/cli/geo_cli.rb +4 -5
- data/lib/geoengineer/cli/status_command.rb +7 -1
- data/lib/geoengineer/environment.rb +53 -51
- data/lib/geoengineer/project.rb +5 -24
- data/lib/geoengineer/resource.rb +89 -20
- data/lib/geoengineer/resources/aws_customer_gateway.rb +23 -0
- data/lib/geoengineer/resources/aws_eip.rb +43 -0
- data/lib/geoengineer/resources/aws_iam_group.rb +26 -0
- data/lib/geoengineer/resources/aws_iam_group_membership.rb +50 -0
- data/lib/geoengineer/resources/aws_iam_policy.rb +12 -4
- data/lib/geoengineer/resources/aws_iam_policy_attachment.rb +95 -0
- data/lib/geoengineer/resources/aws_iam_role.rb +45 -0
- data/lib/geoengineer/resources/aws_instance.rb +7 -4
- data/lib/geoengineer/resources/aws_internet_gateway.rb +23 -0
- data/lib/geoengineer/resources/aws_lambda_alias.rb +50 -0
- data/lib/geoengineer/resources/aws_lambda_event_source_mapping.rb +47 -0
- data/lib/geoengineer/resources/aws_lambda_function.rb +30 -0
- data/lib/geoengineer/resources/aws_lambda_permission.rb +74 -0
- data/lib/geoengineer/resources/aws_main_route_table_association.rb +51 -0
- data/lib/geoengineer/resources/aws_nat_gateway.rb +29 -0
- data/lib/geoengineer/resources/aws_network_acl.rb +38 -0
- data/lib/geoengineer/resources/aws_network_acl_rule.rb +50 -0
- data/lib/geoengineer/resources/aws_route.rb +47 -0
- data/lib/geoengineer/resources/aws_route53_record.rb +4 -0
- data/lib/geoengineer/resources/aws_route_table.rb +26 -0
- data/lib/geoengineer/resources/aws_route_table_association.rb +45 -0
- data/lib/geoengineer/resources/aws_security_group.rb +8 -5
- data/lib/geoengineer/resources/aws_subnet.rb +24 -0
- data/lib/geoengineer/resources/aws_vpc.rb +24 -0
- data/lib/geoengineer/resources/aws_vpc_dhcp_options.rb +29 -0
- data/lib/geoengineer/resources/aws_vpc_dhcp_options_association.rb +40 -0
- data/lib/geoengineer/resources/aws_vpc_endpoint.rb +26 -0
- data/lib/geoengineer/resources/aws_vpc_peering_connection.rb +29 -0
- data/lib/geoengineer/resources/aws_vpn_connection.rb +23 -0
- data/lib/geoengineer/resources/aws_vpn_connection_route.rb +35 -0
- data/lib/geoengineer/resources/aws_vpn_gateway.rb +22 -0
- data/lib/geoengineer/resources/aws_vpn_gateway_attachment.rb +41 -0
- data/lib/geoengineer/template.rb +20 -4
- data/lib/geoengineer/utils/aws_clients.rb +4 -0
- data/lib/geoengineer/utils/crc32.rb +61 -0
- data/lib/geoengineer/utils/has_attributes.rb +25 -11
- data/lib/geoengineer/utils/has_projects.rb +21 -0
- data/lib/geoengineer/utils/has_resources.rb +17 -4
- data/lib/geoengineer/utils/has_templates.rb +31 -0
- data/lib/geoengineer/utils/has_validations.rb +18 -3
- data/lib/geoengineer/version.rb +1 -1
- data/spec/environment_spec.rb +40 -19
- data/spec/project_spec.rb +2 -2
- data/spec/resource_spec.rb +87 -6
- data/spec/resources/aws_customer_gateway_spec.rb +24 -0
- data/spec/resources/aws_eip_spec.rb +29 -0
- data/spec/resources/aws_iam_group_membership_spec.rb +83 -0
- data/spec/resources/aws_iam_group_spec.rb +43 -0
- data/spec/resources/aws_iam_policy_attachment_spec.rb +80 -0
- data/spec/resources/{aws_iam_policy.rb → aws_iam_policy_spec.rb} +6 -5
- data/spec/resources/aws_iam_role_spec.rb +45 -0
- data/spec/resources/aws_internet_gateway_spec.rb +24 -0
- data/spec/resources/aws_lambda_alias_spec.rb +39 -0
- data/spec/resources/aws_lambda_event_source_mapping_spec.rb +53 -0
- data/spec/resources/aws_lambda_function_spec.rb +29 -0
- data/spec/resources/aws_lambda_permission_spec.rb +90 -0
- data/spec/resources/aws_main_route_table_association_spec.rb +57 -0
- data/spec/resources/aws_nat_gateway_spec.rb +31 -0
- data/spec/resources/aws_network_acl_rule_spec.rb +73 -0
- data/spec/resources/aws_network_acl_spec.rb +31 -0
- data/spec/resources/aws_route53_record_spec.rb +5 -0
- data/spec/resources/aws_route_spec.rb +47 -0
- data/spec/resources/aws_route_table_association_spec.rb +47 -0
- data/spec/resources/aws_route_table_spec.rb +24 -0
- data/spec/resources/aws_security_group_spec.rb +36 -2
- data/spec/resources/aws_subnet_spec.rb +24 -0
- data/spec/resources/aws_vpc_dhcp_options_association_spec.rb +43 -0
- data/spec/resources/aws_vpc_dhcp_options_spec.rb +24 -0
- data/spec/resources/aws_vpc_endpoint_spec.rb +41 -0
- data/spec/resources/aws_vpc_peering_connection_spec.rb +33 -0
- data/spec/resources/aws_vpc_spec.rb +24 -0
- data/spec/resources/aws_vpn_connection_route_spec.rb +43 -0
- data/spec/resources/aws_vpn_connection_spec.rb +41 -0
- data/spec/resources/aws_vpn_gateway_attachment_spec.rb +41 -0
- data/spec/resources/aws_vpn_gateway_spec.rb +39 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/utils/crc32_spec.rb +14 -0
- data/spec/utils/has_attributes_spec.rb +22 -0
- data/spec/utils/has_resources_spec.rb +4 -0
- data/spec/utils/has_validations_spec.rb +45 -0
- metadata +117 -6
- metadata.gz.sig +1 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsCustomerGateway is the +aws_customer_gateway+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/customer_gateway.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsCustomerGateway < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:bgp_asn, :ip_address, :type]) }
|
8
|
+
validate -> { validate_has_tag(:Name) }
|
9
|
+
|
10
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
11
|
+
after :initialize, -> { _geo_id -> { NullObject.maybe(tags)[:Name] } }
|
12
|
+
|
13
|
+
def self._fetch_remote_resources
|
14
|
+
AwsClients.ec2.describe_customer_gateways['customer_gateways'].map(&:to_h).map do |gateway|
|
15
|
+
gateway.merge(
|
16
|
+
{
|
17
|
+
_terraform_id: gateway[:customer_gateway_id],
|
18
|
+
_geo_id: gateway[:tags]&.find { |tag| tag[:key] == "Name" }&.dig(:value)
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsEip is the +aws_eip+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/eip.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
|
7
|
+
# Currently geo can't create EIPs - only codify existing ones
|
8
|
+
# It does this by requiring the '_public_ip' attribute and hard-coding the '_geo_id' to that
|
9
|
+
class GeoEngineer::Resources::AwsEip < GeoEngineer::Resource
|
10
|
+
validate :validate_instance_or_network_interface
|
11
|
+
validate -> { validate_required_attributes([:_public_ip]) }
|
12
|
+
|
13
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
14
|
+
after :initialize, -> { _geo_id -> { _public_ip } }
|
15
|
+
|
16
|
+
# Can't associate both an instance and a network interface with an elastic IP
|
17
|
+
def validate_instance_or_network_interface
|
18
|
+
errors = []
|
19
|
+
|
20
|
+
unless instance.nil? || network_interface.nil?
|
21
|
+
errors << "Must associate and Elastic IP with either and EC2 instance or a network interface"
|
22
|
+
end
|
23
|
+
|
24
|
+
errors
|
25
|
+
end
|
26
|
+
|
27
|
+
def support_tags?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
# Always create within a VPC
|
32
|
+
def vpc
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def self._fetch_remote_resources
|
37
|
+
AwsClients.ec2.describe_addresses['addresses'].map(&:to_h).map do |address|
|
38
|
+
address[:_terraform_id] = address[:allocation_id]
|
39
|
+
address[:_geo_id] = address[:public_ip]
|
40
|
+
address
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsIamGroup +aws_iam_group+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/iam_group.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsIamGroup < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:name]) }
|
8
|
+
|
9
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
10
|
+
after :initialize, -> { _geo_id -> { name.to_s } }
|
11
|
+
|
12
|
+
def support_tags?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self._fetch_remote_resources
|
17
|
+
groups = AwsClients.iam.list_groups['groups'].map(&:to_h)
|
18
|
+
|
19
|
+
groups.map do |g|
|
20
|
+
g[:name] = g[:group_name]
|
21
|
+
g[:_geo_id] = g[:group_name]
|
22
|
+
g[:_terraform_id] = g[:group_name]
|
23
|
+
g
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsIamGroup +aws_iam_group_membership+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/iam_group_membership.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsIamGroupMembership < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:name, :users, :group]) }
|
8
|
+
|
9
|
+
before :validation, -> { group _group.to_ref(:name) if _group }
|
10
|
+
|
11
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
12
|
+
after :initialize, -> { _geo_id -> { name.to_s } }
|
13
|
+
|
14
|
+
def to_terraform_state
|
15
|
+
tfstate = super
|
16
|
+
|
17
|
+
attributes = {
|
18
|
+
'group' => _group.name.to_s,
|
19
|
+
'name' => name.to_s
|
20
|
+
}
|
21
|
+
|
22
|
+
tfstate[:primary][:attributes] = attributes
|
23
|
+
tfstate
|
24
|
+
end
|
25
|
+
|
26
|
+
def support_tags?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_remote_as_individual?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def remote_resource_params
|
35
|
+
return {} unless _group
|
36
|
+
return {} unless _group.remote_resource
|
37
|
+
|
38
|
+
users = AwsClients.iam.get_group({ group_name: _group.name })['users']
|
39
|
+
build_remote_resource_params(users)
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_remote_resource_params(users)
|
43
|
+
{
|
44
|
+
name: _group.name,
|
45
|
+
_terraform_id: name.to_s,
|
46
|
+
_geo_id: name.to_s,
|
47
|
+
users: users.map(&:user_name)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
@@ -16,12 +16,16 @@ class GeoEngineer::Resources::AwsIamPolicy < GeoEngineer::Resource
|
|
16
16
|
def to_terraform_state
|
17
17
|
arn = NullObject.maybe(remote_resource).arn
|
18
18
|
default_version_id = NullObject.maybe(remote_resource).default_version_id
|
19
|
+
|
19
20
|
policy = _get_policy_document(arn, default_version_id)
|
20
21
|
|
21
22
|
tfstate = super
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
|
24
|
+
attributes = { 'policy' => policy }
|
25
|
+
attributes['arn'] = arn if arn
|
26
|
+
|
27
|
+
tfstate[:primary][:attributes] = attributes
|
28
|
+
|
25
29
|
tfstate
|
26
30
|
end
|
27
31
|
|
@@ -29,6 +33,10 @@ class GeoEngineer::Resources::AwsIamPolicy < GeoEngineer::Resource
|
|
29
33
|
false
|
30
34
|
end
|
31
35
|
|
36
|
+
def _policy_file(path, binding_obj = nil)
|
37
|
+
_json_file(:policy, path, binding_obj)
|
38
|
+
end
|
39
|
+
|
32
40
|
def _get_policy_document(arn, version_id)
|
33
41
|
response = AwsClients.iam.get_policy_version({ policy_arn: arn,
|
34
42
|
version_id: version_id })
|
@@ -36,7 +44,7 @@ class GeoEngineer::Resources::AwsIamPolicy < GeoEngineer::Resource
|
|
36
44
|
end
|
37
45
|
|
38
46
|
def self._all_remote_policies
|
39
|
-
AwsClients.iam.list_policies.each.map(&:policies).flatten.map(&:to_h)
|
47
|
+
AwsClients.iam.list_policies({ scope: "Local" }).each.map(&:policies).flatten.map(&:to_h)
|
40
48
|
end
|
41
49
|
|
42
50
|
def self._fetch_remote_resources
|
@@ -0,0 +1,95 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsIamPolicyAttachment +aws_iam_policy_attachment+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/iam_policy_attachment.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsIamPolicyAttachment < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:name, :_policy]) }
|
8
|
+
|
9
|
+
validate :shares_name_with_policy
|
10
|
+
|
11
|
+
before :validation, -> { policy_arn _policy.to_ref(:arn) if _policy }
|
12
|
+
|
13
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
14
|
+
after :initialize, -> { _geo_id -> { name.to_s } }
|
15
|
+
|
16
|
+
def validate_shares_name_with_policy
|
17
|
+
return "Policy attachment must share a name with the policy" unless shares_name_with_policy?
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def shares_name_with_policy?
|
22
|
+
policy && name.to_s == policy.name
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_terraform_state
|
26
|
+
tfstate = super
|
27
|
+
|
28
|
+
attributes = { 'name' => name.to_s }
|
29
|
+
attributes['policy_arn'] = remote_resource.policy_arn if remote_resource
|
30
|
+
|
31
|
+
attributes = attributes
|
32
|
+
.merge(terraform_users_attributes)
|
33
|
+
.merge(terraform_groups_attributes)
|
34
|
+
.merge(terraform_roles_attributes)
|
35
|
+
|
36
|
+
tfstate[:primary][:attributes] = attributes
|
37
|
+
tfstate
|
38
|
+
end
|
39
|
+
|
40
|
+
def terraform_users_attributes
|
41
|
+
return {} if users.nil?
|
42
|
+
|
43
|
+
user_attributes = { 'users.#' => users.count.to_s }
|
44
|
+
users.each_with_index { |u, i| user_attributes["users.#{i}"] = u }
|
45
|
+
|
46
|
+
user_attributes
|
47
|
+
end
|
48
|
+
|
49
|
+
def terraform_groups_attributes
|
50
|
+
return {} if groups.nil?
|
51
|
+
|
52
|
+
groups_attributes = { 'groups.#' => groups.count.to_s }
|
53
|
+
groups.each_with_index { |g, i| groups_attributes["groups.#{i}"] = g }
|
54
|
+
|
55
|
+
groups_attributes
|
56
|
+
end
|
57
|
+
|
58
|
+
def terraform_roles_attributes
|
59
|
+
return {} if roles.nil?
|
60
|
+
|
61
|
+
roles_attributes = { 'roles.#' => roles.count.to_s }
|
62
|
+
roles.each_with_index { |r, i| roles_attributes["roles.#{i}"] = r }
|
63
|
+
|
64
|
+
roles_attributes
|
65
|
+
end
|
66
|
+
|
67
|
+
def support_tags?
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_remote_as_individual?
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
def remote_resource_params
|
76
|
+
return {} unless _policy
|
77
|
+
return {} unless _policy.remote_resource
|
78
|
+
|
79
|
+
arn = _policy.remote_resource._terraform_id
|
80
|
+
entities = AwsClients.iam.list_entities_for_policy({ policy_arn: arn })
|
81
|
+
build_remote_resource_params(arn, entities)
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_remote_resource_params(arn, entities)
|
85
|
+
{
|
86
|
+
name: _policy.name,
|
87
|
+
_terraform_id: arn,
|
88
|
+
_geo_id: _policy.name,
|
89
|
+
policy_arn: arn,
|
90
|
+
users: entities[:policy_users].map(&:user_name),
|
91
|
+
groups: entities[:policy_groups].map(&:group_name),
|
92
|
+
roles: entities[:policy_roles].map(&:role_name)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# AwsIamGroup +aws_iam_role+ terrform resource,
|
5
|
+
#
|
6
|
+
# {https://www.terraform.io/docs/providers/aws/r/iam_role.html Terraform Docs}
|
7
|
+
########################################################################
|
8
|
+
class GeoEngineer::Resources::AwsIamRole < GeoEngineer::Resource
|
9
|
+
validate -> { validate_required_attributes([:name, :assume_role_policy]) }
|
10
|
+
|
11
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
12
|
+
after :initialize, -> { _geo_id -> { name.to_s } }
|
13
|
+
|
14
|
+
def to_terraform_state
|
15
|
+
tfstate = super
|
16
|
+
|
17
|
+
arn = NullObject.maybe(remote_resource).arn
|
18
|
+
assume_role_policy = NullObject.maybe(remote_resource).assume_role_policy
|
19
|
+
|
20
|
+
attributes = {}
|
21
|
+
attributes['arn'] = arn if arn
|
22
|
+
attributes['assume_role_policy'] = _normalize_json(assume_role_policy) if assume_role_policy
|
23
|
+
|
24
|
+
tfstate[:primary][:attributes] = attributes
|
25
|
+
tfstate
|
26
|
+
end
|
27
|
+
|
28
|
+
def _assume_role_policy_file(path, binding_obj = nil)
|
29
|
+
_json_file(:assume_role_policy, path, binding_obj)
|
30
|
+
end
|
31
|
+
|
32
|
+
def support_tags?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def self._fetch_remote_resources
|
37
|
+
roles = AwsClients.iam.list_roles['roles'].map(&:to_h)
|
38
|
+
roles.map do |r|
|
39
|
+
r.merge({ name: r[:role_name],
|
40
|
+
_geo_id: r[:role_name],
|
41
|
+
_terraform_id: r[:role_name],
|
42
|
+
assume_role_policy: URI.decode(r[:assume_role_policy_document]) })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -15,10 +15,13 @@ class GeoEngineer::Resources::AwsInstance < GeoEngineer::Resource
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self._fetch_remote_resources
|
18
|
-
_all_remote_instances.map do |
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
_all_remote_instances.map do |instance|
|
19
|
+
instance.merge(
|
20
|
+
{
|
21
|
+
_terraform_id: instance[:instance_id],
|
22
|
+
_geo_id: instance[:tags]&.find { |tag| tag[:key] == "Name" }&.dig(:value)
|
23
|
+
}
|
24
|
+
)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsInternetGateway is the +aws_internet_gateway+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/internet_gateway.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsInternetGateway < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:vpc_id]) }
|
8
|
+
validate -> { validate_has_tag(:Name) }
|
9
|
+
|
10
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
11
|
+
after :initialize, -> { _geo_id -> { NullObject.maybe(tags)[:Name] } }
|
12
|
+
|
13
|
+
def self._fetch_remote_resources
|
14
|
+
AwsClients.ec2.describe_internet_gateways['internet_gateways'].map(&:to_h).map do |gateway|
|
15
|
+
gateway.merge(
|
16
|
+
{
|
17
|
+
_terraform_id: gateway[:internet_gateway_id],
|
18
|
+
_geo_id: gateway[:tags]&.find { |tag| tag[:key] == "Name" }&.dig(:value)
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsLambdaAlias is the +aws_lambda_function+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/lambda_alias.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsLambdaAlias < GeoEngineer::Resource
|
7
|
+
validate -> { validate_required_attributes([:name, :function_name, :function_version]) }
|
8
|
+
validate -> {
|
9
|
+
!(name =~ /(?!^[0-9]+$)([a-zA-Z0-9\-_]+)/).nil? if name
|
10
|
+
}
|
11
|
+
validate -> {
|
12
|
+
!(function_version =~ /(\$LATEST|[0-9]+)/).nil? if function_version
|
13
|
+
}
|
14
|
+
|
15
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
16
|
+
after :initialize, -> { _geo_id -> { [name, function_name, function_version].join("::") } }
|
17
|
+
|
18
|
+
def support_tags?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO(Brad) - May need to implement solution for pagination...
|
23
|
+
def self._fetch_functions
|
24
|
+
AwsClients
|
25
|
+
.lambda
|
26
|
+
.list_functions['functions']
|
27
|
+
.map(&:to_h)
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO(Brad) - May need to implement solution for pagination...
|
31
|
+
def self._fetch_aliases(function)
|
32
|
+
options = { function_name: function[:function_name] }
|
33
|
+
AwsClients.lambda.list_aliases(options)[:aliases].map(&:to_h).map do |f_alias|
|
34
|
+
geo_id_components = [f_alias[:name], f_alias[:function_name], f_alias[:function_version]]
|
35
|
+
f_alias.merge(
|
36
|
+
{
|
37
|
+
_terraform_id: f_alias[:alias_arn],
|
38
|
+
_geo_id: geo_id_components.join('::')
|
39
|
+
}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self._fetch_remote_resources
|
45
|
+
_fetch_functions
|
46
|
+
.map { |function| _fetch_aliases(function) }
|
47
|
+
.flatten
|
48
|
+
.compact
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
########################################################################
|
2
|
+
# AwsLambdaEventSourceMapping is the +aws_lambda_event_source_mapping+ terrform resource,
|
3
|
+
#
|
4
|
+
# {https://www.terraform.io/docs/providers/aws/r/lambda_event_source_mapping.html Terraform Docs}
|
5
|
+
########################################################################
|
6
|
+
class GeoEngineer::Resources::AwsLambdaEventSourceMapping < GeoEngineer::Resource
|
7
|
+
validate -> {
|
8
|
+
validate_required_attributes([:event_source_arn, :function_name, :starting_position])
|
9
|
+
}
|
10
|
+
validate -> {
|
11
|
+
if self.starting_position && !%w(TRIM_HORIZON LATEST).include?(self.starting_position)
|
12
|
+
["starting_position must be either TRIM_HORIZON OR LATEST"]
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
after :initialize, -> { _terraform_id -> { NullObject.maybe(remote_resource)._terraform_id } }
|
17
|
+
after :initialize, -> { _geo_id -> { [event_source_arn, function_name].join("::") } }
|
18
|
+
|
19
|
+
def support_tags?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def short_type
|
24
|
+
"event_mapping"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self._extract_name_from_arn(arn)
|
28
|
+
arn_components = arn.split(":")
|
29
|
+
arn_components[arn_components.index("function") + 1] if arn_components.index("function")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self._fetch_remote_resources
|
33
|
+
AwsClients
|
34
|
+
.lambda
|
35
|
+
.list_event_source_mappings['event_source_mappings']
|
36
|
+
.map(&:to_h)
|
37
|
+
.map do |event|
|
38
|
+
geo_id = [event[:event_source_arn], self._extract_name_from_arn(event[:function_arn])]
|
39
|
+
event.merge(
|
40
|
+
{
|
41
|
+
_terraform_id: event[:uuid],
|
42
|
+
_geo_id: geo_id.join("::")
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|