Module: Terrafying::Components::Usable

Included in:
DynamicSet, Endpoint, Instance, LoadBalancer, Service, StaticSet
Defined in:
lib/terrafying/components/usable.rb

Instance Method Summary collapse

Instance Method Details

#egress_security_groupObject



16
17
18
# File 'lib/terrafying/components/usable.rb', line 16

def egress_security_group
  @egress_security_group || @security_group
end

#ingress_security_groupObject



12
13
14
# File 'lib/terrafying/components/usable.rb', line 12

def ingress_security_group
  @ingress_security_group || @security_group
end

#path_mtu_setup!Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/terrafying/components/usable.rb', line 20

def path_mtu_setup!
  resource :aws_security_group_rule, "#{@name}-path-mtu", {
               security_group_id: self.egress_security_group,
               type: "ingress",
               protocol: 1, # icmp
               from_port: 3, # icmp type
               to_port: 4, # icmp code
               cidr_blocks: ["0.0.0.0/0"],
             }
end

#pingable_by(*other_resources) ⇒ Object



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
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/terrafying/components/usable.rb', line 61

def pingable_by(*other_resources)
  other_resources.map { |other_resource|
    resource :aws_security_group_rule, "#{@name}-to-#{other_resource.name}-ping", {
               security_group_id: self.ingress_security_group,
               type: "ingress",
               protocol: 1, # icmp
               from_port: 8, # icmp type
               to_port: 0, # icmp code
               source_security_group_id: other_resource.egress_security_group,
             }

    resource :aws_security_group_rule, "#{@name}-to-#{other_resource.name}-pingv6", {
               security_group_id: self.ingress_security_group,
               type: "ingress",
               protocol: 58, # icmpv6
               from_port: 128, # icmp type
               to_port: 0, # icmp code
               source_security_group_id: other_resource.egress_security_group,
             }

    resource :aws_security_group_rule, "#{other_resource.name}-to-#{@name}-ping", {
               security_group_id: other_resource.egress_security_group,
               type: "egress",
               protocol: 1, # icmp
               from_port: 8, # icmp type
               to_port: 0, # icmp code
               source_security_group_id: self.ingress_security_group,
             }

    resource :aws_security_group_rule, "#{other_resource.name}-to-#{@name}-pingv6", {
               security_group_id: other_resource.egress_security_group,
               type: "egress",
               protocol: 58, # icmpv6
               from_port: 128, # icmp type
               to_port: 0, # icmp code
               source_security_group_id: self.ingress_security_group,
             }
  }
end

#pingable_by_cidr(*cidrs) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/terrafying/components/usable.rb', line 31

def pingable_by_cidr(*cidrs)
  ident = Digest::SHA2.hexdigest cidrs.to_s

  resource :aws_security_group_rule, "#{@name}-to-#{ident}-ping", {
               security_group_id: self.ingress_security_group,
               type: "ingress",
               protocol: 1, # icmp
               from_port: 8, # icmp type
               to_port: 0, # icmp code
               cidr_blocks: cidrs,
             }
end

#security_groupObject



8
9
10
# File 'lib/terrafying/components/usable.rb', line 8

def security_group
  @security_group
end

#used_by(*other_resources) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/terrafying/components/usable.rb', line 101

def used_by(*other_resources)
  other_resources.map { |other_resource|
    @ports.map {|port|
      resource :aws_security_group_rule, "#{@name}-to-#{other_resource.name}-#{port[:name]}", {
                 security_group_id: self.ingress_security_group,
                 type: "ingress",
                 from_port: port[:upstream_port],
                 to_port: port[:upstream_port],
                 protocol: port[:type] == "udp" ? "udp" : "tcp",
                 source_security_group_id: other_resource.egress_security_group,
               }

      resource :aws_security_group_rule, "#{other_resource.name}-to-#{@name}-#{port[:name]}", {
                 security_group_id: other_resource.egress_security_group,
                 type: "egress",
                 from_port: port[:downstream_port],
                 to_port: port[:downstream_port],
                 protocol: port[:type] == "udp" ? "udp" : "tcp",
                 source_security_group_id: self.ingress_security_group,
               }
    }
  }
end

#used_by_cidr(*cidrs) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/terrafying/components/usable.rb', line 44

def used_by_cidr(*cidrs)
  cidrs.map { |cidr|
    cidr_ident = cidr.gsub(/[\.\/]/, "-")

    @ports.map {|port|
      resource :aws_security_group_rule, "#{@name}-to-#{cidr_ident}-#{port[:name]}", {
                 security_group_id: self.ingress_security_group,
                 type: "ingress",
                 from_port: port[:upstream_port],
                 to_port: port[:upstream_port],
                 protocol: port[:type] == "udp" ? "udp" : "tcp",
                 cidr_blocks: [cidr],
               }
    }
  }
end