Skip to content

Commit

Permalink
Merge pull request #175 from citrix/enhancements
Browse files Browse the repository at this point in the history
Enhancements
  • Loading branch information
George Nikolopoulos authored Jul 16, 2021
2 parents 62396b6 + b69285b commit 94b3a86
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
67 changes: 66 additions & 1 deletion citrixadc/resource_citrixadc_nsconfig_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions docs/resources/nsconfig_save.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94b3a86

Please sign in to comment.