Class: Forger::Network
- Inherits:
-
Object
- Object
- Forger::Network
- Extended by:
- Memoist
- Includes:
- AwsServices
- Defined in:
- lib/forger/network.rb
Instance Method Summary collapse
-
#initialize(vpc_id) ⇒ Network
constructor
A new instance of Network.
-
#security_group_id ⇒ Object
default security group.
-
#subnet_ids ⇒ Object
all subnets.
- #vpc_id ⇒ Object
Methods included from AwsServices
Constructor Details
#initialize(vpc_id) ⇒ Network
Returns a new instance of Network.
8 9 10 |
# File 'lib/forger/network.rb', line 8 def initialize(vpc_id) @vpc_id = vpc_id end |
Instance Method Details
#security_group_id ⇒ Object
default security group
39 40 41 42 43 44 45 |
# File 'lib/forger/network.rb', line 39 def security_group_id resp = ec2.describe_security_groups(filters: [ {name: "vpc-id", values: [vpc_id]}, {name: "group-name", values: ["default"]} ]) resp.security_groups.first.group_id end |
#subnet_ids ⇒ Object
all subnets
30 31 32 33 34 35 |
# File 'lib/forger/network.rb', line 30 def subnet_ids resp = ec2.describe_subnets(filters: [ {name: "vpc-id", values: [vpc_id]} ]) resp.subnets.map(&:subnet_id).sort end |
#vpc_id ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/forger/network.rb', line 12 def vpc_id return @vpc_id if @vpc_id resp = ec2.describe_vpcs(filters: [ {name: "isDefault", values: ["true"]} ]) default_vpc = resp.vpcs.first if default_vpc default_vpc.vpc_id else puts "A default vpc was not found in this AWS account and region.".color(:red) puts "Because there is no default vpc, please specify the --vpc-id option." exit 1 end end |