From e5707df993fa2b95ea9a7b191f0751c8380204cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20P=C5=82oski?= Date: Thu, 5 Dec 2024 14:32:25 +0100 Subject: [PATCH] Add retry to acl endpoint update --- splunk/resource_splunk_configs_conf.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/splunk/resource_splunk_configs_conf.go b/splunk/resource_splunk_configs_conf.go index b24194e2..e37e4877 100644 --- a/splunk/resource_splunk_configs_conf.go +++ b/splunk/resource_splunk_configs_conf.go @@ -5,10 +5,12 @@ import ( "errors" "fmt" "io" + "log" "net/http" "regexp" "strconv" + "github.com/avast/retry-go/v4" "github.com/splunk/terraform-provider-splunk/client/models" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -65,7 +67,18 @@ func configsConfCreate(d *schema.ResourceData, meta interface{}) error { } if _, ok := d.GetOk("acl"); ok { conf, stanza := (*provider.Client).SplitConfStanza(name) - err := (*provider.Client).UpdateAcl(aclObject.Owner, aclObject.App, stanza, aclObject, "configs", "conf-"+conf) + // add retry as sometimes config object is not yet propagated and acl endpoint return 404 + err = retry.Do( + func() error { + err := (*provider.Client).UpdateAcl(aclObject.Owner, aclObject.App, stanza, aclObject, "configs", "conf-"+conf) + if err != nil { + return err + } + return nil + }, retry.Attempts(10), retry.OnRetry(func(n uint, err error) { + log.Printf("#%d: %s. Retrying...\n", n, err) + }), retry.DelayType(retry.BackOffDelay), + ) if err != nil { return err }