Class: ElasticBeans::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_beans/network.rb

Overview

The networking CloudFormation stack provided to configure.

Defined Under Namespace

Classes: MissingNetworkingError

Constant Summary collapse

APPLICATION_SECURITY_GROUP_KEY =
"ApplicationSecurityGroup"
APPLICATION_SUBNET_KEY =
"ApplicationSubnet"
APPLICATION_SUBNET_KEY_PATTERN =
/\AApplicationSubnet\d*\z/
ELB_SECURITY_GROUP_KEY =
"ELBSecurityGroup"
ELB_SUBNET_KEY =
"ELBSubnet"
ELB_SUBNET_KEY_PATTERN =
/\AELBSubnet\d*\z/
SSH_SECURITY_GROUP_KEY =
"SSHSecurityGroup"
VPC_KEY =
"VpcId"

Instance Method Summary collapse

Constructor Details

#initialize(stack_name:, cloudformation:) ⇒ Network

Returns a new instance of Network.



15
16
17
# File 'lib/elastic_beans/network.rb', line 15

def initialize(stack_name:, cloudformation:)
  @stack = ElasticBeans::Aws::CloudformationStack.new(stack_name, cloudformation: cloudformation)
end

Instance Method Details

#application_security_groupsObject



19
20
21
# File 'lib/elastic_beans/network.rb', line 19

def application_security_groups
  [stack.stack_output(APPLICATION_SECURITY_GROUP_KEY)]
end

#application_subnetsObject



23
24
25
26
27
28
29
# File 'lib/elastic_beans/network.rb', line 23

def application_subnets
  subnet_outputs = stack.stack_outputs.select { |key, value| key =~ APPLICATION_SUBNET_KEY_PATTERN }
  if subnet_outputs.empty?
    raise MissingNetworkingError.new(stack: stack, key: APPLICATION_SUBNET_KEY)
  end
  subnet_outputs.values
end

#elb_security_groupsObject



31
32
33
# File 'lib/elastic_beans/network.rb', line 31

def elb_security_groups
  [stack.stack_output(ELB_SECURITY_GROUP_KEY)]
end

#elb_subnetsObject



35
36
37
38
39
40
41
# File 'lib/elastic_beans/network.rb', line 35

def elb_subnets
  subnet_outputs = stack.stack_outputs.select { |key, value| key =~ ELB_SUBNET_KEY_PATTERN }
  if subnet_outputs.empty?
    raise MissingNetworkingError.new(stack: stack, key: ELB_SUBNET_KEY)
  end
  subnet_outputs.values
end

#ssh_security_groupObject



43
44
45
# File 'lib/elastic_beans/network.rb', line 43

def ssh_security_group
  stack.stack_output(SSH_SECURITY_GROUP_KEY)
end

#vpcObject



47
48
49
# File 'lib/elastic_beans/network.rb', line 47

def vpc
  stack.stack_output(VPC_KEY)
end