lib/rspec/terraform/helpers/plan.rb in rspec-terraform-0.1.0.pre.37 vs lib/rspec/terraform/helpers/plan.rb in rspec-terraform-0.1.0.pre.38
- old
+ new
@@ -30,14 +30,12 @@
clean(parameters)
init(parameters)
plan_file = plan(parameters)
plan_contents = show(parameters, plan_file)
-
- RubyTerraform::Models::Plan.new(
- JSON.parse(plan_contents, symbolize_names: true)
- )
+ remove(parameters, plan_file)
+ parse(plan_contents)
end
private
def with_configuration_provider_parameters(parameters)
@@ -103,10 +101,22 @@
show_command(stdout: stdout)
.execute(show_parameters(parameters, plan_file))
stdout.string
end
+ def parse(plan_contents)
+ RubyTerraform::Models::Plan.new(
+ JSON.parse(plan_contents, symbolize_names: true)
+ )
+ end
+
+ def remove(parameters, plan_file)
+ FileUtils.rm_f(
+ File.join(parameters[:configuration_directory], plan_file)
+ )
+ end
+
def init_command
RubyTerraform::Commands::Init.new(binary: binary)
end
def plan_command
@@ -133,10 +143,11 @@
# rubocop:disable Metrics/MethodLength
def plan_parameters(parameters)
plan_parameters =
parameters.merge(
chdir: parameters[:configuration_directory],
- out: parameters[:plan_file_name] || SecureRandom.hex(10),
+ out: parameters[:plan_file_name] ||
+ "#{SecureRandom.hex[0, 10]}.tfplan",
input: false
)
if parameters[:state_file]
plan_parameters =