diff --git a/CHANGELOG.md b/CHANGELOG.md index 42b388a14..3bccdf2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.5.0 (July 16, 2021) + +ENHANCEMENTS + +* add `save_on_destroy` option in `nsconfig_save` resrouce + ## 1.4.0 (July 13, 2021) FEATURES diff --git a/citrixadc/resource_citrixadc_nsconfig_save.go b/citrixadc/resource_citrixadc_nsconfig_save.go index c0c23d6c5..05cd62d8d 100644 --- a/citrixadc/resource_citrixadc_nsconfig_save.go +++ b/citrixadc/resource_citrixadc_nsconfig_save.go @@ -17,7 +17,7 @@ func resourceCitrixAdcNsconfigSave() *schema.Resource { SchemaVersion: 1, Create: createNsconfigSaveFunc, Read: schema.Noop, - Delete: schema.Noop, + Delete: deleteNsconfigSaveFunc, Schema: map[string]*schema.Schema{ "all": &schema.Schema{ Type: schema.TypeBool, @@ -53,6 +53,12 @@ func resourceCitrixAdcNsconfigSave() *schema.Resource { Default: "10s", ForceNew: true, }, + "save_on_destroy": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: false, + ForceNew: true, + }, }, } } @@ -141,3 +147,62 @@ func saveConfigPoll(d *schema.ResourceData, meta interface{}) resource.StateRefr } } } + +func deleteNsconfigSaveFunc(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] citrixadc-provider: In deleteNsconfigSaveFunc") + + if !d.Get("save_on_destroy").(bool) { + log.Printf("[DEBUG] citrixadc-provider: No save_on_destroy") + d.SetId("") + return nil + } + // Fallthrough + + err := doSaveConfig(d, meta) + + if err != nil { + if !strings.Contains(err.Error(), "\"errorcode\": 293") { + return err + } + // Fallthrough + + // Check concurrent save flag + if !d.Get("concurrent_save_ok").(bool) { + return err + } + // Fallthrough + + concurrentSaveRetries := d.Get("concurrent_save_retries").(int) + + // Do retries only when it is a non zero value + if concurrentSaveRetries > 0 { + + // Do retries + var concurrent_save_interval time.Duration + if concurrent_save_interval, err = time.ParseDuration(d.Get("concurrent_save_interval").(string)); err != nil { + return err + } + + var concurrent_save_timeout time.Duration + if concurrent_save_timeout, err = time.ParseDuration(d.Get("concurrent_save_timeout").(string)); err != nil { + return err + } + stateConf := &resource.StateChangeConf{ + Pending: []string{"saving"}, + Target: []string{"saved"}, + Refresh: saveConfigPoll(d, meta), + PollInterval: concurrent_save_interval, + Delay: concurrent_save_interval, + Timeout: concurrent_save_timeout, + NotFoundChecks: concurrentSaveRetries, + } + + _, err = stateConf.WaitForState() + if err != nil { + return err + } + } + } + d.SetId("") + return nil +} diff --git a/docs/resources/nsconfig_save.md b/docs/resources/nsconfig_save.md index 4a164aa02..f5ddc9562 100644 --- a/docs/resources/nsconfig_save.md +++ b/docs/resources/nsconfig_save.md @@ -25,6 +25,7 @@ resource "citrixadc_nsconfig_save" "tf_ns_save" { * `concurrent_save_retries` - (Optional) Number of retries after which we throw an error for the concurrent save error code. * `concurrent_save_timeout` - (Optional) Time period after which we throw an error for the concurrent save error code. * `concurrent_save_interval` - (Optional) Time period between tries to save the resource when processing the save error workflow. +* `save_on_destroy` - (Optional) Boolean flag. If set to `true` then the save configuration operation will be applied during the destroy operation. Defaults to `false`. ## Attribute Reference