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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended wait logic to ibm_resource_tag #5251

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ 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)
response, errored := WaitForTagsAvailable(meta, resourceID, resourceType, tagType, news, 30*time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of harcoded 30 sec declare timeouts in schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to timeout, default is 30 seconds and updated the docs

if errored != nil {
log.Printf(`[ERROR] Error waiting for resource tags %s : %v
%v`, resourceID, errored, response)
Expand All @@ -2569,7 +2569,7 @@ func UpdateGlobalTagsUsingCRN(oldList, newList interface{}, meta interface{}, re
return nil
}

func waitForTagsAvailable(meta interface{}, resourceID, resourceType, tagType string, desired *schema.Set, timeout time.Duration) (interface{}, error) {
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{
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/globaltagging/resource_ibm_resource_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package globaltagging
import (
"context"
"fmt"
"log"
"os"
"strings"
"time"

"github.com/IBM/platform-services-go-sdk/globaltaggingv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
Expand Down Expand Up @@ -143,8 +145,10 @@ func resourceIBMResourceTagCreate(d *schema.ResourceData, meta interface{}) erro
resources = append(resources, r)

var add []string
var news *schema.Set
if v, ok := d.GetOk(tags); ok {
tags := v.(*schema.Set)
news = v.(*schema.Set)
for _, t := range tags.List() {
add = append(add, fmt.Sprint(t))
}
Expand Down Expand Up @@ -183,6 +187,11 @@ func resourceIBMResourceTagCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("[ERROR] Error attaching resource tags : %v\n%s", resp, err)
}
response, errored := flex.WaitForTagsAvailable(meta, resourceID, resourceType, tagType, news, 30*time.Second)
if errored != nil {
log.Printf(`[ERROR] Error waiting for resource tags %s : %v
%v`, resourceID, errored, response)
}
}

if strings.HasPrefix(resourceID, "crn:") {
Expand Down
35 changes: 35 additions & 0 deletions ibm/service/globaltagging/resource_ibm_resource_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ func TestAccResourceTag_Basic(t *testing.T) {
},
})
}
func TestAccResourceTag_Wait(t *testing.T) {
name := fmt.Sprintf("tf-satellitelocation-%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{

{
Config: testAccCheckResourceTagWaitCreate(name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckResourceTagExists("ibm_resource_tag.tag"),
resource.TestCheckResourceAttr("ibm_resource_tag.tag", "tags.#", "3"),
),
},
},
})
}

func testAccCheckResourceTagExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -72,6 +90,23 @@ func testAccCheckResourceTagExists(n string) resource.TestCheckFunc {
}
}

func testAccCheckResourceTagWaitCreate(name string) string {
return fmt.Sprintf(`

resource "ibm_is_vpc" "vpc" {
name = "%s"
}

data "ibm_is_vpc" "test_vpc" {
name = ibm_is_vpc.vpc.name
}

resource "ibm_resource_tag" "tag" {
resource_id = data.ibm_is_vpc.test_vpc.crn
tags = ["env:dev", "cpu:4", "user:8"]
}
`, name)
}
func testAccCheckResourceTagCreate(name, managed_from string) string {
return fmt.Sprintf(`

Expand Down