/
vpc_peering_connection.rb
48 lines (43 loc) · 1.47 KB
/
vpc_peering_connection.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Enscalator
module Plugins
# VPC Peering Connection Plugin
module VPCPeeringConnection
# Template parameter for VPC ID
#
# @param [String] name parameter name
# @param [String] description parameter description
def parameter_vpc_id(name, description, default_value = nil)
options = {
Description: description,
Type: 'String',
AllowedPattern: 'vpc-[a-zA-Z0-9]*',
ConstraintDescription: 'must be valid VPC id (vpc-*).'
}
options[:Default] = default_value if default_value && !default_value.nil?
parameter name, options
end
# Create new vpc peering connection
#
# @param [String] conn_name connection name
# @param [Array<String>] tags list of tags
def vpc_peering_init(conn_name, tags: [])
options = {}
options[:Properties] = {
VpcId: ref("#{conn_name}VpcId"),
PeerVpcId: ref("#{conn_name}PeerVpcId")
}
# Set plugin tags
options[:Properties][:Tags] = tags if tags && !tags.empty?
resource conn_name,
{
Type: 'AWS::EC2::VPCPeeringConnection'
}.merge(options)
output conn_name,
Description: 'VPC Peering connection name',
Value: ref(conn_name)
# return resource name
conn_name
end
end # module VPCPeeringConnection
end # module Plugins
end # module Enscalator