class Terracop::PlanLoader
Loads a Terraform plan file and transforms it into a Terracop-friendly list of instances.
Public Class Methods
load(file)
click to toggle source
# File lib/terracop/plan_loader.rb, line 8 def load(file) plan = decode(file) changed_resources = plan['resource_changes'].reject! do |resource| resource['change']['actions'] == ['no-op'] || resource['change']['actions'] == ['delete'] end restruct_resources(changed_resources) end
Private Class Methods
decode(file)
click to toggle source
:nocov:
# File lib/terracop/plan_loader.rb, line 22 def decode(file) JSON.parse(`terraform show -json #{file}`) rescue JSON::ParserError puts 'Terraform failed to decode the plan file.' exit end
restruct_resources(resources)
click to toggle source
:nocov:
# File lib/terracop/plan_loader.rb, line 30 def restruct_resources(resources) resources.map do |resource| { type: resource['type'], name: resource['name'], index: resource['index'], attributes: resource['change']['after'] } end end