diff --git a/.ci/magic-modules/create-pr.sh b/.ci/magic-modules/create-pr.sh index 1bbc0ff74292..2aeb428f4438 100755 --- a/.ci/magic-modules/create-pr.sh +++ b/.ci/magic-modules/create-pr.sh @@ -83,7 +83,7 @@ else # PR, rather than create a new one. git branch -f "$ORIGINAL_PR_BRANCH" - if [ -z "$TERRAFORM_REPO_USER" ]; then + if [ -n "$TERRAFORM_REPO_USER" ]; then pushd build/terraform git branch -f "$ORIGINAL_PR_BRANCH" popd diff --git a/build/terraform b/build/terraform index b01028ffbee6..f2d67fd0dd8f 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit b01028ffbee66fd14305831df8b2832000cf72ae +Subproject commit f2d67fd0dd8f84ad1ff7ba5ed5555787b91e8ccb diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index c08a6c9feee2..6d2306a95323 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -401,7 +401,7 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: - # 'compiled_file': 'templates/terraform/compiled_file' + 'google/provider_{{product_name}}_gen.go': 'templates/terraform/provider_gen.erb' # This is for custom testing code. All of our tests follow a specific pattern # that sometimes needs to be deviated from. We're working towards a world where diff --git a/provider/core.rb b/provider/core.rb index 706c8d2585f6..2f2710f3ad3d 100644 --- a/provider/core.rb +++ b/provider/core.rb @@ -179,6 +179,8 @@ def compile_file_list(output_folder, files, data = {}) Google::LOGGER.info "Compiling #{source} => #{target}" target_file = File.join(output_folder, target) .gsub('{{product_name}}', @api.prefix[1..-1]) + + manifest = @config.respond_to?(:manifest) ? @config.manifest : {} generate_file( data.clone.merge( name: target, @@ -186,7 +188,7 @@ def compile_file_list(output_folder, files, data = {}) object: {}, config: {}, scopes: @api.scopes, - manifest: @config.manifest, + manifest: manifest, tests: '', template: source, generated_files: @generated, @@ -198,6 +200,10 @@ def compile_file_list(output_folder, files, data = {}) product_ns: Google::StringUtils.camelize(@api.prefix[1..-1], :upper) ) ) + + if File.extname(target_file) == '.go' + %x(goimports -w #{target_file}) + end end end # rubocop:enable Metrics/MethodLength diff --git a/templates/terraform/provider_gen.erb b/templates/terraform/provider_gen.erb new file mode 100644 index 000000000000..e4132f63a264 --- /dev/null +++ b/templates/terraform/provider_gen.erb @@ -0,0 +1,26 @@ +<% if false # the license inside this if block pertains to this file -%> +# Copyright 2017 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. +<% end -%> +<%= lines(autogen_notice :go) -%> + +package google + +import "github.com/hashicorp/terraform/helper/schema" + +var Generated<%= product_ns -%>ResourcesMap = map[string]*schema.Resource{ +<% product.objects.reject { |r| r.exclude }.each do |object| -%> +<% resource_name = product_ns + object.name -%> + "google_<%= Google::StringUtils.underscore(resource_name) -%>": resource<%= resource_name -%>(), +<% end -%> +}