diff --git a/huaweicloud/config/force_new.go b/huaweicloud/config/force_new.go index 6eaf41f0ef..f5c26d038a 100644 --- a/huaweicloud/config/force_new.go +++ b/huaweicloud/config/force_new.go @@ -16,12 +16,19 @@ import ( // when non-updatable parameters are changed // if ForceNew is enabled, the resource will be recreated // if ForceNew is not enabled, an error will be raise -func FlexibleForceNew(keys []string) schema.CustomizeDiffFunc { +// if there is DiffSuppressFunc in the schema, this func need resource schema to make DiffSuppressFunc work +func FlexibleForceNew(keys []string, resourceSchemas ...map[string]*schema.Schema) schema.CustomizeDiffFunc { return func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { + var resourceSchema map[string]*schema.Schema + if len(resourceSchemas) > 0 { + resourceSchema = resourceSchemas[0] + } + cfg := meta.(*Config) var err error forceNew := cfg.GetForceNew(d) keysExpand := expandKeys(keys, d) + if forceNew { for _, k := range keysExpand { if err := d.ForceNew(k); err != nil { @@ -32,7 +39,12 @@ func FlexibleForceNew(keys []string) schema.CustomizeDiffFunc { for _, k := range keysExpand { if d.Id() != "" && d.HasChange(k) { oldValue, newValue := d.GetChange(k) - err = multierror.Append(err, fmt.Errorf("%s can't be updated, %v -> %v", k, oldValue, newValue)) + if resourceSchema != nil && resourceSchema[k] != nil && resourceSchema[k].DiffSuppressFunc != nil && + resourceSchema[k].DiffSuppressFunc(k, oldValue.(string), newValue.(string), nil) { + log.Printf("[DEBUG] ignoring change of %s due to DiffSuppressFunc, %v -> %v", k, oldValue, newValue) + } else { + err = multierror.Append(err, fmt.Errorf("%s can't be updated, %v -> %v", k, oldValue, newValue)) + } } } }