lib/terraforming/cli.rb in terraforming-0.1.3 vs lib/terraforming/cli.rb in terraforming-0.1.4
- old
+ new
@@ -124,22 +124,37 @@
end
private
def execute(klass, options)
- result = if options[:tfstate]
- tfstate(klass, options[:merge])
- else
- klass.tf
- end
-
+ result = options[:tfstate] ? tfstate(klass, options[:merge]) : tf(klass)
puts result
end
+ def tf(klass)
+ klass.tf
+ end
+
def tfstate(klass, tfstate_path)
- return klass.tfstate unless tfstate_path
+ tfstate = tfstate_path ? JSON.parse(open(tfstate_path).read) : tfstate_skeleton
+ tfstate["serial"] = tfstate["serial"] + 1
+ tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(klass.tfstate)
+ JSON.pretty_generate(tfstate)
+ end
- tfstate_base = JSON.parse(open(tfstate_path).read)
- klass.tfstate(tfstate_base: tfstate_base)
+ def tfstate_skeleton
+ {
+ "version" => 1,
+ "serial" => 0,
+ "modules" => [
+ {
+ "path" => [
+ "root"
+ ],
+ "outputs" => {},
+ "resources" => {},
+ }
+ ]
+ }
end
end
end