Hello
I have the situation when refreshing plan there is field which I don’t update from schema.
And when update function is called there are created empty request and because it’s failed.
2021/01/15 13:20:22 [DEBUG] UserGroup update configuration: &testgo.UserGroupEditRequest{Label:"", RoleIDs:[]string(nil), BillingPlanIDs:[]int(nil)}
How I can skip calling update function if some fields are updated in place???
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# module.ug["tf_ug"].user_group.ug will be updated in-place
~ resource "user_group" "ug" {
label = "tf_ug"
preconfigured_only = false
provider_vdc_id = 0
+ roles = (known after apply)
updated_at = "2021-01-15T11:52:43.000Z"
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: datasourceRoleSchema(),
},
},
func resourceUserGroupUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*CombinedConfig).testgoClient()
if client == nil {
return fmt.Errorf("[ERROR] testgoClient return nil")
}
id, err := strconv.Atoi(d.Id())
if err != nil {
return fmt.Errorf("invalid user group id: %v", err)
}
opts := &testgo.UserGroupEditRequest{}
// Enable partial state mode
d.Partial(true)
if d.HasChange("label") {
opts.Label = d.Get("label").(string)
}
if d.HasChange("role_ids") {
if attr, ok := d.GetOk("role_ids"); ok {
opts.RoleIDs = expandSliceOfString(attr.(*schema.Set).List())
}
}
if d.HasChange("billing_plan_ids") {
if attr, ok := d.GetOk("billing_plan_ids"); ok {
opts.BillingPlanIDs = expandBillingPlanIDs(attr.([]interface{}))
}
}
d.Partial(false)
log.Printf("[DEBUG] UserGroup update configuration: %#v", opts)
_, err = client.UserGroups.Edit(context.Background(), id, opts)
if err != nil {
return fmt.Errorf("[ERROR] Error updating UserGroup: %s", err)
}
return resourceUserGroupRead(d, meta)
}