lib/cloudspin/stack/rake/stack_task.rb in cloudspin-stack-rake-0.1.17 vs lib/cloudspin/stack/rake/stack_task.rb in cloudspin-stack-rake-0.1.18

- old
+ new

@@ -19,11 +19,11 @@ configuration_files: nil ) @environment = environment @stack_name = stack_name @base_folder = base_folder - @configuration_files = configuration_files || the_usual_configuration_files + set_configuration_files(configuration_files) # TODO: Pick this up from the configuration files? @definition_location = if definition_location definition_location elsif definition_folder @@ -35,57 +35,14 @@ # @remote_zipfile = remote_zipfile define end - def instance - @instance ||= begin - local_definition_folder = fetch_definition - puts "Will use local stack definition files in #{local_definition_folder}" - - the_instance = Cloudspin::Stack::Instance.from_folder( - @configuration_files, - stack_name: stack_name, - definition_folder: local_definition_folder, - base_folder: @base_folder, - base_working_folder: "#{@base_folder}/work" - ) - - if the_instance.configuration.has_remote_state_configuration? - add_terraform_backend_source(local_definition_folder) - end - - the_instance - end + def set_configuration_files(additional_configuration_files) + @configuration_files = (the_usual_configuration_files << additional_configuration_files).flatten.compact end - def fetch_definition - if /^http.*\.zip$/.match @definition_location - puts "Downloading stack definition source from a remote zipfile" - fetch_definition_zipfile - elsif /^[\.\/]/.match @definition_location - puts "Using local stack definition source" - @definition_location - else - raise UnsupportedStackDefinitionLocationError, @definition_location - end - end - - def add_terraform_backend_source(terraform_source_folder) - - puts "Creating file #{terraform_source_folder}/_cloudspin_created_backend.tf" - - File.open("#{terraform_source_folder}/_cloudspin_created_backend.tf", 'w') { |backend_file| - backend_file.write(<<~TF_BACKEND_SOURCE - terraform { - backend "s3" {} - } - TF_BACKEND_SOURCE - ) - } - end - def the_usual_configuration_files file_list = default_configuration_files if @environment if File.exists? full_path_of(environment_config_file) file_list << environment_config_file @@ -96,12 +53,12 @@ file_list end def default_configuration_files [ - "#{@base_folder}/stack-#{@stack_name}-defaults.yaml", - "#{@base_folder}/stack-#{@stack_name}-local.yaml" + "#{@base_folder}/stack-instance-defaults.yaml", + "#{@base_folder}/stack-instance-local.yaml" ] end def environment_config_file "#{@base_folder}/environments/stack-#{@stack_name}-#{@environment}.yaml" @@ -143,10 +100,55 @@ task :refresh do puts instance.refresh end end + def instance + @instance ||= begin + local_definition_folder = fetch_definition + puts "Will use local stack definition files in #{local_definition_folder}" + + the_instance = Cloudspin::Stack::Instance.from_folder( + @configuration_files, + stack_name: stack_name, + definition_folder: local_definition_folder, + base_folder: @base_folder, + base_working_folder: "#{@base_folder}/work" + ) + + if the_instance.configuration.has_remote_state_configuration? + add_terraform_backend_source(local_definition_folder) + end + + the_instance + end + end + + def add_terraform_backend_source(terraform_source_folder) + puts "Creating file #{terraform_source_folder}/_cloudspin_created_backend.tf" + File.open("#{terraform_source_folder}/_cloudspin_created_backend.tf", 'w') { |backend_file| + backend_file.write(<<~TF_BACKEND_SOURCE + terraform { + backend "s3" {} + } + TF_BACKEND_SOURCE + ) + } + end + # TODO: This stuff belongs in a core class, so the CLI and other stuff can use it, too. + + def fetch_definition + if /^http.*\.zip$/.match @definition_location + puts "Downloading stack definition source from a remote zipfile" + fetch_definition_zipfile + elsif /^[\.\/]/.match @definition_location + puts "Using local stack definition source" + @definition_location + else + raise UnsupportedStackDefinitionLocationError, @definition_location + end + end def fetch_definition_zipfile unpack(download_artefact(@definition_location), '.cloudspin/definitions') end