Skip to content

Commit ae80102

Browse files
Fix terraform template name
1 parent 612ade6 commit ae80102

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

app/models/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ def sync
4646
# eg.
4747
# https://github.ibm.com/manoj-puthran/sample-scripts/tree/v2.0/terraform/templates/hello-world
4848
# is converted as
49-
# "hello-world(v2.0):github.ibm.com/manoj-puthran/sample-scripts/terraform/templates"
50-
def self.template_name_from_git_repo_url(git_repo_url, branch_name, relative_path)
49+
# templates/hello-world
50+
def self.template_name_from_git_repo_url(git_repo_url, relative_path)
5151
temp_url = git_repo_url
5252
# URI library cannot handle git urls, so just convert it to a standard url.
5353
temp_url = temp_url.sub(':', '/').sub('git@', 'https://') if temp_url.start_with?('git@')
5454
temp_uri = URI.parse(temp_url)
55-
hostname = temp_uri.hostname
5655
path = temp_uri.path
5756
path = path[0...-4] if path.end_with?('.git')
5857
path = path[0...-5] if path.end_with?('.git/')
@@ -64,7 +63,7 @@ def self.template_name_from_git_repo_url(git_repo_url, branch_name, relative_pat
6463
basename = File.basename(relative_path)
6564
parent_path = File.dirname(relative_path)
6665
end
67-
"#{basename}(#{branch_name}):#{hostname}#{path}/#{parent_path}"
66+
"#{parent_path}/#{basename}"
6867
end
6968

7069
private
@@ -87,7 +86,7 @@ def find_templates_in_git_repo
8786
.select { |_dir, files| files.any? { |f| f.end_with?(".tf", ".tf.json") } }
8887
.transform_values! { |files| files.map { |f| File.basename(f) } }
8988
.each do |parent_dir, files|
90-
name = self.class.template_name_from_git_repo_url(git_repository.url, scm_branch, parent_dir)
89+
name = self.class.template_name_from_git_repo_url(git_repository.url, parent_dir)
9190

9291
# TODO: add parsing for input/output vars
9392
input_vars = nil

spec/models/manageiq/providers/embedded_terraform/automation_manager/configuration_script_source_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def files_in_repository(git_repo_dir)
8282
names = names_and_payloads.collect(&:first)
8383
payloads = names_and_payloads.collect(&:second)
8484

85-
expect(names.first).to(eq("hello_world_local(master):#{local_repo}/"))
85+
expect(names.first).to(eq("/hello_world_local"))
8686

8787
expected_hash = {
8888
"relative_path" => File.dirname(*repo_dir_structure),
@@ -114,7 +114,7 @@ def files_in_repository(git_repo_dir)
114114
names = names_and_payloads.collect(&:first)
115115
payloads = names_and_payloads.collect(&:second)
116116

117-
expect(names.first).to(eq("hello-world(master):#{nested_repo}/templates"))
117+
expect(names.first).to(eq("templates/hello-world"))
118118

119119
expected_hash = {
120120
"relative_path" => File.dirname(*nested_repo_structure),
@@ -167,8 +167,8 @@ def files_in_repository(git_repo_dir)
167167
expect(names).to(
168168
eq(
169169
[
170-
"hello-world(master):#{multiple_templates_repo}/templates",
171-
"single-vm(master):#{multiple_templates_repo}/templates"
170+
"templates/hello-world",
171+
"templates/single-vm"
172172
]
173173
)
174174
)
@@ -213,7 +213,7 @@ def files_in_repository(git_repo_dir)
213213
names = names_and_payloads.collect(&:first)
214214
payloads = names_and_payloads.collect(&:second)
215215

216-
expect(names.first).to(eq("hello-world(master):#{nested_repo}/templates"))
216+
expect(names.first).to(eq("templates/hello-world"))
217217

218218
files = JSON.parse(payloads.first)["files"]
219219

@@ -241,15 +241,15 @@ def files_in_repository(git_repo_dir)
241241
record = build_record
242242

243243
names = record.configuration_script_payloads.pluck(:name)
244-
expect(names).to(match_array(["hello-world(master):#{nested_repo}/templates"]))
244+
expect(names).to(match_array(["templates/hello-world"]))
245245
end
246246
end
247247
end
248248

249249
describe "#template_name_from_git_repo_url" do
250-
let(:git_url_branch_path) { ["git@example.com:manoj-puthran/sample-scripts.git", "v2.0", "terraform/templates/hello-world"] }
251-
let(:https_url_branch_path) { ["https://example.com/manoj-puthran/sample-scripts.git", "v2.0", "terraform/templates/hello-world"] }
252-
let(:expected_result) { "hello-world(v2.0):example.com/manoj-puthran/sample-scripts/terraform/templates" }
250+
let(:git_url_branch_path) { ["git@example.com:manoj-puthran/sample-scripts.git", "terraform/templates/hello-world"] }
251+
let(:https_url_branch_path) { ["https://example.com/manoj-puthran/sample-scripts.git", "terraform/templates/hello-world"] }
252+
let(:expected_result) { "terraform/templates/hello-world" }
253253

254254
it "supports https urls" do
255255
expect(described_class.template_name_from_git_repo_url(*https_url_branch_path)).to(eq(expected_result))
@@ -279,7 +279,7 @@ def files_in_repository(git_repo_dir)
279279
names = names_and_payloads.collect(&:first)
280280
payloads = names_and_payloads.collect(&:second)
281281

282-
expect(names.first).to(eq("hello_world_local(other_branch):#{local_repo}/"))
282+
expect(names.first).to(eq("/hello_world_local"))
283283

284284
expected_hash = {
285285
"relative_path" => File.dirname(*repo_dir_structure),

0 commit comments

Comments
 (0)