-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support non-cloud providers and backends
* decouple backend detection from plugins * expander backend detection that doesn't evaluate ERB * adjust default max retries for backend re-init to 1
- Loading branch information
Showing
5 changed files
with
68 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Simpler than Terraspace::Compiler::Backend::Parser because | ||
# Terraspace::Compiler::Expander autodetect backend super early on. | ||
# It's so early that don't want helper methods like <%= expansion(...) %> to be called. | ||
# Calling the expansion helper itself results in Terraspace autodetecting a concrete | ||
# Terraspace Plugin Expander, which creates an infinite loop. | ||
# This simple detection class avoids calling ERB and avoids the infinite loop. | ||
class Terraspace::Compiler::Expander | ||
class Backend | ||
extend Memoist | ||
|
||
def initialize(mod) | ||
@mod = mod | ||
end | ||
|
||
COMMENT = /^\s+#/ | ||
# Works for both backend.rb DSL and backend.tf ERB | ||
def detect | ||
lines = IO.readlines(src_path) | ||
backend_line = lines.find { |l| l.include?("backend") && l !~ COMMENT } | ||
md = backend_line.match(/['"](.*)['"]/) | ||
md[1] if md | ||
end | ||
|
||
private | ||
# Use original unrendered source as wont know the | ||
# @mod.cache_dir = ":CACHE_ROOT/:REGION/:ENV/:BUILD_DIR" | ||
# Until the concrete Terraspace Plugin Expander has been autodetected. | ||
# Follow same precedence rules as rest of Terraspace. | ||
def src_path | ||
exprs = [ | ||
"app/stacks/#{@mod.build_dir}/backend.*", | ||
"app/modules/#{@mod.build_dir}/backend.*", | ||
"vendor/stacks/#{@mod.build_dir}/backend.*", | ||
"vendor/modules/#{@mod.build_dir}/backend.*", | ||
"config/terraform/backend.*", | ||
] | ||
path = nil | ||
exprs.find { |expr| path = Dir.glob(expr).first } | ||
path | ||
end | ||
memoize :src_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters