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

- old
+ new

@@ -39,17 +39,24 @@ def instance @instance ||= begin local_definition_folder = fetch_definition puts "Will use local stack definition files in #{local_definition_folder}" - Cloudspin::Stack::Instance.from_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 fetch_definition if /^http.*\.zip$/.match @definition_location @@ -61,10 +68,24 @@ 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 @@ -115,9 +136,13 @@ desc "Destroy stack instance" task :down do puts instance.init_dry puts instance.down_dry puts instance.down + end + + task :refresh do + puts instance.refresh end end # TODO: This stuff belongs in a core class, so the CLI and other stuff can use it, too.