terraform-template-renderer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +24 -0
- data/Rakefile +6 -0
- data/bin/rake +21 -0
- data/bin/rspec +21 -0
- data/exe/render-template +38 -0
- data/lib/terraform_template_renderer.rb +3 -0
- data/lib/terraform_template_renderer/binding.rb +11 -0
- data/lib/terraform_template_renderer/renderer.rb +28 -0
- data/lib/terraform_template_renderer/version.rb +3 -0
- data/terraform-template-renderer.gemspec +35 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cef4859595c7d96c5122dbe5b058da92806f7905
|
4
|
+
data.tar.gz: 162af8691305d44a0cb024d1f2ceac8efe83a5a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e221e4184fa8e12e9ce5c0c850071bcdf1a5a84e734872790ba3cb5250112f08547babeab991e13a951aa5246e6d1099c13d310ab4ad0562876446657b13870d
|
7
|
+
data.tar.gz: 372ebfe28e1e7d077c0ea60ed8827410e4d1a6c45c17c39721a684b5af8a025c3ea016ff4b39823baf8c1f4d21839aa38e1eec14d8b602d787c5d320e889f87a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 119
|
3
|
+
Exclude:
|
4
|
+
- "spec/**/*"
|
5
|
+
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Exclude:
|
8
|
+
- "spec/**/*"
|
9
|
+
|
10
|
+
RSpec/ExampleLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
RSpec/LetSetup:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/DotPosition:
|
17
|
+
EnforcedStyle: trailing
|
18
|
+
|
19
|
+
Style/SingleLineBlockParams:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/StringLiterals:
|
23
|
+
EnforcedStyle: double_quotes
|
24
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jonathan Harden
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# terraform-template-renderer
|
2
|
+
|
3
|
+
Provides a ruby executable which will take a path to an ERB template as it's only positional argument and render that
|
4
|
+
with a json blob passed in to STDIN. The keys in the json blob will be used as instance variable names to use in the
|
5
|
+
template.
|
6
|
+
|
7
|
+
The result will be returned inside a json blob with a single key, the name of which is rendered.
|
8
|
+
|
9
|
+
For example if your template is
|
10
|
+
|
11
|
+
Hello <%= @my_key %>!
|
12
|
+
|
13
|
+
And you execute the command as:
|
14
|
+
|
15
|
+
echo '{ "my_key": "dear reader" }' | template_renderer path_to_my_template
|
16
|
+
|
17
|
+
You will produce
|
18
|
+
|
19
|
+
{ "rendered": "Hello dear reader!" }
|
20
|
+
|
21
|
+
The purpose for this strange behaviour is to be a [terraform external
|
22
|
+
provider](https://www.terraform.io/docs/providers/external/data_source.html) to render arbitrarily complex templates,
|
23
|
+
terraform passes in the variables to render as a json blob to stdin as described above and expects a json blob
|
24
|
+
back.
|
data/Rakefile
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
12
|
+
load(bundle_binstub) if File.file?(bundle_binstub)
|
13
|
+
|
14
|
+
require "pathname"
|
15
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
16
|
+
Pathname.new(__FILE__).realpath)
|
17
|
+
|
18
|
+
require "rubygems"
|
19
|
+
require "bundler/setup"
|
20
|
+
|
21
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
12
|
+
load(bundle_binstub) if File.file?(bundle_binstub)
|
13
|
+
|
14
|
+
require "pathname"
|
15
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
16
|
+
Pathname.new(__FILE__).realpath)
|
17
|
+
|
18
|
+
require "rubygems"
|
19
|
+
require "bundler/setup"
|
20
|
+
|
21
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/exe/render-template
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json"
|
5
|
+
require_relative "../lib/terraform_template_renderer"
|
6
|
+
|
7
|
+
def help
|
8
|
+
puts <<~EOF
|
9
|
+
Usage: render-template <path_to_erb_template>
|
10
|
+
|
11
|
+
Reads json blob with params from STDIN
|
12
|
+
EOF
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.empty?
|
16
|
+
STDERR.puts "You must supply the path to an ERB template as the first argument"
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
template_path = ARGV[0]
|
21
|
+
|
22
|
+
if ["-h", "--help", "-help", "help"].include?(template_path)
|
23
|
+
help
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
|
27
|
+
unless File.exist?(template_path)
|
28
|
+
STDERR.puts "ERB Template #{template_path} does not exist"
|
29
|
+
exit 2
|
30
|
+
end
|
31
|
+
|
32
|
+
template = File.read(template_path)
|
33
|
+
json_params = STDIN.read
|
34
|
+
|
35
|
+
renderer = TerraformTemplateRenderer::Renderer.new(template)
|
36
|
+
rendered_template = renderer.render(json_params)
|
37
|
+
json_output = { rendered: rendered_template }.to_json
|
38
|
+
puts json_output
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module TerraformTemplateRenderer
|
5
|
+
class Renderer
|
6
|
+
def initialize(template)
|
7
|
+
@erb_template = ERB.new(template)
|
8
|
+
end
|
9
|
+
|
10
|
+
# The passed in json_variables needs to be a JSON object (not array), all the keys will be used
|
11
|
+
# as variables in the templates
|
12
|
+
def render(json_variables)
|
13
|
+
@erb_template.result(template_binding(json_variables))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def template_binding(json_variables)
|
19
|
+
Binding.new.tap { |binding_object| add_params_to_object(binding_object, JSON.parse(json_variables)) }.bind
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_params_to_object(object, params)
|
23
|
+
params.each do |key, value|
|
24
|
+
object.add_param(key, value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "lib/terraform_template_renderer/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "terraform-template-renderer"
|
5
|
+
spec.version = TerraformTemplateRenderer::VERSION
|
6
|
+
spec.authors = ["Jonathan Harden"]
|
7
|
+
spec.email = ["jfharden@gmail.com"]
|
8
|
+
spec.license = "MIT"
|
9
|
+
spec.homepage = "http://github.com/jfharden/terraform-template-renderer"
|
10
|
+
|
11
|
+
spec.summary = "Renders an aribtrary erb template with passed in JSON variables"
|
12
|
+
spec.description = <<-DESCRIPTION
|
13
|
+
Will render an arbitrary erb template (passed as the first positional argument),
|
14
|
+
filling variables from a passed in JSON blob, the keys will be used as variable names
|
15
|
+
and the values their respective values.
|
16
|
+
|
17
|
+
The purpose of this GEM is to make it easy to render complex templates in terraform in
|
18
|
+
a modular and reusable way.
|
19
|
+
DESCRIPTION
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = "render-template"
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.required_ruby_version = ">= 2.3.0"
|
29
|
+
|
30
|
+
spec.add_development_dependency "aruba", "~> 0.14.3"
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
32
|
+
spec.add_development_dependency "pry-byebug", "~> 3.5"
|
33
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terraform-template-renderer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Harden
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aruba
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
description: |2
|
84
|
+
Will render an arbitrary erb template (passed as the first positional argument),
|
85
|
+
filling variables from a passed in JSON blob, the keys will be used as variable names
|
86
|
+
and the values their respective values.
|
87
|
+
|
88
|
+
The purpose of this GEM is to make it easy to render complex templates in terraform in
|
89
|
+
a modular and reusable way.
|
90
|
+
email:
|
91
|
+
- jfharden@gmail.com
|
92
|
+
executables:
|
93
|
+
- render-template
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".rubocop.yml"
|
100
|
+
- CHANGELOG.md
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- bin/rake
|
106
|
+
- bin/rspec
|
107
|
+
- exe/render-template
|
108
|
+
- lib/terraform_template_renderer.rb
|
109
|
+
- lib/terraform_template_renderer/binding.rb
|
110
|
+
- lib/terraform_template_renderer/renderer.rb
|
111
|
+
- lib/terraform_template_renderer/version.rb
|
112
|
+
- terraform-template-renderer.gemspec
|
113
|
+
homepage: http://github.com/jfharden/terraform-template-renderer
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 2.3.0
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.5.1
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Renders an aribtrary erb template with passed in JSON variables
|
137
|
+
test_files: []
|