Class: Cloudspin::Stack::Terraform
- Inherits:
-
Object
- Object
- Cloudspin::Stack::Terraform
- Defined in:
- lib/cloudspin/stack/terraform.rb
Instance Method Summary collapse
- #down ⇒ Object
- #down_dry ⇒ Object
- #init ⇒ Object
- #init_dry ⇒ Object
-
#initialize(working_folder: '.', terraform_variables: {}, terraform_init_arguments: {}, terraform_command_arguments: {}) ⇒ Terraform
constructor
KSM: Maybe this should be a static class - pass in the working directory and the arguments, and call them.
- #plan(plan_destroy: false) ⇒ Object
- #plan_dry(plan_destroy: false) ⇒ Object
- #refresh ⇒ Object
-
#terraform_command_arguments(added_parameters = {}) ⇒ Object
KSM: Do we have this here, or do we munge all this up in the calling method and just pass in the processed list of arguments? For that matter, should we just call each of the actions on this class as static methods? Does this class really need to hold any kind of state?.
- #terraform_init ⇒ Object
- #up ⇒ Object
- #up_dry ⇒ Object
Constructor Details
#initialize(working_folder: '.', terraform_variables: {}, terraform_init_arguments: {}, terraform_command_arguments: {}) ⇒ Terraform
KSM: Maybe this should be a static class - pass in the working directory and the arguments, and call them. All the logic of assembling the command line arguments should be in the caller?? Since I want the caller to be able to spit out the things in a variables file, for instance.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cloudspin/stack/terraform.rb', line 12 def initialize( working_folder: '.', terraform_variables: {}, terraform_init_arguments: {}, terraform_command_arguments: {} ) @working_folder = working_folder # @terraform_variables = terraform_variables @terraform_variables = {} @terraform_init_arguments = terraform_init_arguments @base_terraform_command_arguments = terraform_command_arguments end |
Instance Method Details
#down ⇒ Object
58 59 60 61 62 63 |
# File 'lib/cloudspin/stack/terraform.rb', line 58 def down Dir.chdir(@working_folder) do terraform_init RubyTerraform.destroy(terraform_command_arguments(force: true)) end end |
#down_dry ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/cloudspin/stack/terraform.rb', line 65 def down_dry down_command = RubyTerraform::Commands::Destroy.new command_line_builder = down_command.instantiate_builder configured_command = down_command.configure_command(command_line_builder, terraform_command_arguments) built_command = configured_command.build "cd #{@working_folder} && #{built_command.to_s}" end |
#init ⇒ Object
84 85 86 87 88 |
# File 'lib/cloudspin/stack/terraform.rb', line 84 def init Dir.chdir(@working_folder) do terraform_init end end |
#init_dry ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cloudspin/stack/terraform.rb', line 90 def init_dry init_command = RubyTerraform::Commands::Init.new command_line_builder = init_command.instantiate_builder configured_command = init_command.configure_command( command_line_builder, @terraform_init_arguments ) built_command = configured_command.build "cd #{@working_folder} && #{built_command.to_s}" end |
#plan(plan_destroy: false) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/cloudspin/stack/terraform.rb', line 25 def plan(plan_destroy: false) Dir.chdir(@working_folder) do terraform_init RubyTerraform.plan(terraform_command_arguments(destroy: plan_destroy)) end end |
#plan_dry(plan_destroy: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloudspin/stack/terraform.rb', line 32 def plan_dry(plan_destroy: false) plan_command = RubyTerraform::Commands::Plan.new command_line_builder = plan_command.instantiate_builder configured_command = plan_command.configure_command( command_line_builder, terraform_command_arguments(:destroy => plan_destroy) ) built_command = configured_command.build "cd #{@working_folder} && #{built_command.to_s}" end |
#refresh ⇒ Object
73 74 75 76 77 78 |
# File 'lib/cloudspin/stack/terraform.rb', line 73 def refresh Dir.chdir(@working_folder) do terraform_init RubyTerraform.refresh(terraform_command_arguments(force: true)) end end |
#terraform_command_arguments(added_parameters = {}) ⇒ Object
KSM: Do we have this here, or do we munge all this up in the calling method and just pass in the processed list of arguments? For that matter, should we just call each of the actions on this class as static methods? Does this class really need to hold any kind of state?
106 107 108 109 110 |
# File 'lib/cloudspin/stack/terraform.rb', line 106 def terraform_command_arguments(added_parameters = {}) @base_terraform_command_arguments.merge({ vars: @terraform_variables }).merge(added_parameters) end |
#terraform_init ⇒ Object
80 81 82 |
# File 'lib/cloudspin/stack/terraform.rb', line 80 def terraform_init RubyTerraform.init(@terraform_init_arguments) end |
#up ⇒ Object
43 44 45 46 47 48 |
# File 'lib/cloudspin/stack/terraform.rb', line 43 def up Dir.chdir(@working_folder) do terraform_init RubyTerraform.apply(terraform_command_arguments(auto_approve: true)) end end |
#up_dry ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/cloudspin/stack/terraform.rb', line 50 def up_dry up_command = RubyTerraform::Commands::Apply.new command_line_builder = up_command.instantiate_builder configured_command = up_command.configure_command(command_line_builder, terraform_command_arguments) built_command = configured_command.build "cd #{@working_folder} && #{built_command.to_s}" end |