lib/terraforming/util.rb in terraforming-0.0.5 vs lib/terraforming/util.rb in terraforming-0.1.0
- old
+ new
@@ -15,24 +15,39 @@
def template_path(template_name)
File.join(File.expand_path(File.dirname(__FILE__)), "template", template_name) << ".erb"
end
- def generate_tfstate(resources)
- tfstate = {
+ def generate_tfstate(resources, tfstate_base = nil)
+ tfstate = tfstate_base || tfstate_skeleton
+ tfstate["serial"] = tfstate["serial"] + 1
+ tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(resources)
+ JSON.pretty_generate(tfstate)
+ end
+
+ def prettify_policy(policy_document, breakline = false)
+ json = JSON.pretty_generate(JSON.parse(CGI.unescape(policy_document)))
+
+ if breakline
+ json[-1] != "\n" ? json << "\n" : json
+ else
+ json.strip
+ end
+ end
+
+ def tfstate_skeleton
+ {
"version" => 1,
- "serial" => 1,
+ "serial" => 0,
"modules" => [
{
"path" => [
"root"
],
"outputs" => {},
- "resources" => resources
+ "resources" => {},
}
]
}
-
- JSON.pretty_generate(tfstate)
end
end
end