Sha256: 835350900c263510354910b17fc77be69cc4a28ebd1d4b98161f7926f7210f88

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

module Jets::Resource::ChildStack
  class ApiDeployment < Jets::Resource::Base
    def initialize(s3_bucket)
      @s3_bucket = s3_bucket
    end

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

    def parameters
      {
        RestApi: "!GetAtt ApiGateway.Outputs.RestApi",
      }
    end

    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}-")
        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

    def outputs
      {
        logical_id => "!Ref #{logical_id}",
      }
    end

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

    def template_url
      path = File.basename("#{Jets.config.project_namespace}-api-deployment.yml")
      "https://s3.amazonaws.com/#{@s3_bucket}/jets/cfn-templates/#{path}"
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
jets-0.8.18 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.17 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.15 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.14 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.13 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.12 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.11 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.10 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.9 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.8 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.6 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.5 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.4 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.3 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.2 lib/jets/resource/child_stack/api_deployment.rb
jets-0.8.1 lib/jets/resource/child_stack/api_deployment.rb