Class: Jets::Resource::ChildStack::ApiDeployment

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/resource/child_stack/api_deployment.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #outputs, #template_url

Methods inherited from Base

#replacements, #resource

Constructor Details

This class inherits a constructor from Jets::Resource::ChildStack::Base

Instance Method Details

#definitionObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 8

def definition
  {
    deployment_id => {
      type: "AWS::CloudFormation::Stack",
      properties: {
        template_url: template_url,
        parameters: parameters,
      },
      depends_on: depends_on,
    }
  }
end

#depends_onObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 31

def depends_on
  expression = "#{Jets::Naming.template_path_prefix}-*_controller*"
  controller_logical_ids = []
  Dir.glob(expression).each do |path|
    next unless File.file?(path)

    # map the path to a camelized logical_id. Example:
    #   /tmp/jets/demo/templates/demo-dev-2-posts_controller.yml to
    #   PostsController
    regexp = Regexp.new(".*#{Jets.config.project_namespace}-app-")
    controller_name = path.sub(regexp, '').sub('.yml', '')
    controller_logical_id = controller_name.underscore.camelize
    controller_logical_ids << controller_logical_id
  end
  controller_logical_ids
end

#deployment_idObject



48
49
50
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 48

def deployment_id
  Jets::Resource::ApiGateway::Deployment.logical_id
end

#parametersObject



21
22
23
24
25
26
27
28
29
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 21

def parameters
  p = {
    IamRole: "!GetAtt IamRole.Arn",
    RestApi: "!GetAtt ApiGateway.Outputs.RestApi",
    S3Bucket: "!Ref S3Bucket",
  }
  p[:DomainName] = "!GetAtt ApiGateway.Outputs.DomainName" if Jets.custom_domain?
  p
end

#template_filenameObject



52
53
54
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 52

def template_filename
  "#{Jets.config.project_namespace}-api-deployment.yml"
end