# Copyright 2018 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# These files contains code that needs to be compiled before being delivered to
# the final module tree structure:
<%
  dir = @target_version_name == 'ga' ? 'google' : "google-#{@target_version_name}"
-%>

# Compile all of the terraform resources that are still hand written into the specific service folder
<% Dir["third_party/terraform/services/**"].each do |product_path|
  product_name = product_path.split('/')[-1]
  Dir[product_path + "/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/services/<%= product_name -%>/<%= fname.delete_suffix(".erb") -%>': '<%= product_path -%>/<%= fname -%>'
<% end -%>
<% end -%>

<%
  Dir["third_party/terraform/acctest/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/acctest/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/acctest/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/provider/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/provider/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/provider/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/tpgiamresource/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/tpgiamresource/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/tpgiamresource/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/tpgresource/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/tpgresource/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/tpgresource/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/fwmodels/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/fwmodels/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/fwmodels/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/fwprovider/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/fwprovider/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/fwprovider/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/fwtransport/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/fwtransport/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/fwtransport/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/sweeper/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/sweeper/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/sweeper/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/transport/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/transport/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/transport/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/verify/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/verify/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/verify/<%= fname -%>'
<% end -%>

<%
  Dir["third_party/terraform/framework_models/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/framework_models/<%= fname -%>'
<% end -%>
<%
  Dir["third_party/terraform/functions/*.go.erb"].each do |file_path|
    fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/functions/<%= fname.delete_suffix(".erb") -%>': 'third_party/terraform/functions/<%= fname -%>'
<% end -%>
<%
  Dir["third_party/terraform/scripts/**/*.erb"].each do |file_path|
    fname = file_path.delete_prefix("third_party/terraform/")
-%>
'<%= fname.delete_suffix(".erb") -%>': '<%= file_path -%>'
<% end -%>
'main.go': 'third_party/terraform/main.go.erb'
'go.mod': 'third_party/terraform/go.mod.erb'
'.goreleaser.yml': 'third_party/terraform/.goreleaser.yml.erb'
'terraform-registry-manifest.json': 'third_party/terraform/terraform-registry-manifest.json.erb'
'.release/release-metadata.hcl': 'third_party/terraform/release-metadata.hcl.erb'
'.copywrite.hcl': 'third_party/terraform/.copywrite.hcl.erb'