diff --git a/mmv1/api/resource.rb b/mmv1/api/resource.rb index 1fd7d2a9711b..146995943246 100644 --- a/mmv1/api/resource.rb +++ b/mmv1/api/resource.rb @@ -647,6 +647,52 @@ def delete_uri end end + def resource_name + __product.name + name + end + + # Filter the properties to keep only the ones don't have custom update + # method and group them by update url & verb. + def properties_without_custom_update(properties) + properties.select do |p| + p.update_url.nil? || p.update_verb.nil? || p.update_verb == :NOOP + end + end + + def update_body_properties + update_prop = properties_without_custom_update(settable_properties) + update_prop = update_prop.reject(&:immutable) if update_verb == :PATCH + update_prop + end + + # Handwritten TF Operation objects will be shaped like accessContextManager + # while the Google Go Client will have a name like accesscontextmanager + def client_name_pascal + client_name = __product.client_name || __product.name + client_name.camelize(:upper) + end + + # In order of preference, use TF override, + # general defined timeouts, or default Timeouts + def timeouts + timeouts_filtered = @timeouts + timeouts_filtered ||= async&.operation&.timeouts + timeouts_filtered ||= Api::Timeouts.new + timeouts_filtered + end + + def project? + base_url.include?('{{project}}') || create_url&.include?('{{project}}') + end + + def region? + base_url.include?('{{region}}') && parameters.any? { |p| p.name == 'region' && p.ignore_read } + end + + def zone? + base_url.include?('{{zone}}') && parameters.any? { |p| p.name == 'zone' && p.ignore_read } + end + def merge(other) result = self.class.new instance_variables.each do |v| diff --git a/mmv1/templates/terraform/iam/iap_web_appengine_diff_suppress.go.erb b/mmv1/templates/terraform/iam/iap_web_appengine_diff_suppress.go.erb index 9ea4f0101332..9ac859987c48 100644 --- a/mmv1/templates/terraform/iam/iap_web_appengine_diff_suppress.go.erb +++ b/mmv1/templates/terraform/iam/iap_web_appengine_diff_suppress.go.erb @@ -1,4 +1,4 @@ -func <%= resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { +func <%= object.resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { newParts := strings.Split(new, "appengine-") if len(newParts) == 1 { diff --git a/mmv1/templates/terraform/iam/sourcerepo_diff_suppress.go.erb b/mmv1/templates/terraform/iam/sourcerepo_diff_suppress.go.erb index f265d9c10f14..aa8b3cb506e6 100644 --- a/mmv1/templates/terraform/iam/sourcerepo_diff_suppress.go.erb +++ b/mmv1/templates/terraform/iam/sourcerepo_diff_suppress.go.erb @@ -1,4 +1,4 @@ -func <%= resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { +func <%= object.resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { oldParts := regexp.MustCompile("projects/[^/]+/repos/").Split(old, -1) if len(oldParts) == 2 { return oldParts[1] == new diff --git a/mmv1/templates/terraform/iam/storage_bucket_diff_suppress.go.erb b/mmv1/templates/terraform/iam/storage_bucket_diff_suppress.go.erb index 849dcda76231..7c85beac7793 100644 --- a/mmv1/templates/terraform/iam/storage_bucket_diff_suppress.go.erb +++ b/mmv1/templates/terraform/iam/storage_bucket_diff_suppress.go.erb @@ -1,3 +1,3 @@ -func <%= resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { +func <%= object.resource_name -%>DiffSuppress(_, old, new string, _ *schema.ResourceData) bool { return tpgresource.CompareResourceNames("", old, new, nil) } \ No newline at end of file diff --git a/mmv1/templates/terraform/iam_policy.go.erb b/mmv1/templates/terraform/iam_policy.go.erb index 22b70189460c..d6ecdaedaa25 100644 --- a/mmv1/templates/terraform/iam_policy.go.erb +++ b/mmv1/templates/terraform/iam_policy.go.erb @@ -38,7 +38,7 @@ parent_resource_name = object.iam_policy.parent_resource_attribute || object.nam resource_params = extract_identifiers(resource_uri.gsub('{{name}}', "{{#{parent_resource_name}}}")) -%> -var <%= resource_name -%>IamSchema = map[string]*schema.Schema{ +var <%= object.resource_name -%>IamSchema = map[string]*schema.Schema{ <% resource_params.each_with_index do |param, i| -%> "<%= param.underscore -%>": { Type: schema.TypeString, @@ -54,7 +54,7 @@ var <%= resource_name -%>IamSchema = map[string]*schema.Schema{ <% if object.iam_policy.custom_diff_suppress.nil? -%> DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, <% else -%> - DiffSuppressFunc: <%= resource_name -%>DiffSuppress, + DiffSuppressFunc: <%= object.resource_name -%>DiffSuppress, <% end -%> <% end # param == object.name -%> }, @@ -65,7 +65,7 @@ var <%= resource_name -%>IamSchema = map[string]*schema.Schema{ <%= lines(compile(pwd + '/' + object.iam_policy.custom_diff_suppress)) -%> <% end -%> -type <%= resource_name -%>IamUpdater struct { +type <%= object.resource_name -%>IamUpdater struct { <% resource_params.each do |param| -%> <%= param.camelize(:lower) -%> string <% end # resource_params.each -%> @@ -74,7 +74,7 @@ type <%= resource_name -%>IamUpdater struct { } <% provider_default_values = ['project', 'location', 'region', 'zone'] -%> -func <%= resource_name -%>IamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) { +func <%= object.resource_name -%>IamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) { values := make(map[string]string) <% resource_params.each do |param| -%> @@ -106,7 +106,7 @@ func <%= resource_name -%>IamUpdaterProducer(d tpgresource.TerraformResourceData values[k] = v } - u := &<%= resource_name -%>IamUpdater{ + u := &<%= object.resource_name -%>IamUpdater{ <% resource_params.each do |param| -%> <%= param.camelize(:lower) -%>: values["<%= param -%>"], <% end -%> @@ -137,7 +137,7 @@ func <%= resource_name -%>IamUpdaterProducer(d tpgresource.TerraformResourceData return u, nil } -func <%= resource_name -%>IdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { +func <%= object.resource_name -%>IdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { values := make(map[string]string) <% resource_params.each do |param| -%> @@ -159,7 +159,7 @@ func <%= resource_name -%>IdParseFunc(d *schema.ResourceData, config *transport_ values[k] = v } - u := &<%= resource_name -%>IamUpdater{ + u := &<%= object.resource_name -%>IamUpdater{ <% resource_params.each do |param| -%> <%= param.camelize(:lower) -%>: values["<%= param -%>"], <% end -%> @@ -181,7 +181,7 @@ func <%= resource_name -%>IdParseFunc(d *schema.ResourceData, config *transport_ return nil } -func (u *<%= resource_name -%>IamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { +func (u *<%= object.resource_name -%>IamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { url, err := u.qualify<%= object.name -%>Url("<%= object.iam_policy.fetch_iam_policy_method -%>") if err != nil { return nil, err @@ -246,7 +246,7 @@ func (u *<%= resource_name -%>IamUpdater) GetResourceIamPolicy() (*cloudresource return out, nil } -func (u *<%= resource_name -%>IamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { +func (u *<%= object.resource_name -%>IamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { json, err := tpgresource.ConvertToMap(policy) if err != nil { return err @@ -306,7 +306,7 @@ func (u *<%= resource_name -%>IamUpdater) SetResourceIamPolicy(policy *cloudreso <% import_url = resource_uri.gsub(/({{)\%?(\w+)(}})/, '%s') -%> <% string_qualifiers = extract_identifiers(resource_uri.gsub('{{name}}', "{{#{parent_resource_name}}}")).map{|param| "u.#{param.camelize(:lower)}"}.join(', ') -%> -func (u *<%= resource_name -%>IamUpdater) qualify<%= object.name -%>Url(methodIdentifier string) (string, error) { +func (u *<%= object.resource_name -%>IamUpdater) qualify<%= object.name -%>Url(methodIdentifier string) (string, error) { urlTemplate := fmt.Sprintf("{{<%= object.__product.name -%>BasePath}}%s<%= object.iam_policy.method_name_separator -%>%s", fmt.Sprintf("<%= import_url -%>", <%= string_qualifiers -%>), methodIdentifier) url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate) if err != nil { @@ -315,14 +315,14 @@ func (u *<%= resource_name -%>IamUpdater) qualify<%= object.name -%>Url(methodId return url, nil } -func (u *<%= resource_name -%>IamUpdater) GetResourceId() string { +func (u *<%= object.resource_name -%>IamUpdater) GetResourceId() string { return fmt.Sprintf("<%= import_url -%>", <%= string_qualifiers -%>) } func (u *<%= resource_name -%>IamUpdater) GetMutexKey() string { - return fmt.Sprintf("iam-<%= object.__product.name .downcase -%>-<%= object.name.downcase -%>-%s", u.GetResourceId()) + return fmt.Sprintf("iam-<%= object.__product.name.downcase -%>-<%= object.name.downcase -%>-%s", u.GetResourceId()) } func (u *<%= resource_name -%>IamUpdater) DescribeResource() string { - return fmt.Sprintf("<%= object.__product.name .downcase -%> <%= object.name.downcase -%> %q", u.GetResourceId()) + return fmt.Sprintf("<%= object.__product.name.downcase -%> <%= object.name.downcase -%> %q", u.GetResourceId()) } diff --git a/mmv1/templates/terraform/nested_query.go.erb b/mmv1/templates/terraform/nested_query.go.erb index ab261583199c..7328ea68d875 100644 --- a/mmv1/templates/terraform/nested_query.go.erb +++ b/mmv1/templates/terraform/nested_query.go.erb @@ -1,5 +1,5 @@ <% unless object.nested_query.nil? -%> -func flattenNested<%= resource_name -%>(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { +func flattenNested<%= object.resource_name -%>(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { var v interface{} var ok bool @@ -26,24 +26,24 @@ func flattenNested<%= resource_name -%>(d *schema.ResourceData, meta interface{} return nil, fmt.Errorf("expected list or map for value <%= object.nested_query.keys.join(".") -%>. Actual value: %v", v) } - _, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, v.([]interface{})) + _, item, err := resource<%=object.resource_name%>FindNestedObjectInList(d, meta, v.([]interface{})) if err != nil { return nil, err } return item, nil } -func resource<%=resource_name%>FindNestedObjectInList(d *schema.ResourceData, meta interface{}, items []interface{}) (index int, item map[string]interface{}, err error) { +func resource<%=object.resource_name%>FindNestedObjectInList(d *schema.ResourceData, meta interface{}, items []interface{}) (index int, item map[string]interface{}, err error) { <% object.identity.each do |id_prop| -%> <% if settable_properties.include?(id_prop) -%> - expected<%= titlelize_property(id_prop) -%>, err := expandNested<%= resource_name -%><%= titlelize_property(id_prop) -%>(d.Get("<%= id_prop.name.underscore -%>"), d, meta.(*transport_tpg.Config)) + expected<%= titlelize_property(id_prop) -%>, err := expandNested<%= object.resource_name -%><%= titlelize_property(id_prop) -%>(d.Get("<%= id_prop.name.underscore -%>"), d, meta.(*transport_tpg.Config)) if err != nil { return -1, nil, err } <% else -%> expected<%= titlelize_property(id_prop) -%> := d.Get("<%= id_prop.name.underscore -%>") <% end # settable_properties.include?(id_prop)-%> - expectedFlattened<%= titlelize_property(id_prop) -%> := flattenNested<%= resource_name -%><%= titlelize_property(id_prop) -%>(expected<%= titlelize_property(id_prop) -%>, d, meta.(*transport_tpg.Config)) + expectedFlattened<%= titlelize_property(id_prop) -%> := flattenNested<%= object.resource_name -%><%= titlelize_property(id_prop) -%>(expected<%= titlelize_property(id_prop) -%>, d, meta.(*transport_tpg.Config)) <% end # object.identity.each -%> // Search list for this resource. @@ -62,14 +62,14 @@ func resource<%=resource_name%>FindNestedObjectInList(d *schema.ResourceData, me <% if object.custom_code.decoder -%> // Decode list item before comparing. - item, err := resource<%= resource_name -%>Decoder(d, meta, item) + item, err := resource<%= object.resource_name -%>Decoder(d, meta, item) if err != nil { return -1, nil, err } <% end -%> <% object.identity.each do |prop| -%> - item<%= titlelize_property(prop) -%> := flattenNested<%= resource_name -%><%= titlelize_property(prop) -%>(item["<%= prop.api_name %>"], d, meta.(*transport_tpg.Config)) + item<%= titlelize_property(prop) -%> := flattenNested<%= object.resource_name -%><%= titlelize_property(prop) -%>(item["<%= prop.api_name %>"], d, meta.(*transport_tpg.Config)) // IsEmptyValue check so that if one is nil and the other is "", that's considered a match if !(tpgresource.IsEmptyValue(reflect.ValueOf(item<%= titlelize_property(prop) -%>)) && tpgresource.IsEmptyValue(reflect.ValueOf(expectedFlattened<%= titlelize_property(prop) -%>))) && !reflect.DeepEqual(item<%= titlelize_property(prop) -%>, expectedFlattened<%= titlelize_property(prop) -%>) { log.Printf("[DEBUG] Skipping item with <%= prop.api_name %>= %#v, looking for %#v)", item<%= titlelize_property(prop) -%>, expectedFlattened<%= titlelize_property(prop) -%>) @@ -88,13 +88,13 @@ func resource<%=resource_name%>FindNestedObjectInList(d *schema.ResourceData, me %> // PatchCreateEncoder handles creating request data to PATCH parent resource // with list including new object. -func resource<%= resource_name -%>PatchCreateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { - currItems, err := resource<%= resource_name -%>ListForPatch(d, meta) +func resource<%= object.resource_name -%>PatchCreateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + currItems, err := resource<%= object.resource_name -%>ListForPatch(d, meta) if err != nil { return nil, err } - _, found, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems) + _, found, err := resource<%=object.resource_name%>FindNestedObjectInList(d, meta, currItems) if err != nil { return nil, err } @@ -145,13 +145,13 @@ func resource<%= resource_name -%>PatchCreateEncoder(d *schema.ResourceData, met <% if updatable?(object, object.root_properties) -%> // PatchUpdateEncoder handles creating request data to PATCH parent resource // with list including updated object. -func resource<%= resource_name -%>PatchUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { - items, err := resource<%= resource_name -%>ListForPatch(d, meta) +func resource<%= object.resource_name -%>PatchUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + items, err := resource<%= object.resource_name -%>ListForPatch(d, meta) if err != nil { return nil, err } - idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, items) + idx, item, err := resource<%=object.resource_name%>FindNestedObjectInList(d, meta, items) if err != nil { return nil, err } @@ -185,19 +185,19 @@ func resource<%= resource_name -%>PatchUpdateEncoder(d *schema.ResourceData, met // PatchDeleteEncoder handles creating request data to PATCH parent resource // with list excluding object to delete. -func resource<%= resource_name -%>PatchDeleteEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { - currItems, err := resource<%= resource_name -%>ListForPatch(d, meta) +func resource<%= object.resource_name -%>PatchDeleteEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { + currItems, err := resource<%= object.resource_name -%>ListForPatch(d, meta) if err != nil { return nil, err } - idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems) + idx, item, err := resource<%=object.resource_name%>FindNestedObjectInList(d, meta, currItems) if err != nil { return nil, err } if item == nil { // Spoof 404 error for proper handling by Delete (i.e. no-op) - return nil, tpgresource.Fake404("nested", "<%= resource_name%>") + return nil, tpgresource.Fake404("nested", "<%= object.resource_name%>") } updatedItems := append(currItems[:idx], currItems[idx+1:]...) @@ -224,7 +224,7 @@ func resource<%= resource_name -%>PatchDeleteEncoder(d *schema.ResourceData, met # 2) returns the full list of other resources, rather than just the # matching resource -%> -func resource<%= resource_name -%>ListForPatch(d *schema.ResourceData, meta interface{}) ([]interface{}, error) { +func resource<%= object.resource_name -%>ListForPatch(d *schema.ResourceData, meta interface{}) ([]interface{}, error) { config := meta.(*transport_tpg.Config) url, err := tpgresource.ReplaceVars(d, config, "<%= "{{#{object.__product.name}BasePath}}#{object.self_link_uri}" -%>") if err != nil { diff --git a/mmv1/templates/terraform/post_create/labels.erb b/mmv1/templates/terraform/post_create/labels.erb index 1aaf5c26ce90..357979809086 100644 --- a/mmv1/templates/terraform/post_create/labels.erb +++ b/mmv1/templates/terraform/post_create/labels.erb @@ -1,17 +1,17 @@ -<% if properties.any?{ |p| p.name == "labels" } -%> +<% if object.properties.any?{ |p| p.name == "labels" } -%> if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { labels := d.Get("labels") terraformLables := d.Get("terraform_labels") // Labels cannot be set in a create. We'll have to set them here. - err = resource<%= resource_name -%>Read(d, meta) + err = resource<%= object.resource_name -%>Read(d, meta) if err != nil { return err } obj := make(map[string]interface{}) // d.Get("effective_labels") will have been overridden by the Read call. - labelsProp, err := expand<%= resource_name -%>EffectiveLabels(v, d, config) + labelsProp, err := expand<%= object.resource_name -%>EffectiveLabels(v, d, config) if err != nil { return err } @@ -38,11 +38,11 @@ if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect <% end -%> }) if err != nil { - return fmt.Errorf("Error adding labels to <%= resource_name -%> %q: %s", d.Id(), err) + return fmt.Errorf("Error adding labels to <%= object.resource_name -%> %q: %s", d.Id(), err) } err = ComputeOperationWaitTime( - config, res, project, "Updating <%= resource_name -%> Labels", userAgent, + config, res, project, "Updating <%= object.resource_name -%> Labels", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { diff --git a/mmv1/templates/terraform/post_create_failure/delete_on_failure.go.erb b/mmv1/templates/terraform/post_create_failure/delete_on_failure.go.erb index 1ea301b38012..e7ee1aa003ee 100644 --- a/mmv1/templates/terraform/post_create_failure/delete_on_failure.go.erb +++ b/mmv1/templates/terraform/post_create_failure/delete_on_failure.go.erb @@ -1,9 +1,9 @@ log.Printf("[WARN] Attempt to clean up <%= object.name -%> if it still exists") var cleanErr error -if cleanErr = resource<%= resource_name -%>Read(d, meta); cleanErr == nil { +if cleanErr = resource<%= object.resource_name -%>Read(d, meta); cleanErr == nil { if d.Id() != "" { log.Printf("[WARN] <%= object.name -%> %q still exists, attempting to delete...", d.Id()) - if cleanErr = resource<%= resource_name -%>Delete(d, meta); cleanErr == nil { + if cleanErr = resource<%= object.resource_name -%>Delete(d, meta); cleanErr == nil { log.Printf("[WARN] Invalid <%= object.name -%> was successfully deleted") d.SetId("") } diff --git a/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb b/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb index b48f3e7d1a24..e3b759b33449 100644 --- a/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb +++ b/mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb @@ -38,6 +38,6 @@ if isDefaultStartFlow || isDefaultWelcomeIntent || isDefaultNegativeIntent { d.SetId(id) // and defer to the Update method: - log.Printf("[DEBUG] Updating default <%= resource_name -%>") - return resource<%= resource_name -%>Update(d, meta) + log.Printf("[DEBUG] Updating default <%= object.resource_name -%>") + return resource<%= object.resource_name -%>Update(d, meta) } \ No newline at end of file diff --git a/mmv1/templates/terraform/pre_delete/dialogflowcx_set_location_skip_default_obj.go.erb b/mmv1/templates/terraform/pre_delete/dialogflowcx_set_location_skip_default_obj.go.erb index 520f992a5d8b..946e42b3b179 100644 --- a/mmv1/templates/terraform/pre_delete/dialogflowcx_set_location_skip_default_obj.go.erb +++ b/mmv1/templates/terraform/pre_delete/dialogflowcx_set_location_skip_default_obj.go.erb @@ -3,16 +3,16 @@ location := "" if parts := regexp.MustCompile(`locations\/([^\/]*)\/`).FindStringSubmatch(d.Get("parent").(string)); parts != nil { - location = parts[1] + location = parts[1] } else { - return fmt.Errorf( - "Saw %s when the parent is expected to contains location %s", - d.Get("parent"), - "projects/{{project}}/locations/{{location}}/...", - ) + return fmt.Errorf( + "Saw %s when the parent is expected to contains location %s", + d.Get("parent"), + "projects/{{project}}/locations/{{location}}/...", + ) } -url = strings.Replace(url,"-dialogflow",fmt.Sprintf("%s-dialogflow",location),1) +url = strings.Replace(url, "-dialogflow", fmt.Sprintf("%s-dialogflow", location), 1) // if it's a default object Dialogflow creates for you, skip deletion // Note: below we try to access fields that aren't present in the resource, because this custom code is reused across multiple Dialogflow resources that contain different fields. When the field isn't present, we deliberately ignore the error and the boolean is false. @@ -20,7 +20,7 @@ isDefaultStartFlow, _ := d.Get("is_default_start_flow").(bool) isDefaultWelcomeIntent, _ := d.Get("is_default_welcome_intent").(bool) isDefaultNegativeIntent, _ := d.Get("is_default_negative_intent").(bool) if isDefaultStartFlow || isDefaultWelcomeIntent || isDefaultNegativeIntent { - // we can't delete these resources so do nothing - log.Printf("[DEBUG] Not deleting default <%= resource_name -%>") - return nil + // we can't delete these resources so do nothing + log.Printf("[DEBUG] Not deleting default <%= object.resource_name -%>") + return nil } \ No newline at end of file diff --git a/mmv1/templates/terraform/resource.erb b/mmv1/templates/terraform/resource.erb index 8e5b6b4c2b50..95a1155212be 100644 --- a/mmv1/templates/terraform/resource.erb +++ b/mmv1/templates/terraform/resource.erb @@ -53,47 +53,27 @@ import ( <%= lines(compile(pwd + '/' + object.custom_code.constants)) if object.custom_code.constants -%> -<% - resource_name = object.__product.name + object.name - properties = object.all_user_properties - update_body_properties = properties_without_custom_update(object.settable_properties) - update_body_properties = update_body_properties.reject(&:immutable) if object.update_verb == :PATCH - # Handwritten TF Operation objects will be shaped like accessContextManager while the Google Go Client will have a name like accesscontextmanager - client_name = object.__product.client_name || object.__product.name - client_name_camel = client_name.camelize(:lower) - client_name_pascal = client_name.camelize(:upper) - client_name_lower = client_name.downcase - has_project = object.base_url.include?('{{project}}') || (object.create_url && object.create_url.include?('{{project}}')) - has_region = object.base_url.include?('{{region}}') && object.parameters.any?{ |p| p.name == 'region' && p.ignore_read } - has_zone = object.base_url.include?('{{zone}}') && object.parameters.any?{ |p| p.name == 'zone' && p.ignore_read } - # In order of preference, use TF override, - # general defined timeouts, or default Timeouts - timeouts = object.timeouts - timeouts ||= object&.async&.operation&.timeouts - timeouts ||= Api::Timeouts.new --%> - -func Resource<%= resource_name -%>() *schema.Resource { +func Resource<%= object.resource_name -%>() *schema.Resource { return &schema.Resource{ - Create: resource<%= resource_name -%>Create, - Read: resource<%= resource_name -%>Read, -<% if updatable?(object, properties) -%> - Update: resource<%= resource_name -%>Update, + Create: resource<%= object.resource_name -%>Create, + Read: resource<%= object.resource_name -%>Read, +<% if updatable?(object, object.all_user_properties) -%> + Update: resource<%= object.resource_name -%>Update, <% end -%> - Delete: resource<%= resource_name -%>Delete, + Delete: resource<%= object.resource_name -%>Delete, <% unless object.exclude_import -%> Importer: &schema.ResourceImporter{ - State: resource<%= resource_name -%>Import, + State: resource<%= object.resource_name -%>Import, }, <% end -%> Timeouts: &schema.ResourceTimeout { - Create: schema.DefaultTimeout(<%= timeouts.insert_minutes -%> * time.Minute), -<% if updatable?(object, properties) -%> - Update: schema.DefaultTimeout(<%= timeouts.update_minutes -%> * time.Minute), + Create: schema.DefaultTimeout(<%= object.timeouts.insert_minutes -%> * time.Minute), +<% if updatable?(object, object.all_user_properties) -%> + Update: schema.DefaultTimeout(<%= object.timeouts.update_minutes -%> * time.Minute), <% end -%> - Delete: schema.DefaultTimeout(<%= timeouts.delete_minutes -%> * time.Minute), + Delete: schema.DefaultTimeout(<%= object.timeouts.delete_minutes -%> * time.Minute), }, <% if object.schema_version -%> @@ -107,19 +87,19 @@ func Resource<%= resource_name -%>() *schema.Resource { StateUpgraders: []schema.StateUpgrader{ <% for v in object.state_upgrade_base_schema_version..object.schema_version-1 -%> { - Type: resource<%= "#{resource_name}ResourceV#{v}" -%>().CoreConfigSchema().ImpliedType(), - Upgrade: Resource<%= "#{resource_name}UpgradeV#{v}" -%>, + Type: resource<%= "#{object.resource_name}ResourceV#{v}" -%>().CoreConfigSchema().ImpliedType(), + Upgrade: Resource<%= "#{object.resource_name}UpgradeV#{v}" -%>, Version: <%= v -%>, }, <% end -%> }, <% end -%> -<% if ((has_project || has_region || has_zone) && !object.skip_default_cdiff) || object.custom_diff.any? || object.settable_properties.any? {|p| p.unordered_list}-%> +<% if ((object.project? || object.region? || object.zone?) && !object.skip_default_cdiff) || object.custom_diff.any? || object.settable_properties.any? {|p| p.unordered_list}-%> CustomizeDiff: customdiff.All( <% if object.settable_properties.any? {|p| p.unordered_list} -%> <%= object.settable_properties.select { |p| p.unordered_list } - .map { |p| "resource#{resource_name}#{p.name.camelize(:upper)}SetStyleDiff"} + .map { |p| "resource#{object.resource_name}#{p.name.camelize(:upper)}SetStyleDiff"} .join(",\n") -%>, <% end -%> @@ -128,13 +108,13 @@ func Resource<%= resource_name -%>() *schema.Resource { <%= cdiff%>, <% end -%> <% end -%> -<% if has_project && !object.skip_default_cdiff -%> +<% if object.project? && !object.skip_default_cdiff -%> tpgresource.DefaultProviderProject, <% end -%> -<% if has_region && !object.skip_default_cdiff -%> +<% if object.region? && !object.skip_default_cdiff -%> tpgresource.DefaultProviderRegion, <% end -%> -<% if has_zone && !object.skip_default_cdiff -%> +<% if object.zone? && !object.skip_default_cdiff -%> tpgresource.DefaultProviderZone, <% end -%> ), @@ -145,7 +125,7 @@ func Resource<%= resource_name -%>() *schema.Resource { <% end -%> Schema: map[string]*schema.Schema{ -<% order_properties(properties).each do |prop| -%> +<% order_properties(object.all_user_properties).each do |prop| -%> <%= lines(build_schema_property(prop, object, pwd)) -%> <% end -%> <%- unless object.virtual_fields.empty? -%> @@ -164,7 +144,7 @@ func Resource<%= resource_name -%>() *schema.Resource { <% end -%> <% end -%> <%= lines(compile(pwd + '/' + object.custom_code.extra_schema_entry)) if object.custom_code.extra_schema_entry -%> -<% if has_project -%> +<% if object.project? -%> "project": { Type: schema.TypeString, Optional: true, @@ -183,21 +163,21 @@ func Resource<%= resource_name -%>() *schema.Resource { } } -<% properties.each do |prop| -%> +<% object.all_user_properties.each do |prop| -%> <%= lines(build_subresource_schema(prop, object, pwd), 1) -%> <% end -%> <% object.settable_properties.select {|p| p.unordered_list}.each do |prop| -%> -func resource<%= resource_name -%><%= prop.name.camelize(:upper) -%>SetStyleDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { +func resource<%= object.resource_name -%><%= prop.name.camelize(:upper) -%>SetStyleDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { <%= compile_template(pwd + '/templates/terraform/unordered_list_customize_diff.erb', prop: prop, - resource_name: resource_name) + object: object) -%> } <% end -%> -func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{}) error { +func resource<%= object.resource_name -%>Create(d *schema.ResourceData, meta interface{}) error { <% if object.async&.is_a?(Api::OpAsync) && object.async.include_project && object.async&.allow?('create') -%> var project string <% end -%> @@ -213,7 +193,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ obj := make(map[string]interface{}) <% object.settable_properties.each do |prop| -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> - <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) + <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { return err <% if prop.send_empty_value -%> @@ -228,7 +208,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% end -%> <% if object.custom_code.encoder -%> - obj, err = resource<%= resource_name -%>Encoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>Encoder(d, meta, obj) if err != nil { return err } @@ -251,7 +231,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Creating new <%= object.name -%>: %#v", obj) <% if object.nested_query&.modify_by_patch -%> <%# Keep this after mutex - patch request data relies on current resource state %> - obj, err = resource<%= resource_name -%>PatchCreateEncoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>PatchCreateEncoder(d, meta, obj) if err != nil { return err } @@ -264,7 +244,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% end -%> billingProject := "" -<% if has_project -%> +<% if object.project? -%> project, err := tpgresource.GetProject(d, config) if err != nil { return fmt.Errorf("Error fetching project for <%= object.name -%>: %s", err) @@ -305,7 +285,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ }) if err != nil { <% if object.custom_code.post_create_failure && object.async.nil? # Only add if not handled by async error handling -%> - resource<%= resource_name -%>PostCreateFailure(d, meta) + resource<%= object.resource_name -%>PostCreateFailure(d, meta) <% end -%> return fmt.Errorf("Error creating <%= object.name -%>: %s", err) } @@ -313,7 +293,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% unless object.async&.is_a? Api::OpAsync -%> <% object.gettable_properties.each do |prop| -%> <% if object.identity.include?(prop) && prop.output -%> - if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config)); err != nil { + if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config)); err != nil { return fmt.Errorf(`Error setting computed identity field "<%=prop.name.underscore%>": %s`, err) } <% end -%> @@ -333,12 +313,12 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ // Use the resource in the operation response to populate // identity fields and d.Id() before read var opRes map[string]interface{} - err = <%= client_name_pascal -%>OperationWaitTimeWithResponse( - config, res, &opRes, <% if has_project || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Creating <%= object.name -%>", userAgent, + err = <%= object.client_name_pascal -%>OperationWaitTimeWithResponse( + config, res, &opRes, <% if object.project? || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { <% if object.custom_code.post_create_failure -%> - resource<%= resource_name -%>PostCreateFailure(d, meta) + resource<%= object.resource_name -%>PostCreateFailure(d, meta) <% end -%> <% unless object.taint_resource_on_failed_create -%> // The resource didn't actually create @@ -349,7 +329,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ } <% if object.custom_code.decoder -%> - opRes, err = resource<%= resource_name -%>Decoder(d, meta, opRes) + opRes, err = resource<%= object.resource_name -%>Decoder(d, meta, opRes) if err != nil { return fmt.Errorf("Error decoding response from operation: %s", err) } @@ -360,7 +340,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% if object.nested_query -%> if _, ok := opRes["<%=object.nested_query.keys[0]-%>"]; ok { - opRes, err = flattenNested<%= resource_name -%>(d, meta, opRes) + opRes, err = flattenNested<%= object.resource_name -%>(d, meta, opRes) if err != nil { return fmt.Errorf("Error getting nested object from operation response: %s", err) } @@ -372,7 +352,7 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% end -%> <% object.gettable_properties.each do |prop| -%> <% if object.identity.include?(prop) -%> - if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(opRes["<%= prop.api_name -%>"], d, config)); err != nil { + if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(opRes["<%= prop.api_name -%>"], d, config)); err != nil { return err } <% end -%> @@ -386,13 +366,13 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ d.SetId(id) <% else # if object.async.is_a? Api::OpAsync -%> - err = <%= client_name_pascal -%>OperationWaitTime( - config, res, <% if has_project || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Creating <%= object.name -%>", userAgent, + err = <%= object.client_name_pascal -%>OperationWaitTime( + config, res, <% if object.project? || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Creating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutCreate)) if err != nil { <% if object.custom_code.post_create_failure -%> - resource<%= resource_name -%>PostCreateFailure(d, meta) + resource<%= object.resource_name -%>PostCreateFailure(d, meta) <% end -%> <% unless object.taint_resource_on_failed_create -%> // The resource didn't actually create @@ -409,13 +389,13 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ <% if object.async&.allow?('create') -%> <% if object.async.is_a? Provider::Terraform::PollAsync -%> - err = transport_tpg.PollingWaitTime(resource<%= resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Creating <%= object.name -%>", d.Timeout(schema.TimeoutCreate), <%= object.async.target_occurrences -%>) + err = transport_tpg.PollingWaitTime(resource<%= object.resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Creating <%= object.name -%>", d.Timeout(schema.TimeoutCreate), <%= object.async.target_occurrences -%>) if err != nil { <% if object.async.suppress_error -%> log.Printf("[ERROR] Unable to confirm eventually consistent <%= object.name -%> %q finished updating: %q", d.Id(), err) <% else -%> <% if object.custom_code.post_create_failure -%> - resource<%= resource_name -%>PostCreateFailure(d, meta) + resource<%= object.resource_name -%>PostCreateFailure(d, meta) <% end -%> return fmt.Errorf("Error waiting to create <%= object.name -%>: %s", err) <% end -%> @@ -426,12 +406,12 @@ func resource<%= resource_name -%>Create(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Finished creating <%= object.name -%> %q: %#v", d.Id(), res) - return resource<%= resource_name -%>Read(d, meta) + return resource<%= object.resource_name -%>Read(d, meta) <% end # if custom_create -%> } <% if object.async&.is_a? Provider::Terraform::PollAsync -%> -func resource<%= resource_name -%>PollRead(d *schema.ResourceData, meta interface{}) transport_tpg.PollReadFunc { +func resource<%= object.resource_name -%>PollRead(d *schema.ResourceData, meta interface{}) transport_tpg.PollReadFunc { return func() (map[string]interface{}, error) { <% if object.async.custom_poll_read -%> <%= lines(compile(pwd + '/' + object.async.custom_poll_read)) -%> @@ -447,7 +427,7 @@ func resource<%= resource_name -%>PollRead(d *schema.ResourceData, meta interfac billingProject := "" -<% if has_project -%> +<% if object.project? -%> project, err := tpgresource.GetProject(d, config) if err != nil { return nil, fmt.Errorf("Error fetching project for <%= object.name -%>: %s", err) @@ -492,23 +472,23 @@ func resource<%= resource_name -%>PollRead(d *schema.ResourceData, meta interfac return res, err } <% if object.nested_query -%> - res, err = flattenNested<%= resource_name -%>(d, meta, res) + res, err = flattenNested<%= object.resource_name -%>(d, meta, res) if err != nil { return nil, err } if res == nil { - return nil, tpgresource.Fake404("nested", "<%= resource_name%>") + return nil, tpgresource.Fake404("nested", "<%= object.resource_name%>") } <% end -%> <% if object.custom_code.decoder -%> - res, err = resource<%= resource_name -%>Decoder(d, meta, res) + res, err = resource<%= object.resource_name -%>Decoder(d, meta, res) if err != nil { return nil, err } if res == nil { - return nil, tpgresource.Fake404("decoded", "<%= resource_name%>") + return nil, tpgresource.Fake404("decoded", "<%= object.resource_name%>") } <% end -%> @@ -518,7 +498,7 @@ func resource<%= resource_name -%>PollRead(d *schema.ResourceData, meta interfac } <% end # if object.async&.is_a? Provider::Terraform::PollAsync -%> -func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) error { +func resource<%= object.resource_name -%>Read(d *schema.ResourceData, meta interface{}) error { <% if object.skip_read -%> // This resource could not be read from the API. return nil @@ -536,7 +516,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) billingProject := "" -<% if has_project -%> +<% if object.project? -%> project, err := tpgresource.GetProject(d, config) if err != nil { return fmt.Errorf("Error fetching project for <%= object.name -%>: %s", err) @@ -575,21 +555,21 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) }) if err != nil { <% if object.read_error_transform -%> - return transport_tpg.HandleNotFoundError(<%= object.read_error_transform %>(err), d, fmt.Sprintf("<%= resource_name -%> %q", d.Id())) + return transport_tpg.HandleNotFoundError(<%= object.read_error_transform %>(err), d, fmt.Sprintf("<%= object.resource_name -%> %q", d.Id())) <% else -%> - return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("<%= resource_name -%> %q", d.Id())) + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("<%= object.resource_name -%> %q", d.Id())) <% end -%> } <% if object.nested_query -%> - res, err = flattenNested<%= resource_name -%>(d, meta, res) + res, err = flattenNested<%= object.resource_name -%>(d, meta, res) if err != nil { return err } if res == nil { // Object isn't there any more - remove it from the state. - log.Printf("[DEBUG] Removing <%= resource_name -%> because it couldn't be matched.") + log.Printf("[DEBUG] Removing <%= object.resource_name -%> because it couldn't be matched.") d.SetId("") return nil } @@ -597,14 +577,14 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) <% end -%> <% if object.custom_code.decoder -%> - res, err = resource<%= resource_name -%>Decoder(d, meta, res) + res, err = resource<%= object.resource_name -%>Decoder(d, meta, res) if err != nil { return err } if res == nil { // Decoding the object has resulted in it being gone. It may be marked deleted - log.Printf("[DEBUG] Removing <%= resource_name -%> because it no longer exists.") + log.Printf("[DEBUG] Removing <%= object.resource_name -%> because it no longer exists.") d.SetId("") return nil } @@ -622,13 +602,13 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) <% end -%> <% end -%> <% end -%> -<% if has_project -%> +<% if object.project? -%> if err := d.Set("project", project); err != nil { return fmt.Errorf("Error reading <%= object.name -%>: %s", err) } <% end -%> -<% if has_region -%> +<% if object.region? -%> region, err := tpgresource.GetRegion(d, config) if err != nil { return err @@ -638,7 +618,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) } <% end -%> -<% if has_zone -%> +<% if object.zone? -%> zone, err := tpgresource.GetZone(d, config) if err != nil { return err @@ -652,7 +632,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) <% if prop.flatten_object -%> // Terraform must set the top level schema field, but since this object contains collapsed properties // it's difficult to know what the top level should be. Instead we just loop over the map returned from flatten. - if flattenedProp := flatten<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config); flattenedProp != nil { + if flattenedProp := flatten<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config); flattenedProp != nil { if gerr, ok := flattenedProp.(*googleapi.Error); ok { return fmt.Errorf("Error reading <%= object.name -%>: %s", gerr) } @@ -666,7 +646,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) } } <% else -%> - if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config)); err != nil { + if err := d.Set("<%= prop.name.underscore -%>", flatten<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(res["<%= prop.api_name -%>"], d, config)); err != nil { return fmt.Errorf("Error reading <%= object.name -%>: %s", err) } <% end -%> @@ -682,7 +662,7 @@ func resource<%= resource_name -%>Read(d *schema.ResourceData, meta interface{}) } <% if updatable?(object, object.root_properties) -%> -func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{}) error { +func resource<%= object.resource_name -%>Update(d *schema.ResourceData, meta interface{}) error { <% if object.async&.is_a?(Api::OpAsync) && object.async.include_project && object.async&.allow?('update') -%> var project string <% end -%> @@ -697,7 +677,7 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ billingProject := "" -<% if has_project -%> +<% if object.project? -%> project, err := tpgresource.GetProject(d, config) if err != nil { return fmt.Errorf("Error fetching project for <%= object.name -%>: %s", err) @@ -712,10 +692,10 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <% if !object.immutable -%> obj := make(map[string]interface{}) -<% update_body_properties.each do |prop| -%> +<% object.update_body_properties.each do |prop| -%> <%# flattened objects won't have something stored in state so instead nil is passed to the next expander. -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> - <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) + <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { return err <% if prop.send_empty_value -%> @@ -731,12 +711,12 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <%# We need to decide what encoder to use here - if there's an update encoder, use that! -%> <% if object.custom_code.update_encoder -%> - obj, err = resource<%= resource_name -%>UpdateEncoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>UpdateEncoder(d, meta, obj) if err != nil { return err } <% elsif object.custom_code.encoder -%> - obj, err = resource<%= resource_name -%>Encoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>Encoder(d, meta, obj) if err != nil { return err } @@ -761,7 +741,7 @@ func resource<%= resource_name -%>Update(d *schema.ResourceData, meta interface{ <%= lines(compile(pwd + '/' + object.custom_code.pre_update)) if object.custom_code.pre_update -%> <% if object.nested_query&.modify_by_patch -%> <%# Keep this after mutex - patch request data relies on current resource state %> - obj, err = resource<%= resource_name -%>PatchUpdateEncoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>PatchUpdateEncoder(d, meta, obj) if err != nil { return err } @@ -805,15 +785,15 @@ if len(updateMask) > 0 { <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync -%> - err = <%= client_name_pascal -%>OperationWaitTime( - config, res, <% if has_project || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Updating <%= object.name -%>", userAgent, + err = <%= object.client_name_pascal -%>OperationWaitTime( + config, res, <% if object.project? || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } <% elsif object.async.is_a? Provider::Terraform::PollAsync -%> - err = transport_tpg.PollingWaitTime(resource<%= resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Updating <%= object.name -%>", d.Timeout(schema.TimeoutUpdate), <%= object.async.target_occurrences -%>) + err = transport_tpg.PollingWaitTime(resource<%= object.resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Updating <%= object.name -%>", d.Timeout(schema.TimeoutUpdate), <%= object.async.target_occurrences -%>) if err != nil { <% if object.async.suppress_error-%> log.Printf("[ERROR] Unable to confirm eventually consistent <%= object.name -%> %q finished updating: %q", d.Id(), err) @@ -867,17 +847,17 @@ if len(updateMask) > 0 { <% end -%> }) if err != nil { - return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("<%= resource_name -%> %q", d.Id())) + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("<%= object.resource_name -%> %q", d.Id())) } obj["<%= key[:fingerprint_name] %>"] = getRes["<%= key[:fingerprint_name] %>"] <% end # unless key[:fingerprint_name] -%> -<% custom_update_properties_by_key(properties, key) +<% custom_update_properties_by_key(object.all_user_properties, key) .reject(&:url_param_only) .each do |prop| -%> <% schemaPrefix = prop.flatten_object ? "nil" : "d.Get( \"#{prop.name.underscore}\" )" -%> - <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) + <%= prop.api_name -%>Prop, err := expand<%= "Nested" if object.nested_query -%><%= object.resource_name -%><%= titlelize_property(prop) -%>(<%= schemaPrefix -%>, d, config) if err != nil { return err <%# There is some nuance in when we choose to send a value to an update function. @@ -910,7 +890,7 @@ if len(updateMask) > 0 { <%# We need to decide what encoder to use here - if there's an update encoder, use that! -%> <% if object.custom_code.update_encoder -%> - obj, err = resource<%= resource_name -%>UpdateEncoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>UpdateEncoder(d, meta, obj) if err != nil { return err } @@ -966,14 +946,14 @@ if len(updateMask) > 0 { <% if object.async&.allow?('update') -%> <% if object.async.is_a? Api::OpAsync-%> - err = <%= client_name_pascal -%>OperationWaitTime( - config, res, <% if has_project || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Updating <%= object.name -%>", userAgent, + err = <%= object.client_name_pascal -%>OperationWaitTime( + config, res, <% if object.project? || object.async.include_project -%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Updating <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } <% elsif object.async.is_a? Provider::Terraform::PollAsync -%> - err = transport_tpg.PollingWaitTime(resource<%= resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Updating <%= object.name -%>", d.Timeout(schema.TimeoutUpdate), <%= object.async.target_occurrences -%>) + err = transport_tpg.PollingWaitTime(resource<%= object.resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_existence -%>, "Updating <%= object.name -%>", d.Timeout(schema.TimeoutUpdate), <%= object.async.target_occurrences -%>) if err != nil { <% if object.async.suppress_error-%> log.Printf("[ERROR] Unable to confirm eventually consistent <%= object.name -%> %q finished updating: %q", d.Id(), err) @@ -990,12 +970,12 @@ if len(updateMask) > 0 { <% end -%> <%= lines(compile(pwd + '/' + object.custom_code.post_update)) if object.custom_code.post_update -%> - return resource<%= resource_name -%>Read(d, meta) + return resource<%= object.resource_name -%>Read(d, meta) <% end # if custom_update -%> } <% end # if updatable? -%> -func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{}) error { +func resource<%= object.resource_name -%>Delete(d *schema.ResourceData, meta interface{}) error { <% if object.async&.is_a?(Api::OpAsync) && object.async.include_project && object.async&.allow?('delete') -%> var project string <% end -%> @@ -1019,7 +999,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ billingProject := "" -<% if has_project -%> +<% if object.project? -%> project, err := tpgresource.GetProject(d, config) if err != nil { return fmt.Errorf("Error fetching project for <%= object.name -%>: %s", err) @@ -1050,7 +1030,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ <%= lines(compile(pwd + '/' + object.custom_code.pre_delete)) if object.custom_code.pre_delete -%> <% if object.nested_query&.modify_by_patch -%> <%# Keep this after mutex - patch request data relies on current resource state %> - obj, err = resource<%= resource_name -%>PatchDeleteEncoder(d, meta, obj) + obj, err = resource<%= object.resource_name -%>PatchDeleteEncoder(d, meta, obj) if err != nil { return transport_tpg.HandleNotFoundError(err, d, "<%= object.name -%>") } @@ -1096,7 +1076,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ <% if object.async&.allow?('delete') -%> <% if object.async.is_a? Provider::Terraform::PollAsync -%> - err = transport_tpg.PollingWaitTime(resource<%= resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_absence -%>, "Deleting <%= object.name -%>", d.Timeout(schema.TimeoutCreate), <%= object.async.target_occurrences -%>) + err = transport_tpg.PollingWaitTime(resource<%= object.resource_name -%>PollRead(d, meta), <%= object.async.check_response_func_absence -%>, "Deleting <%= object.name -%>", d.Timeout(schema.TimeoutCreate), <%= object.async.target_occurrences -%>) if err != nil { <% if object.async.suppress_error -%> log.Printf("[ERROR] Unable to confirm eventually consistent <%= object.name -%> %q finished updating: %q", d.Id(), err) @@ -1105,8 +1085,8 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ <% end -%> } <% else -%> - err = <%= client_name_pascal -%>OperationWaitTime( - config, res, <% if has_project || object.async.include_project-%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Deleting <%= object.name -%>", userAgent, + err = <%= object.client_name_pascal -%>OperationWaitTime( + config, res, <% if object.project? || object.async.include_project-%> <% if object.legacy_long_form_project -%>tpgresource.GetResourceNameFromSelfLink(project)<% else %>project<% end %>, <% end -%> "Deleting <%= object.name -%>", userAgent, d.Timeout(schema.TimeoutDelete)) if err != nil { @@ -1123,7 +1103,7 @@ func resource<%= resource_name -%>Delete(d *schema.ResourceData, meta interface{ } <% unless object.exclude_import -%> -func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resource<%= object.resource_name -%>Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { <% if object.custom_code.custom_import -%> <%= lines(compile(pwd + '/' + object.custom_code.custom_import)) -%> <% else -%> @@ -1162,21 +1142,21 @@ func resource<%= resource_name -%>Import(d *schema.ResourceData, meta interface{ <%- nested_prefix = object.nested_query ? "Nested" : "" -%> <% object.gettable_properties.reject(&:ignore_read).each do |prop| -%> -<%= lines(build_flatten_method(nested_prefix+resource_name, prop, object, pwd), 1) -%> +<%= lines(build_flatten_method(nested_prefix+object.resource_name, prop, object, pwd), 1) -%> <% end -%> <% object.settable_properties.each do |prop| -%> -<%= lines(build_expand_method(nested_prefix+resource_name, prop, object, pwd), 1) -%> +<%= lines(build_expand_method(nested_prefix+object.resource_name, prop, object, pwd), 1) -%> <% end -%> <% if object.custom_code.encoder -%> -func resource<%= resource_name -%>Encoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { +func resource<%= object.resource_name -%>Encoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { <%= lines(compile(pwd + '/' + object.custom_code.encoder)) -%> } <% end -%> <% if object.custom_code.update_encoder-%> -func resource<%= resource_name -%>UpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { +func resource<%= object.resource_name -%>UpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { <%= lines(compile(pwd + '/' + object.custom_code.update_encoder)) -%> } <% end -%> @@ -1184,18 +1164,17 @@ func resource<%= resource_name -%>UpdateEncoder(d *schema.ResourceData, meta int <% if object.nested_query -%> <%= compile_template(pwd + '/templates/terraform/nested_query.go.erb', object: object, - settable_properties: object.settable_properties, - resource_name: resource_name) -%> + settable_properties: object.settable_properties) -%> <% end -%> <% if object.custom_code.decoder -%> -func resource<%= resource_name -%>Decoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { +func resource<%= object.resource_name -%>Decoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { <%= lines(compile(pwd + '/' + object.custom_code.decoder)) -%> } <% end -%> <% if object.custom_code.post_create_failure -%> -func resource<%= resource_name -%>PostCreateFailure(d *schema.ResourceData, meta interface{}) { +func resource<%= object.resource_name -%>PostCreateFailure(d *schema.ResourceData, meta interface{}) { <%= lines(compile(pwd + '/' + object.custom_code.post_create_failure)) -%> } <% end -%> diff --git a/mmv1/templates/terraform/self_link_query.erb b/mmv1/templates/terraform/self_link_query.erb index b832252b8767..c7ed618038d5 100644 --- a/mmv1/templates/terraform/self_link_query.erb +++ b/mmv1/templates/terraform/self_link_query.erb @@ -12,14 +12,14 @@ for _, item := range listObj { <% object.identity.each do |prop| -%> <% if settable_properties.include?(prop) -%> - this<%= titlelize_property(prop) -%>, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(d.Get("<%= prop.name.underscore -%>"), d, config) + this<%= titlelize_property(prop) -%>, err := expand<%= object.resource_name -%><%= titlelize_property(prop) -%>(d.Get("<%= prop.name.underscore -%>"), d, config) if err != nil { return err } <% else -%> this<%= titlelize_property(prop) -%> := d.Get("<%= prop.name.underscore -%>") <% end -%> - that<%= titlelize_property(prop) -%> := flatten<%= resource_name -%><%= titlelize_property(prop) -%>(item["<%= prop.api_name -%>"], d, config) + that<%= titlelize_property(prop) -%> := flatten<%= object.resource_name -%><%= titlelize_property(prop) -%>(item["<%= prop.api_name -%>"], d, config) log.Printf("[DEBUG] Checking equality of %#v, %#v", that<%= titlelize_property(prop) -%>, this<%= titlelize_property(prop) -%>) if !reflect.DeepEqual(that<%= titlelize_property(prop) -%>, this<%= titlelize_property(prop) -%>) { continue @@ -30,7 +30,7 @@ } if res == nil { // Object isn't there any more - remove it from the state. - log.Printf("[DEBUG] Removing <%= resource_name -%> because it couldn't be matched.") + log.Printf("[DEBUG] Removing <%= object.resource_name -%> because it couldn't be matched.") d.SetId("") return nil } diff --git a/mmv1/templates/terraform/unordered_list_customize_diff.erb b/mmv1/templates/terraform/unordered_list_customize_diff.erb index 099c26b1170f..347c03441fc0 100644 --- a/mmv1/templates/terraform/unordered_list_customize_diff.erb +++ b/mmv1/templates/terraform/unordered_list_customize_diff.erb @@ -27,8 +27,8 @@ for i := 0; i < count; i++ { } } -oldSet := schema.NewSet(schema.HashResource(Resource<%= resource_name -%>().Schema[<%= go_literal(prop.name.underscore) -%>].Elem.(*schema.Resource)), old) -newSet := schema.NewSet(schema.HashResource(Resource<%= resource_name -%>().Schema[<%= go_literal(prop.name.underscore) -%>].Elem.(*schema.Resource)), new) +oldSet := schema.NewSet(schema.HashResource(Resource<%= object.resource_name -%>().Schema[<%= go_literal(prop.name.underscore) -%>].Elem.(*schema.Resource)), old) +newSet := schema.NewSet(schema.HashResource(Resource<%= object.resource_name -%>().Schema[<%= go_literal(prop.name.underscore) -%>].Elem.(*schema.Resource)), new) if oldSet.Equal(newSet) { if err := diff.Clear(<%= go_literal(prop.name.underscore) -%>); err != nil { diff --git a/mmv1/templates/terraform/update_encoder/containeranalysis_occurrence.go.erb b/mmv1/templates/terraform/update_encoder/containeranalysis_occurrence.go.erb index 1d2f4e2e0adb..86c6021054f7 100644 --- a/mmv1/templates/terraform/update_encoder/containeranalysis_occurrence.go.erb +++ b/mmv1/templates/terraform/update_encoder/containeranalysis_occurrence.go.erb @@ -20,4 +20,4 @@ if err != nil { obj["noteName"] = noteNameProp } -return resource<%= resource_name -%>Encoder(d, meta, obj) +return resource<%= object.resource_name -%>Encoder(d, meta, obj) diff --git a/mmv1/templates/terraform/update_mask.erb b/mmv1/templates/terraform/update_mask.erb index d469b2c9e3c7..515abec07aaa 100644 --- a/mmv1/templates/terraform/update_mask.erb +++ b/mmv1/templates/terraform/update_mask.erb @@ -9,13 +9,13 @@ -%> updateMask := []string{} <% - masks_for_props = get_property_update_masks_groups(update_body_properties) + masks_for_props = get_property_update_masks_groups(object.update_body_properties) masks_for_props.each do |prop_name, masks| -%> if d.HasChange("<%= prop_name %>") { updateMask = append(updateMask, <%= masks.map{|m| "\"#{m}\"" }.join(",\n") %>) } -<% end # update_body_properties.each -%> +<% end # object.update_body_properties.each -%> // updateMask is a URL parameter but not present in the schema, so ReplaceVars // won't set it url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) diff --git a/mmv1/templates/tgc/examples/base_configs/test_file.go.erb b/mmv1/templates/tgc/examples/base_configs/test_file.go.erb index de2d6854b47f..8c87bc8c0a5f 100644 --- a/mmv1/templates/tgc/examples/base_configs/test_file.go.erb +++ b/mmv1/templates/tgc/examples/base_configs/test_file.go.erb @@ -18,14 +18,14 @@ terraform_name = object.legacy_name || "google_#{tf_product}_#{tf_resource}" -%> <% # @api.version_obj_or_closest(version) is slightly wrong; we want the _object_ version or the generation version. -# Ultimately this won't matter though, since the API default should always be less than the object default. +# Ultimately this will not matter though, since the API default should always be less than the object default. object.examples .reject(&:skip_test) .reject { |e| @api.version_obj_or_closest(version) < @api.version_obj_or_closest(e.min_version) } .each do |example| # {Compute}{Address}_{addressBasic} - test_slug = "#{resource_name}_#{example.name.camelize(:lower)}Example" + test_slug = "#{object.resource_name}_#{example.name.camelize(:lower)}Example" ignore_read = object.all_user_properties .select{|p| p.url_param_only || p.ignore_read || p.is_a?(Api::Type::ResourceRef) } diff --git a/mmv1/templates/tgc/resource_converter.go.erb b/mmv1/templates/tgc/resource_converter.go.erb index f87e9bfd9e06..20bd286427be 100644 --- a/mmv1/templates/tgc/resource_converter.go.erb +++ b/mmv1/templates/tgc/resource_converter.go.erb @@ -40,25 +40,25 @@ import ( <%= lines(compile(pwd + '/' + object.custom_code.constants)) if object.custom_code.constants -%> -const <%= resource_name -%>AssetType string = "<%= product_backend_name.downcase -%>.googleapis.com/<%= object.name -%>" +const <%= object.resource_name -%>AssetType string = "<%= product_backend_name.downcase -%>.googleapis.com/<%= object.name -%>" -func ResourceConverter<%= resource_name -%>() cai.ResourceConverter { +func ResourceConverter<%= object.resource_name -%>() cai.ResourceConverter { return cai.ResourceConverter{ - AssetType: <%= resource_name -%>AssetType, - Convert: Get<%= resource_name -%>CaiObject, + AssetType: <%= object.resource_name -%>AssetType, + Convert: Get<%= object.resource_name -%>CaiObject, } } -func Get<%= resource_name -%>CaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { +func Get<%= object.resource_name -%>CaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { name, err := cai.AssetName(d, config, "<%= asset_name_template -%>") if err != nil { return []cai.Asset{}, err } - if obj, err := Get<%= resource_name -%>ApiObject(d, config); err == nil { + if obj, err := Get<%= object.resource_name -%>ApiObject(d, config); err == nil { return []cai.Asset{{ Name: name, - Type: <%= resource_name -%>AssetType, + Type: <%= object.resource_name -%>AssetType, Resource: &cai.AssetResource{ Version: "<%= api_version -%>", DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/<%= product_backend_name.downcase -%>/<%= api_version -%>/rest", @@ -71,13 +71,13 @@ func Get<%= resource_name -%>CaiObject(d tpgresource.TerraformResourceData, conf } } -func Get<%= resource_name -%>ApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { +func Get<%= object.resource_name -%>ApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { obj := make(map[string]interface{}) <% object.settable_properties.each do |prop| -%> <% if prop.flatten_object -%> - <%= prop.api_name -%>Prop, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(nil, d, config) + <%= prop.api_name -%>Prop, err := expand<%= object.resource_name -%><%= titlelize_property(prop) -%>(nil, d, config) <% else # if flatten -%> - <%= prop.api_name -%>Prop, err := expand<%= resource_name -%><%= titlelize_property(prop) -%>(d.Get("<%= prop.name.underscore -%>"), d, config) + <%= prop.api_name -%>Prop, err := expand<%= object.resource_name -%><%= titlelize_property(prop) -%>(d.Get("<%= prop.name.underscore -%>"), d, config) <% end -%> if err != nil { return nil, err @@ -91,19 +91,19 @@ func Get<%= resource_name -%>ApiObject(d tpgresource.TerraformResourceData, conf <% end -%> <% if object.custom_code.encoder -%> - return resource<%= resource_name -%>Encoder(d, config, obj) + return resource<%= object.resource_name -%>Encoder(d, config, obj) <% else -%> return obj, nil <% end -%> } <% if object.custom_code.encoder -%> -func resource<%= resource_name -%>Encoder(d tpgresource.TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { +func resource<%= object.resource_name -%>Encoder(d tpgresource.TerraformResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) { <%= lines(compile(pwd + '/' + object.custom_code.encoder)) -%> } <% end -%> <% object.settable_properties.each do |prop| -%> -<%= lines(build_expand_method(resource_name, prop, object, pwd), 1) -%> +<%= lines(build_expand_method(object.resource_name, prop, object, pwd), 1) -%> <% end -%> diff --git a/mmv1/templates/tgc/resource_converter_iam.go.erb b/mmv1/templates/tgc/resource_converter_iam.go.erb index a0d9272e7419..f687cdd7aa5d 100644 --- a/mmv1/templates/tgc/resource_converter_iam.go.erb +++ b/mmv1/templates/tgc/resource_converter_iam.go.erb @@ -43,70 +43,70 @@ import ( ) // Provide a separate asset type constant so we don't have to worry about name conflicts between IAM and non-IAM converter files -const <%= resource_name -%>IAMAssetType string = "<%= product_backend_name.downcase -%>.googleapis.com/<%= object.name -%>" +const <%= object.resource_name -%>IAMAssetType string = "<%= product_backend_name.downcase -%>.googleapis.com/<%= object.name -%>" -func ResourceConverter<%= resource_name -%>IamPolicy() cai.ResourceConverter { +func ResourceConverter<%= object.resource_name -%>IamPolicy() cai.ResourceConverter { return cai.ResourceConverter{ - AssetType: <%= resource_name -%>IAMAssetType, - Convert: Get<%= resource_name -%>IamPolicyCaiObject, - MergeCreateUpdate: Merge<%= resource_name -%>IamPolicy, + AssetType: <%= object.resource_name -%>IAMAssetType, + Convert: Get<%= object.resource_name -%>IamPolicyCaiObject, + MergeCreateUpdate: Merge<%= object.resource_name -%>IamPolicy, } } -func ResourceConverter<%= resource_name -%>IamBinding() cai.ResourceConverter { +func ResourceConverter<%= object.resource_name -%>IamBinding() cai.ResourceConverter { return cai.ResourceConverter{ - AssetType: <%= resource_name -%>IAMAssetType, - Convert: Get<%= resource_name -%>IamBindingCaiObject, - FetchFullResource: Fetch<%= resource_name -%>IamPolicy, - MergeCreateUpdate: Merge<%= resource_name -%>IamBinding, - MergeDelete: Merge<%= resource_name -%>IamBindingDelete, + AssetType: <%= object.resource_name -%>IAMAssetType, + Convert: Get<%= object.resource_name -%>IamBindingCaiObject, + FetchFullResource: Fetch<%= object.resource_name -%>IamPolicy, + MergeCreateUpdate: Merge<%= object.resource_name -%>IamBinding, + MergeDelete: Merge<%= object.resource_name -%>IamBindingDelete, } } -func ResourceConverter<%= resource_name -%>IamMember() cai.ResourceConverter { +func ResourceConverter<%= object.resource_name -%>IamMember() cai.ResourceConverter { return cai.ResourceConverter{ - AssetType: <%= resource_name -%>IAMAssetType, - Convert: Get<%= resource_name -%>IamMemberCaiObject, - FetchFullResource: Fetch<%= resource_name -%>IamPolicy, - MergeCreateUpdate: Merge<%= resource_name -%>IamMember, - MergeDelete: Merge<%= resource_name -%>IamMemberDelete, + AssetType: <%= object.resource_name -%>IAMAssetType, + Convert: Get<%= object.resource_name -%>IamMemberCaiObject, + FetchFullResource: Fetch<%= object.resource_name -%>IamPolicy, + MergeCreateUpdate: Merge<%= object.resource_name -%>IamMember, + MergeDelete: Merge<%= object.resource_name -%>IamMemberDelete, } } -func Get<%= resource_name -%>IamPolicyCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { - return new<%= resource_name -%>IamAsset(d, config, cai.ExpandIamPolicyBindings) +func Get<%= object.resource_name -%>IamPolicyCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return new<%= object.resource_name -%>IamAsset(d, config, cai.ExpandIamPolicyBindings) } -func Get<%= resource_name -%>IamBindingCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { - return new<%= resource_name -%>IamAsset(d, config, cai.ExpandIamRoleBindings) +func Get<%= object.resource_name -%>IamBindingCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return new<%= object.resource_name -%>IamAsset(d, config, cai.ExpandIamRoleBindings) } -func Get<%= resource_name -%>IamMemberCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { - return new<%= resource_name -%>IamAsset(d, config, cai.ExpandIamMemberBindings) +func Get<%= object.resource_name -%>IamMemberCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return new<%= object.resource_name -%>IamAsset(d, config, cai.ExpandIamMemberBindings) } -func Merge<%= resource_name -%>IamPolicy(existing, incoming cai.Asset) cai.Asset { +func Merge<%= object.resource_name -%>IamPolicy(existing, incoming cai.Asset) cai.Asset { existing.IAMPolicy = incoming.IAMPolicy return existing } -func Merge<%= resource_name -%>IamBinding(existing, incoming cai.Asset) cai.Asset { +func Merge<%= object.resource_name -%>IamBinding(existing, incoming cai.Asset) cai.Asset { return cai.MergeIamAssets(existing, incoming, cai.MergeAuthoritativeBindings) } -func Merge<%= resource_name -%>IamBindingDelete(existing, incoming cai.Asset) cai.Asset { +func Merge<%= object.resource_name -%>IamBindingDelete(existing, incoming cai.Asset) cai.Asset { return cai.MergeDeleteIamAssets(existing, incoming, cai.MergeDeleteAuthoritativeBindings) } -func Merge<%= resource_name -%>IamMember(existing, incoming cai.Asset) cai.Asset { +func Merge<%= object.resource_name -%>IamMember(existing, incoming cai.Asset) cai.Asset { return cai.MergeIamAssets(existing, incoming, cai.MergeAdditiveBindings) } -func Merge<%= resource_name -%>IamMemberDelete(existing, incoming cai.Asset) cai.Asset { +func Merge<%= object.resource_name -%>IamMemberDelete(existing, incoming cai.Asset) cai.Asset { return cai.MergeDeleteIamAssets(existing, incoming, cai.MergeDeleteAdditiveBindings) } -func new<%= resource_name -%>IamAsset( +func new<%= object.resource_name -%>IamAsset( d tpgresource.TerraformResourceData, config *transport_tpg.Config, expandBindings func(d tpgresource.TerraformResourceData) ([]cai.IAMBinding, error), @@ -123,14 +123,14 @@ func new<%= resource_name -%>IamAsset( return []cai.Asset{{ Name: name, - Type: <%= resource_name -%>IAMAssetType, + Type: <%= object.resource_name -%>IAMAssetType, IAMPolicy: &cai.IAMPolicy{ Bindings: bindings, }, }}, nil } -func Fetch<%= resource_name -%>IamPolicy(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (cai.Asset, error) { +func Fetch<%= object.resource_name -%>IamPolicy(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (cai.Asset, error) { // Check if the identity field returns a value <% resource_params.each do |param| -%> if _, ok := d.GetOk("<%= param.underscore -%>"); !ok { @@ -140,10 +140,10 @@ func Fetch<%= resource_name -%>IamPolicy(d tpgresource.TerraformResourceData, co return cai.FetchIamPolicy( - <%= resource_name -%>IamUpdaterProducer, + <%= object.resource_name -%>IamUpdaterProducer, d, config, "<%= asset_name_template -%>", - <%= resource_name -%>IAMAssetType, + <%= object.resource_name -%>IAMAssetType, ) }