Sha256: a01969f330aa3f7f91ff22a5ddf04bff6440b9297c07969e821f68c6fc8c2138

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 KB

Contents

# Implements:
#
#   definition
#   template_filename
#
module Jets::Resource::ChildStack
  class ApiResource < Base
    def initialize(*)
      super
      @page = @options[:page]
    end

    def definition
      {
        "api_resources_#{@page}" =>  {
          type: "AWS::CloudFormation::Stack",
          # depends_on: "ApiGateway", # CloudFormation seems to be smart enough
          properties: {
            template_url: template_url,
            parameters: parameters,
          }
        }
      }
    end

    def parameters
      params = {}
      # Since dont have all the info required.
      # Read the template back to find the parameters required.
      # Actually might be easier to rationalize this approach.
      template_path = Jets::Names.api_resources_template_path(@page)
      template = Jets::Cfn::BuiltTemplate.get(template_path)
      template['Parameters'].keys.each do |p|
        case p
        when "RestApi"
          params[p] = "!GetAtt ApiGateway.Outputs.RestApi"
        when "RootResourceId"
          params[p] = "!GetAtt ApiGateway.Outputs.RootResourceId"
        else
          params[p] = "!GetAtt #{api_resource_page(p)}.Outputs.#{p}"
        end
      end
      params
    end

    def api_resource_page(parameter)
      Page.logical_id(parameter)
    end

    def template_filename
      "#{Jets.config.project_namespace}-api-resources-#{@page}.yml"
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jets-4.0.12 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.11 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.10 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.9 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.8 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.7 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.6 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.5 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.4 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.3 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.2 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.1 lib/jets/resource/child_stack/api_resource.rb
jets-4.0.0 lib/jets/resource/child_stack/api_resource.rb