Class: Ufo::Cfn::Stack::Builder

Inherits:
Base show all
Includes:
Utils::Logging
Defined in:
lib/ufo/cfn/stack/builder.rb,
lib/ufo/cfn/stack/builder/base.rb,
lib/ufo/cfn/stack/builder/outputs.rb,
lib/ufo/cfn/stack/builder/resources.rb,
lib/ufo/cfn/stack/builder/conditions.rb,
lib/ufo/cfn/stack/builder/parameters.rb

Defined Under Namespace

Classes: Base, Conditions, Outputs, Parameters, Resources

Instance Attribute Summary

Attributes inherited from Ufo::CLI::Base

#task_definition

Instance Method Summary collapse

Methods included from Utils::Logging

#logger

Methods included from Ufo::Concerns

#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 included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
9
# File 'lib/ufo/cfn/stack/builder.rb', line 5

def initialize(options={})
  super
  @vars = options[:vars]
  @template = {Description: "UFO ECS stack #{@vars[:stack_name]}"}
end

Instance Method Details

#buildObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ufo/cfn/stack/builder.rb', line 11

def build
  logger.info "Building template"
  @template[:Parameters] = Parameters.build(@options)
  @template[:Conditions] = Conditions.build(@options)
  @template[:Resources] = Resources.build(@options)
  @template[:Outputs] = Outputs.build(@options)
  @template.deep_stringify_keys!
  @template = Ufo::Utils::Squeezer.new(@template).squeeze
  @template = CustomProperties.new(@template, @vars[:stack_name]).apply
  write(@template)
end

#write(template) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/ufo/cfn/stack/builder.rb', line 23

def write(template)
  text = YAML.dump(template)
  path = ".ufo/output/template.yml"
  IO.write("#{Ufo.root}/#{path}", text)
  logger.info "    #{path}"
  # Only basic YAML validation. Doesnt check for everything CloudFormation checks.
  # For CloudFormation checks handled with an exception handler in Cfn::Stack#print_code(exception)
  Ufo::Yaml.validate!(path)
  text
end