Skip to content

Commit

Permalink
add identity and polling
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 committed Oct 12, 2020
1 parent a1eeaf2 commit b883116
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
7 changes: 7 additions & 0 deletions products/accesscontextmanager/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ objects:
delete_verb: :PATCH
input: true
update_mask: true
identity:
- ipSubnetworks
- requiredAccessLevels
- members
- negate
- devicePolicy
- regions
nested_query: !ruby/object:Api::Resource::NestedQuery
modify_by_patch: true
keys:
Expand Down
6 changes: 6 additions & 0 deletions products/accesscontextmanager/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides
in the provider configuration. Otherwise the ACM API will return a 403 error.
Your account must have the `serviceusage.services.use` permission on the
`billing_project` you defined.
async: !ruby/object:Provider::Terraform::PollAsync
check_response_func_existence: PollCheckForExistence
actions: ['create']
operation: !ruby/object:Api::Async::Operation
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 4
autogen_async: true
exclude_validator: true
exclude_import: true # no unique way to specify
Expand Down
35 changes: 7 additions & 28 deletions templates/terraform/nested_query.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,14 @@ 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)
}

// create desired object
config := meta.(*Config)
desiredObj := 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)
if err != nil {
return nil, err
<% if prop.send_empty_value -%>
} else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop) {
<% elsif prop.flatten_object -%>
} else if !isEmptyValue(reflect.ValueOf(<%= prop.api_name -%>Prop)) {
<% else -%>
} else if v, ok := d.GetOkExists("<%= prop.name.underscore -%>"); !isEmptyValue(reflect.ValueOf(<%= prop.api_name -%>Prop)) && (ok || !reflect.DeepEqual(v, <%= prop.api_name -%>Prop)) {
<% end -%>
desiredObj["<%= prop.api_name -%>"] = <%= prop.api_name -%>Prop
}
<% end -%>

_, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, v.([]interface{}), desiredObj)
_, item, err := resource<%=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{}, obj map[string]interface{}) (index int, item map[string]interface{}, err error) {
func resource<%=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.(*Config))
Expand Down Expand Up @@ -95,10 +76,8 @@ func resource<%=resource_name%>FindNestedObjectInList(d *schema.ResourceData, me
continue
}
<% end -%>
if reflect.DeepEqual(item, obj) {
log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item)
return idx, item, nil
}
log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item)
return idx, item, nil
}
return -1, nil, nil
}
Expand All @@ -115,7 +94,7 @@ func resource<%= resource_name -%>PatchCreateEncoder(d *schema.ResourceData, met
return nil, err
}

_, found, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems, obj)
_, found, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -172,7 +151,7 @@ func resource<%= resource_name -%>PatchUpdateEncoder(d *schema.ResourceData, met
return nil, err
}

idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, items, obj)
idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, items)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -212,7 +191,7 @@ func resource<%= resource_name -%>PatchDeleteEncoder(d *schema.ResourceData, met
return nil, err
}

idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems, obj)
idx, item, err := resource<%=resource_name%>FindNestedObjectInList(d, meta, currItems)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b883116

Please sign in to comment.