Skip to content

Commit

Permalink
Remove usage of terraform_config
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 committed Dec 8, 2023
1 parent 8c28d4d commit 7201450
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 127 deletions.
2 changes: 1 addition & 1 deletion mmv1/compile/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 4 additions & 44 deletions mmv1/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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|
Expand Down Expand Up @@ -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,
Expand All @@ -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 \
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions mmv1/provider/file_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
26 changes: 1 addition & 25 deletions mmv1/provider/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -793,7 +770,6 @@ def build_object_data(_pwd, object, output_folder, version)
output_folder,
object,
version,
@config,
build_env
)
end
Expand Down
25 changes: 0 additions & 25 deletions mmv1/provider/terraform/config.rb

This file was deleted.

15 changes: 0 additions & 15 deletions mmv1/spec/data/terraform-config.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions mmv1/spec/hashicorp_copyright_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions mmv1/spec/provider_terraform_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions mmv1/spec/provider_terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ 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' }
end

before do
allow_open 'spec/data/good-file.yaml'
allow_open 'spec/data/terraform-config.yaml'
product.validate
config.validate
end

describe '#format2regex' do
Expand Down

0 comments on commit 7201450

Please sign in to comment.