Module: Ufo::TaskDefinition::Helpers::Vpc

Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/ufo/task_definition/helpers/vpc.rb

Instance Method Summary collapse

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from AwsServices::Concerns

#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns

Instance Method Details

#default_subnetsObject



30
31
32
33
34
35
36
37
38
# File 'lib/ufo/task_definition/helpers/vpc.rb', line 30

def default_subnets
  if default_vpc.nil?
    logger.error "ERROR: no default subnets because no default vpc found".color(:red)
    exit 1
  end
  resp = ec2.describe_subnets(filters: [name: "vpc-id", values: [default_vpc]])
  subnets = resp.subnets
  subnets.map(&:subnet_id)
end

#default_vpcObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ufo/task_definition/helpers/vpc.rb', line 6

def default_vpc
  resp = ec2.describe_vpcs(filters: [name: "isDefault", values: ["true"]])
  vpc = resp.vpcs.first
  if vpc
    vpc.vpc_id
  else
    logger.error "No default vpc found".color(:red)
    logger.error <<~EOL
      Please configure the `config.vpc` settings.

      Docs: https://ufoships.com/config/vpc/

    EOL
    exit 1
  end
end

#key_pairs(regexp = nil) ⇒ Object



41
42
43
44
45
46
# File 'lib/ufo/task_definition/helpers/vpc.rb', line 41

def key_pairs(regexp=nil)
  resp = ec2.describe_key_pairs
  key_names = resp.key_pairs.map(&:key_name)
  key_names.select! { |k| k =~ regexp } if regexp
  key_names
end

#subnets_for(vpc_id) ⇒ Object



24
25
26
27
28
# File 'lib/ufo/task_definition/helpers/vpc.rb', line 24

def subnets_for(vpc_id)
  resp = ec2.describe_subnets(filters: [name: "vpc-id", values: [vpc_id]])
  subnets = resp.subnets
  subnets.map(&:subnet_id)
end