From cd1161a94d11c2375a32d422cd59e165a35d8814 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Fri, 8 Dec 2023 11:48:34 -0800 Subject: [PATCH] Remove usage of terraform_config --- mmv1/compile/core.rb | 2 +- mmv1/compiler.rb | 48 ++------------------- mmv1/provider/file_template.rb | 5 +-- mmv1/provider/terraform.rb | 26 +---------- mmv1/provider/terraform/config.rb | 25 ----------- mmv1/spec/data/terraform-config.yaml | 15 ------- mmv1/spec/hashicorp_copyright_spec.rb | 3 +- mmv1/spec/provider_terraform_import_spec.rb | 7 +-- mmv1/spec/provider_terraform_spec.rb | 6 +-- 9 files changed, 10 insertions(+), 127 deletions(-) delete mode 100644 mmv1/provider/terraform/config.rb delete mode 100644 mmv1/spec/data/terraform-config.yaml diff --git a/mmv1/compile/core.rb b/mmv1/compile/core.rb index 2bdcf89f18be..e1627384e0b6 100644 --- a/mmv1/compile/core.rb +++ b/mmv1/compile/core.rb @@ -38,7 +38,7 @@ def include(file) # that the provider writer wants to expose to the template can be made # available through the bindings. # - # This allows for exposing instance variables, such as @api and config, or + # This allows for exposing instance variables, such as @api, or # provider or function specific data, such as output_folder. Functions such # as Provider::Core::generate_file() or Provider::Core::compile_file() can # allow providers to generate such bindings (by passing them in a Hash to diff --git a/mmv1/compiler.rb b/mmv1/compiler.rb index 3b58de03fe6c..079eb2937b0d 100755 --- a/mmv1/compiler.rb +++ b/mmv1/compiler.rb @@ -144,8 +144,6 @@ # so lets build it first all_product_files = all_product_files.sort_by { |product| product == 'products/compute' ? 0 : 1 } -# products_for_version entries are a hash of product definitions (:definitions) -# and provider config (:overrides) for the product # rubocop:disable Metrics/BlockLength products_for_version = Parallel.map(all_product_files, in_processes: 8) do |product_name| product_override_path = '' @@ -156,11 +154,6 @@ api_override_path = File.join(override_dir, product_name, 'api.yaml') if override_dir api_yaml_path = File.join(product_name, 'api.yaml') - # provider_override_path = '' - # provider_override_path = File.join(override_dir, product_name, "#{provider_name}.yaml") \ - # if override_dir - # provider_yaml_path = File.join(product_name, "#{provider_name}.yaml") - unless File.exist?(product_yaml_path) || File.exist?(product_override_path) \ || File.exist?(api_yaml_path) || File.exist?(api_override_path) raise "#{product_name} does not contain an api.yaml or product.yaml file" @@ -188,14 +181,6 @@ product_yaml = File.read(product_yaml_path) end - # unless File.exist?(provider_yaml_path) || File.exist?(provider_override_path) - # unless File.exist?(product_yaml_path) || File.exist?(product_override_path) - # Google::LOGGER.info "#{product_name}: Skipped as no #{provider_name}.yaml file exists" - # next - # end - # provider_yaml_path = 'templates/terraform.yaml' - # end - raise "Output path '#{output_path}' does not exist or is not a directory" \ unless Dir.exist?(output_path) @@ -209,8 +194,6 @@ next end - Google::LOGGER.info "#{product_yaml_path}: product_yaml_path" - if File.exist?(product_yaml_path) || File.exist?(product_override_path) resources = [] Dir["#{product_name}/*"].each do |file_path| @@ -264,33 +247,11 @@ product_api.set_variable(resources, 'objects') end - # Google::LOGGER.info "#{provider_yaml_path}: provider_yaml_path" - # Google::LOGGER.info "#{provider_override_path}: provider_override_path" - - # Google::LOGGER.info "#{product_api}: Compiling provider config product_api 0" - - # if File.exist?(provider_yaml_path) - # product_api, provider_config, = \ - # Provider::Config.parse(provider_yaml_path, product_api, version) - # end - # # Load any dynamic overrides passed in with -r - # if File.exist?(provider_override_path) - # product_api, provider_config, = \ - # Provider::Config.parse(provider_override_path, product_api, version, override_dir) - # end - - provider_config = nil product_api&.validate - # Google::LOGGER.info "#{product_api}: Compiling provider config product_api" - # Google::LOGGER.info "#{provider_config}: Compiling provider config provider_config" - - Google::LOGGER.info "#{product_name}: Compiling provider config" - # pp provider_config if ENV['COMPILER_DEBUG'] - if force_provider.nil? provider = \ - Provider::Terraform.new(provider_config, product_api, version, start_time) + Provider::Terraform.new(product_api, version, start_time) else override_providers = { 'oics' => Provider::TerraformOiCS, @@ -307,12 +268,12 @@ end provider = \ - override_providers[force_provider].new(provider_config, product_api, version, start_time) + override_providers[force_provider].new(product_api, version, start_time) end unless products_to_generate.include?(product_name) Google::LOGGER.info "#{product_name}: Not specified, skipping generation" - next { definitions: product_api, overrides: provider_config, provider: provider } # rubocop:disable Style/HashSyntax + next { definitions: product_api, provider: provider } # rubocop:disable Style/HashSyntax end Google::LOGGER.info \ @@ -326,9 +287,8 @@ generate_docs ) - # provider_config is mutated by instantiating a provider. # we need to preserve a single provider instance to use outside of this loop. - { definitions: product_api, overrides: provider_config, provider: provider } # rubocop:disable Style/HashSyntax + { definitions: product_api, provider: provider } # rubocop:disable Style/HashSyntax end products_for_version = products_for_version.compact # remove any nil values diff --git a/mmv1/provider/file_template.rb b/mmv1/provider/file_template.rb index 33845a370a56..b1c6e4e88430 100644 --- a/mmv1/provider/file_template.rb +++ b/mmv1/provider/file_template.rb @@ -123,8 +123,6 @@ def initialize(output_folder, version, env, products, override_path = nil) class ProductFileTemplate < Provider::FileTemplate # The name of the resource attr_accessor :name - # The provider-specific configuration. - attr_accessor :config # The namespace of the product. attr_accessor :product_ns # The resource itself. @@ -134,10 +132,9 @@ class ProductFileTemplate < Provider::FileTemplate class << self # Construct a new ProductFileTemplate based on a resource object - def file_for_resource(output_folder, object, version, config, env) + def file_for_resource(output_folder, object, version, env) file_template = new(output_folder, object.name, object.__product, version, env) file_template.object = object - file_template.config = config file_template end end diff --git a/mmv1/provider/terraform.rb b/mmv1/provider/terraform.rb index 5eb250709831..2c1c7373f83c 100644 --- a/mmv1/provider/terraform.rb +++ b/mmv1/provider/terraform.rb @@ -18,7 +18,6 @@ require 'json' require 'provider/file_template' require 'provider/terraform/async' -require 'provider/terraform/config' require 'provider/terraform/import' require 'provider/terraform/custom_code' require 'provider/terraform/docs' @@ -42,8 +41,7 @@ class Terraform RESOURCE_DIRECTORY_BETA = 'google-beta'.freeze RESOURCE_DIRECTORY_PRIVATE = 'google-private'.freeze - def initialize(config, api, version_name, start_time) - @config = config + def initialize(api, version_name, start_time) @api = api # @target_version_name is the version specified by MM for this generation @@ -85,15 +83,6 @@ def check_goformat def generate(output_folder, types, product_path, dump_yaml, generate_code, generate_docs) generate_objects(output_folder, types, generate_code, generate_docs) - # Compilation has to be the last step, as some files (e.g. - # CONTRIBUTING.md) may depend on the list of all files previously copied - # or compiled. - # common-compile.yaml is a special file that will get compiled by the last product - # used in a single invocation of the compiled. It should not contain product-specific - # information; instead, it should be run-specific such as the version to compile at. - # compile_product_files(output_folder) \ - # unless @config.files.nil? || @config.files.compile.nil? - FileUtils.mkpath output_folder pwd = Dir.pwd if generate_code @@ -159,18 +148,6 @@ def copy_file_list(output_folder, files) end.map(&:join) end - # Compiles files specified within the product - # def compile_product_files(output_folder) - # file_template = ProductFileTemplate.new( - # output_folder, - # nil, - # @api, - # @target_version_name, - # build_env - # ) - # compile_file_list(output_folder, @config.files.compile, file_template) - # end - # Compiles files that are shared at the provider level def compile_common_files( output_folder, @@ -793,7 +770,6 @@ def build_object_data(_pwd, object, output_folder, version) output_folder, object, version, - @config, build_env ) end diff --git a/mmv1/provider/terraform/config.rb b/mmv1/provider/terraform/config.rb deleted file mode 100644 index da665c17eb21..000000000000 --- a/mmv1/provider/terraform/config.rb +++ /dev/null @@ -1,25 +0,0 @@ -# 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. - -# require 'provider/config' - -module Provider - class Terraform - # Settings for the provider - class Config - def provider - Provider::Terraform - end - end - end -end diff --git a/mmv1/spec/data/terraform-config.yaml b/mmv1/spec/data/terraform-config.yaml deleted file mode 100644 index 105333b37016..000000000000 --- a/mmv1/spec/data/terraform-config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# 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. - ---- !ruby/object:Provider::Terraform::Config -files: !ruby/object:Provider::Config::Files diff --git a/mmv1/spec/hashicorp_copyright_spec.rb b/mmv1/spec/hashicorp_copyright_spec.rb index ea09907fba94..d05e38c66c6e 100644 --- a/mmv1/spec/hashicorp_copyright_spec.rb +++ b/mmv1/spec/hashicorp_copyright_spec.rb @@ -16,12 +16,11 @@ describe 'Provider::Core.expected_output_folder?' do # Inputs for tests - config = 'foo' api = Api::Compiler.new(File.read('spec/data/good-file.yaml')).run version_name = 'ga' start_time = Time.now - provider = Provider::Terraform.new(config, api, version_name, start_time) + provider = Provider::Terraform.new(api, version_name, start_time) # rubocop:disable Layout/LineLength it 'should identify `terraform-provider-google` as an expected output folder' do diff --git a/mmv1/spec/provider_terraform_import_spec.rb b/mmv1/spec/provider_terraform_import_spec.rb index ba8a930c602b..2fa53bf2db07 100644 --- a/mmv1/spec/provider_terraform_import_spec.rb +++ b/mmv1/spec/provider_terraform_import_spec.rb @@ -24,16 +24,11 @@ class << self describe Provider::Terraform do context 'static' do let(:product) { Api::Compiler.new(File.read('spec/data/good-file.yaml')).run } - let(:config) do - Provider::Config.parse('spec/data/terraform-config.yaml', product)[1] - end - let(:provider) { Provider::Terraform.new(config, product, 'ga', Time.now) } + let(:provider) { Provider::Terraform.new(product, 'ga', Time.now) } before do allow_open 'spec/data/good-file.yaml' - allow_open 'spec/data/terraform-config.yaml' product.validate - config.validate end describe '#import_id_formats_from_resource' do diff --git a/mmv1/spec/provider_terraform_spec.rb b/mmv1/spec/provider_terraform_spec.rb index e15684aba6ba..9e58c78c87df 100644 --- a/mmv1/spec/provider_terraform_spec.rb +++ b/mmv1/spec/provider_terraform_spec.rb @@ -23,9 +23,7 @@ class << self describe Provider::Terraform do context 'good file product' do let(:product) { Api::Compiler.new(File.read('spec/data/good-file.yaml')).run } - let(:parsed) { Provider::Config.parse('spec/data/terraform-config.yaml', product) } - let(:config) { parsed[1] } - let(:provider) { Provider::Terraform.new(config, product, 'ga', Time.now) } + let(:provider) { Provider::Terraform.new(product, 'ga', Time.now) } let(:resource) { product.objects[0] } let(:override_resource) do product.objects.find { |o| o.name == 'ThirdResource' } @@ -33,9 +31,7 @@ class << self before do allow_open 'spec/data/good-file.yaml' - allow_open 'spec/data/terraform-config.yaml' product.validate - config.validate end describe '#format2regex' do