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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/compound/vpc.rb', line 3
def self.[](prefix, suffix, &block)
Module.new do
extend ActiveSupport::Concern
included do
def validate_instance_tenancy(value)
unless ["", 'default', 'dedicated'].include? value
raise "Expected instance_tenancy to be within `default` or `dedicated`. Received `#{value}`"
end
value
end
variable :cidr_block,
default: "10.0.0.0/16"
variable :enable_dns_support,
default: true
variable :enable_dns_hostnames,
default: true
variable :instance_tenancy,
filter: :validate_instance_tenancy
yield self if block_given?
resource "#{prefix}_vpc#{suffix}",
type: "AWS::EC2::VPC" do |r, index|
r.property(:cidr_block) { cidr_block }
r.property(:enable_dns_support) { enable_dns_support }
r.property(:enable_dns_hostnames) { enable_dns_hostnames }
r.property(:instance_tenancy) { instance_tenancy } unless instance_tenancy.empty?
end
resource "#{prefix}_internet_gateway#{suffix}",
type: "AWS::EC2::InternetGateway"
resource "#{prefix}_route#{suffix}",
type: "AWS::EC2::Route" do |r, index|
r.property(:destination_cidr_block) { "0.0.0.0/0" }
r.property(:gateway_id) { "#{prefix}_internet_gateway#{suffix}".cfnize.ref }
r.property(:route_table_id) { "#{prefix}_route_table#{suffix}".cfnize.ref }
end
resource "#{prefix}_route_table#{suffix}",
type: "AWS::EC2::RouteTable" do |r, index|
r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
end
resource "#{prefix}_vpc_gateway_attachment#{suffix}",
type: "AWS::EC2::VPCGatewayAttachment" do |r, index|
r.property(:internet_gateway_id) { "#{prefix}_internet_gateway#{suffix}".cfnize.ref }
r.property(:vpc_id) { "#{prefix}_vpc#{suffix}".cfnize.ref }
end
end
end
end
|