Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autogenerate provider-compute-gen.go file #132

Merged
merged 5 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/magic-modules/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion provider/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,16 @@ 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,
product: @api,
object: {},
config: {},
scopes: @api.scopes,
manifest: @config.manifest,
manifest: manifest,
tests: '',
template: source,
generated_files: @generated,
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions templates/terraform/provider_gen.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
}