Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added wait logic for tags async #5174

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
rg "github.com/IBM/platform-services-go-sdk/resourcemanagerv2"
"github.com/apache/openwhisk-client-go/whisk"
"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/softlayer/softlayer-go/datatypes"
"github.com/softlayer/softlayer-go/sl"
Expand Down Expand Up @@ -2558,11 +2559,44 @@ func UpdateGlobalTagsUsingCRN(oldList, newList interface{}, meta interface{}, re
if err != nil {
return fmt.Errorf("[ERROR] Error updating database tags %v : %s\n%s", add, err, resp)
}
response, errored := waitForTagsAvailable(meta, resourceID, resourceType, tagType, news, 30*time.Second)
uibm marked this conversation as resolved.
Show resolved Hide resolved
if errored != nil {
log.Printf(`[ERROR] Error waiting for tags database tags %s : %v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database tags means?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to resource tags. Database tags is tags on remote

%v`, resourceID, errored, response)
}
}

return nil
}

func waitForTagsAvailable(meta interface{}, resourceID, resourceType, tagType string, desired *schema.Set, timeout time.Duration) (interface{}, error) {
log.Printf("Waiting for tag attachment (%s) to be successful.", resourceID)

stateConf := &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"success", "error"},
Refresh: tagsRefreshFunc(meta, resourceID, resourceType, tagType, desired),
Timeout: timeout,
Delay: 3 * time.Second,
MinTimeout: 3 * time.Second,
}
return stateConf.WaitForState()
}

func tagsRefreshFunc(meta interface{}, resourceID, resourceType, tagType string, desired *schema.Set) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
tags, err := GetGlobalTagsUsingCRN(meta, resourceID, resourceType, tagType)
if err != nil {
return tags, "error", fmt.Errorf("[ERROR] Error on get of resource tags (%s) tags: %s", resourceID, err)
}
if tags.Equal(desired) {
return tags, "success", nil
} else {
return tags, "pending", nil
}
}
}

func ResourceIBMVPCHash(v interface{}) int {
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("%s",
Expand Down
Loading