diff --git a/api/resource.rb b/api/resource.rb index 30cb4acf2257..6ce933b2a936 100644 --- a/api/resource.rb +++ b/api/resource.rb @@ -424,6 +424,7 @@ def full_delete_url def regex_url self_link_url.join.gsub('{{project}}', '.*') .gsub('{{name}}', '[a-z1-9\-]*') + .gsub('{{zone}}', '[a-z1-9\-]*') end private diff --git a/build/chef/compute b/build/chef/compute index 0f1920deaa0d..34798efef265 160000 --- a/build/chef/compute +++ b/build/chef/compute @@ -1 +1 @@ -Subproject commit 0f1920deaa0d562c4162dd8afd79dcf49d2e4e0c +Subproject commit 34798efef265bde56ccf79ded90d800978f52cc9 diff --git a/build/chef/container b/build/chef/container index 941cbba4fd14..fefb9e56c60d 160000 --- a/build/chef/container +++ b/build/chef/container @@ -1 +1 @@ -Subproject commit 941cbba4fd142af7be0a6213225c3cb125d5b577 +Subproject commit fefb9e56c60d1500f1443e253b7c73cddd3d0f42 diff --git a/build/chef/dns b/build/chef/dns index 9278cdab9eac..8f9c8e1ab98b 160000 --- a/build/chef/dns +++ b/build/chef/dns @@ -1 +1 @@ -Subproject commit 9278cdab9eac5580e5d3598b4d6f594f122c3cdf +Subproject commit 8f9c8e1ab98bb513a43a70518af0c8a191b03799 diff --git a/build/chef/iam b/build/chef/iam index b99f379602e6..7c1fd7f26210 160000 --- a/build/chef/iam +++ b/build/chef/iam @@ -1 +1 @@ -Subproject commit b99f379602e6cf8d1f49cb3b110fd49328113739 +Subproject commit 7c1fd7f262104a4c4c8ab3ab51521789d5adba30 diff --git a/build/chef/spanner b/build/chef/spanner index a40f609a99bb..7a6c5be4ac0c 160000 --- a/build/chef/spanner +++ b/build/chef/spanner @@ -1 +1 @@ -Subproject commit a40f609a99bbc367a655fea0ea30dfd3ae383001 +Subproject commit 7a6c5be4ac0c0353c134a967c4765e1ce2872043 diff --git a/build/chef/sql b/build/chef/sql index 25cf4fd2e5c9..aa8c1862a3e2 160000 --- a/build/chef/sql +++ b/build/chef/sql @@ -1 +1 @@ -Subproject commit 25cf4fd2e5c943a11472951bdb42436784026f1f +Subproject commit aa8c1862a3e2ae8c81b750641d6854e8f6a826b8 diff --git a/build/chef/storage b/build/chef/storage index 179d422314f3..0ecd8667e217 160000 --- a/build/chef/storage +++ b/build/chef/storage @@ -1 +1 @@ -Subproject commit 179d422314f3793c6242be42bfb30359cc5c557c +Subproject commit 0ecd8667e217877f3fe2633a85128df9a6f79aab diff --git a/build/terraform b/build/terraform index 46001de06d3c..f05d62c89e2a 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 46001de06d3cc532a18cd86854ffd316a4338498 +Subproject commit f05d62c89e2abf3cc2fd75a52715b88c62db4ab0 diff --git a/templates/chef/property/resourceref.rb.erb b/templates/chef/property/resourceref.rb.erb index d9faafd1bead..9a7585e873eb 100644 --- a/templates/chef/property/resourceref.rb.erb +++ b/templates/chef/property/resourceref.rb.erb @@ -12,15 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. <% end -%> -<% if emit_array -%> -require 'google/<%= prop_ns_dir -%>/property/array' -<% end -%> <%# Requires: resource - name of resource being fetched -%> <%# imports - name of property being fetched -%> <%= compile('templates/license.erb') -%> <%= lines(autogen_notice :ruby) -%> +<% if emit_array -%> +require 'google/<%= prop_ns_dir -%>/property/array' +<% end -%> + module Google module <%= product_ns %> module Data @@ -61,8 +62,9 @@ module Google :disabled), 6)) -%> class <%= class_name %>Catalog < <%= class_name %> - def initialize(title) + def initialize(title, parent_resource) @title = title + @parent_resource = parent_resource end # Chef requires the title for autorequiring @@ -84,6 +86,25 @@ module Google Chef.run_context.resource_collection.each do |entry| return entry.exports[:<%= imports -%>] if entry.name == @title end + +<%# Readonly ResourceRefs should regex check + assemble from shortnames for selflinks +If the user inputs a shortname e.g. 'n1-standard-1' we can assemble that into a full URL +based off of the parent's project and zone. -%> +<% if property.resource_ref.readonly && property.imports == 'selfLink' -%> + + unless /<%= property.resource_ref.regex_url.gsub('/', '\/') -%>/.match(@title) + # We'll assemble the self_link for the user if a full URL was not specified + # We need to retrieve attributes from the parent resource to qualify the URL + if @parent_resource.nil? + raise "Cannot find parent resource for resource #{@title}" + end + return "<%= property.resource_ref.self_link_url.join + .gsub('{{name}}', '#{@title}') + .gsub('{{project}}', '#{@parent_resource.project}') + .gsub('{{zone}}', '#{@parent_resource.zone}') + -%>" + end +<% end # if resource_ref.readonly && selfLink -%> <% if property.resource_ref.readonly -%> @title <% else -%> @@ -120,16 +141,19 @@ module Google module Property # A class to manage fetching <%= imports -%> from a <%= resource %> class <%= class_name %> -<%= emit_coerce(product_ns, class_name, 8) -%> - def catalog_parse(value) + def self.coerce + ->(parent_resource, value) { <%= "::Google::#{product_ns}::Property::#{class_name}"%>.catalog_parse(value, parent_resource) } + end + + def catalog_parse(value, parent_resource = nil) return if value.nil? - self.class.catalog_parse(value) + self.class.catalog_parse(value, parent_resource) end - def self.catalog_parse(value) + def self.catalog_parse(value, parent_resource = nil) return if value.nil? return value if value.is_a? Data::<%= class_name %> - Data::<%= class_name %>Catalog.new(value) + Data::<%= class_name %>Catalog.new(value, parent_resource) end # Used for fetched JSON values @@ -145,11 +169,11 @@ module Google class <%= class_name %>Array < Google::<%= product_ns -%>::Property::Array <%= emit_coerce(product_ns, "#{class_name}Array", 8) -%> # Used for parsing Chef catalog - def self.catalog_parse(value) + def self.catalog_parse(value, parent_resource = nil) return if value.nil? - return <%= class_name %>.catalog_parse(value) \ + return <%= class_name %>.catalog_parse(value, parent_resource) \ unless value.is_a?(::Array) - value.map { |v| <%= class_name %>.catalog_parse(v) } + value.map { |v| <%= class_name %>.catalog_parse(v, parent_resource) } end # Used for parsing GCP API responses