Skip to content

Commit 9ec2097

Browse files
committed
Fixing resource imports
1 parent 332c368 commit 9ec2097

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

provider/inspec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def emit_nested_object_overrides(data)
9494
end
9595

9696
def primitive? (property)
97-
return property.is_a?(::Api::Type::Primitive) || (property.is_a?(Api::Type::Array) && !property.item_type.is_a?(::Api::Type::NestedObject))
97+
array_nested = (property.is_a?(Api::Type::Array) && !property.item_type.is_a?(::Api::Type::NestedObject))
98+
map = property.is_a?(::Api::Type::NameValues)
99+
return property.is_a?(::Api::Type::Primitive) || array_nested || map
98100
end
99101

100102
def resource_ref? (property)
@@ -117,6 +119,12 @@ def generate_requires(properties, requires = [])
117119
requires
118120
end
119121

122+
# InSpec doesn't need wrappers for primitives, so exclude them
123+
def emit_requires(requires)
124+
primitives = ['boolean', 'enum', 'string', 'time', 'integer', 'array', 'string_array', 'double']
125+
requires.flatten.sort.uniq.reject{|r| primitives.include?(r.split('/').last)}.map { |r| "require '#{r}'" }.join("\n")
126+
end
127+
120128
def plural(word)
121129
# TODO use a real ruby gem for this? Pluralization is hard
122130
if word[-1] == 's'

templates/inspec/nested_object.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Google
3232
return nil if args.nil?
3333
<% nested_properties.each do |prop| -%>
3434
<%
35-
if primitive?(prop)
35+
if primitive?(prop) || resource_ref?(prop)
3636
init = "args['#{prop.api_name}']"
3737
elsif typed_array?(prop)
3838
init = "#{prop.property_type}.parse(args['#{prop.api_name}'])"

templates/inspec/plural_resource.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ name = "google_#{product_ns.downcase}_#{object.name.underscore}"
2323
-%>
2424
name '<%= plural(name) -%>'
2525
desc '<%= object.name -%> plural resource'
26-
supports platform: 'gcp-mm'
26+
supports platform: 'gcp2'
2727

2828
filter_table_config = FilterTable.create
2929
<% object.all_user_properties.each do |prop| -%>

templates/inspec/singular_resource.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class <%= object.name -%> < Inspec.resource(1)
3737

3838
name 'google_<%= product_ns.downcase -%>_<%= object.name.underscore -%>'
3939
desc '<%= object.name -%>'
40-
supports platform: 'gcp-mm'
40+
supports platform: 'gcp2'
4141

4242
<% object.properties.reject(&:input).each do |prop| -%>
4343
<%= "attr_reader :#{prop.out_name}" -%>

0 commit comments

Comments
 (0)