module Devops module Model class StackTemplateEc2 < StackTemplateBase # In Amazon Cloudformation the template file must be stored on an Amazon S3 bucket. attr_accessor :template_url # types template_url: {type: String, empty: false} def initialize(attrs) self.template_url = attrs['template_url'] super(attrs) end def to_hash_without_id super.merge(template_url: template_url) end def update_template_url self.template_url = generate_template_file_and_upload_to_storage(id, template_body) end class << self def create(attrs) model = super(attrs) model.update_template_url model end end private def generate_template_file_and_upload_to_storage(id, json) uniq_filename = "#{id}-#{SecureRandom.hex}.template" provider_instance.store_stack_template(uniq_filename, json)['url'] end end end end