Class: Ufo::Cfn::Stack::Vars

Inherits:
Base show all
Defined in:
lib/ufo/cfn/stack/vars.rb

Instance Attribute Summary collapse

Attributes inherited from Ufo::CLI::Base

#task_definition

Instance Method Summary collapse

Methods included from Ufo::Concerns

#build, #deploy, #info, #ps

Methods included from Ufo::Concerns::Names

#names

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #find_stack, #ssm_client, #stack_resources, #status, #task_definition_arns, #waf_client

Methods inherited from Ufo::CLI::Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Constructor Details

This class inherits a constructor from Ufo::CLI::Base

Instance Attribute Details

#stack_nameObject (readonly)

Returns the value of attribute stack_name.



3
4
5
# File 'lib/ufo/cfn/stack/vars.rb', line 3

def stack_name
  @stack_name
end

Instance Method Details

#containerObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ufo/cfn/stack/vars.rb', line 75

def container
  task_definition = Builder::Resources::TaskDefinition::Reconstructor.new(@task_definition, @options[:rollback]).reconstruct

  container_def = task_definition["ContainerDefinitions"].first
  requires_compatibilities = task_definition["RequiresCompatibilities"]
  fargate = requires_compatibilities && requires_compatibilities == ["FARGATE"]
  network_mode = task_definition["NetworkMode"]

  mappings = container_def["PortMappings"] || []
  unless mappings.empty?
    port = mappings.first["ContainerPort"]
  end

  result =  {
    name: container_def["Name"],
    fargate: fargate,
    network_mode: network_mode, # awsvpc, bridge, etc
  }
  result[:port] = port if port
  result
end

#create_elb?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
# File 'lib/ufo/cfn/stack/vars.rb', line 66

def create_elb?
  elb = Ufo.config.elb
  if elb.enabled.to_s == "auto"
    container[:name] == "web" # convention
  else
    elb.enabled # true or false
  end
end

#create_listener_ssl?Boolean

if the configuration is set to anything then enable it

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/ufo/cfn/stack/vars.rb', line 61

def create_listener_ssl?
  elb = Ufo.config.elb
  elb.ssl.enabled && elb.ssl.certificates
end

#default_listener_protocolObject



43
44
45
46
47
48
49
50
# File 'lib/ufo/cfn/stack/vars.rb', line 43

def default_listener_protocol
  port = Ufo.config.elb.port
  if elb_type == 'network'
    port == 443 ? 'TLS' : 'TCP'
  else
    port == 443 ? 'HTTPS' : 'HTTP'
  end
end

#default_listener_ssl_protocolObject



52
53
54
# File 'lib/ufo/cfn/stack/vars.rb', line 52

def default_listener_ssl_protocol
  elb_type == 'network' ? 'TLS' : 'HTTPS'
end

#default_target_group_protocolObject



56
57
58
# File 'lib/ufo/cfn/stack/vars.rb', line 56

def default_target_group_protocol
  elb_type == 'network' ? 'TCP' : 'HTTP'
end

#dns_configured?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ufo/cfn/stack/vars.rb', line 39

def dns_configured?
  !!Ufo.config.dns.domain || !!Ufo.config.dns.name
end

#elb_typeObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ufo/cfn/stack/vars.rb', line 105

def elb_type
  elb_type = Ufo.config.elb.type
  return elb_type if elb_type

  # user is trying to create a network load balancer if subnet_mappings used
  subnet_mappings = Ufo.config.elb.subnet_mappings
  if subnet_mappings.empty?
    "application" # default
  else
    "network"
  end
end

#get_parameter_value(stack, key) ⇒ Object



98
99
100
101
102
103
# File 'lib/ufo/cfn/stack/vars.rb', line 98

def get_parameter_value(stack, key)
  param = stack.parameters.find do |p|
    p.parameter_key == key
  end
  param.parameter_value if param
end

#new_stackObject



24
25
26
# File 'lib/ufo/cfn/stack/vars.rb', line 24

def new_stack
  !stack
end

#rollback_task_definitionObject



34
35
36
37
# File 'lib/ufo/cfn/stack/vars.rb', line 34

def rollback_task_definition
  return unless @options[:rollback]
  @options[:rollback_task_definition]
end

#stackObject

Find stack in vars to ensure both ufo build and ufo ship can tell if stack has already been built



29
30
31
# File 'lib/ufo/cfn/stack/vars.rb', line 29

def stack
  find_stack(@stack_name)
end

#valuesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ufo/cfn/stack/vars.rb', line 5

def values
  # Not passing stack down to vars beause its easier to debug. Will require another lookup by thats ok
  {
    cluster: @cluster,
    container: container,
    create_elb: create_elb?, # helps set Ecs DependsOn
    create_listener_ssl: create_listener_ssl?,
    create_route53: create_elb? && dns_configured?,
    default_listener_protocol: default_listener_protocol,
    default_listener_ssl_protocol: default_listener_ssl_protocol,
    default_target_group_protocol: default_target_group_protocol,
    elb_type: elb_type,
    new_stack: new_stack,
    rollback_task_definition: rollback_task_definition,
    stack_name: @stack_name, # used in custom_properties
    task_definition: @task_definition, # to reconstruct TaskDefinition for CloudFormation template
  }
end