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, #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

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ufo/cfn/stack/vars.rb', line 96

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)


81
82
83
84
85
86
87
88
89
90
# File 'lib/ufo/cfn/stack/vars.rb', line 81

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

#create_listener?Boolean

Returns:

  • (Boolean)


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

def create_listener?
  Ufo.config.elb.listener.enabled
end

#create_listener_ssl?Boolean

if the configuration is set to anything then enable it

Returns:

  • (Boolean)


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

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

#create_route53?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
# File 'lib/ufo/cfn/stack/vars.rb', line 72

def create_route53?
  return false unless dns_configured?
  if create_elb?
    true
  else
    Ufo.config.elb.existing.target_group
  end
end

#default_listener_protocolObject



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

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



54
55
56
# File 'lib/ufo/cfn/stack/vars.rb', line 54

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

#default_target_group_protocolObject



58
59
60
# File 'lib/ufo/cfn/stack/vars.rb', line 58

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

#dns_configured?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ufo/cfn/stack/vars.rb', line 41

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

#elb_target_groupObject



92
93
94
# File 'lib/ufo/cfn/stack/vars.rb', line 92

def elb_target_group
  Ufo.config.elb.existing.target_group
end

#elb_typeObject



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ufo/cfn/stack/vars.rb', line 126

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



119
120
121
122
123
124
# File 'lib/ufo/cfn/stack/vars.rb', line 119

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



26
27
28
# File 'lib/ufo/cfn/stack/vars.rb', line 26

def new_stack
  !stack
end

#rollback_task_definitionObject



36
37
38
39
# File 'lib/ufo/cfn/stack/vars.rb', line 36

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



31
32
33
# File 'lib/ufo/cfn/stack/vars.rb', line 31

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
23
24
# 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: create_listener?,
    create_listener_ssl: create_listener_ssl?,
    create_route53: create_route53?,
    default_listener_protocol: default_listener_protocol,
    default_listener_ssl_protocol: default_listener_ssl_protocol,
    default_target_group_protocol: default_target_group_protocol,
    elb_target_group: elb_target_group,
    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