Skip to content

Commit

Permalink
Update CodeRepositoryIndex and RepositoryGroup 409 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JumiDeluxe committed Nov 15, 2024
1 parent be8cc8c commit 2eec99a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 158 deletions.
1 change: 0 additions & 1 deletion mmv1/products/cloudaicompanion/CodeRepositoryIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async:
message: message
include_project: false
custom_code:
custom_create: templates/terraform/custom_create/code_repository_index.go.tmpl
custom_update: templates/terraform/custom_update/code_repository_index.go.tmpl
parameters:
- name: location
Expand Down
121 changes: 0 additions & 121 deletions mmv1/templates/terraform/custom_create/code_repository_index.go.tmpl

This file was deleted.

12 changes: 10 additions & 2 deletions mmv1/templates/terraform/custom_create/repository_group.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", err)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before creating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error creating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error creating RepositoryGroup: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating CodeRepositoryIndex: %#v", obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", err)
if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before updating CodeRepositoryIndex: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error updating CodeRepositoryIndex %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error updating CodeRepositoryIndex: %s", err)
return fmt.Errorf("Error updating CodeRepositoryIndex %q: %s", d.Id(), err)
}
} else {
break
Expand Down
14 changes: 11 additions & 3 deletions mmv1/templates/terraform/custom_update/repository_group.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating RepositoryGroup %q: %#v", d.Id(), obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", err)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before updating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error updating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error updating RepositoryGroup: %s", err)
return fmt.Errorf("Error updating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
break
Expand Down
47 changes: 23 additions & 24 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1626,10 +1626,18 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish")
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", err)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before creating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
t.Fatalf("Error creating RepositoryGroup: %s", err)
}
} else {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
t.Fatalf("Error creating repository group %q: %s", repositoryGroupId, err)
}
} else {
break
Expand Down Expand Up @@ -1700,27 +1708,18 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
}

headers := make(http.Header)
for {
_, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: config.Project,
RawURL: postURL,
UserAgent: config.UserAgent,
Body: obj,
Timeout: 90 * time.Minute,
Headers: headers,
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish")
time.Sleep(3 * time.Minute)
} else {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
}
} else {
break
}
_, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: config.Project,
RawURL: postURL,
UserAgent: config.UserAgent,
Body: obj,
Timeout: 90 * time.Minute,
Headers: headers,
})
if err != nil {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"


"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
Expand Down Expand Up @@ -58,7 +56,7 @@ func TestAccGeminiRepositoryGroupIamBinding(t *testing.T) {

func TestAccGeminiRepositoryGroupIamMember(t *testing.T) {
location := "us-central1"
codeRepositoryIndexId := acctest.BootstrapSharedCodeRepositoryIndex(t, "basic", location, "", "")
codeRepositoryIndexId := acctest.BootstrapSharedCodeRepositoryIndex(t, "basic", location, "", map[string]string{"ccfe_debug_note": "terraform_e2e_should_be_deleted"})
developerConnectionId := acctest.BootstrapDeveloperConnection(t, "basic", location, "projects/502367051001/secrets/tf-test-cloudaicompanion-github-oauthtoken-c42e5c/versions/1", 54180648)
gitRepositoryLinkId := acctest.BootstrapGitRepository(t, "basic", location, "https://github.com/CC-R-github-robot/tf-test.git", developerConnectionId)
repositoryGroupId := acctest.BoostrapSharedRepositoryGroup(t, "basic", location, "", codeRepositoryIndexId,
Expand Down Expand Up @@ -92,7 +90,7 @@ func TestAccGeminiRepositoryGroupIamMember(t *testing.T) {

func TestAccGeminiRepositoryGroupIamPolicy(t *testing.T) {
location := "us-central1"
codeRepositoryIndexId := acctest.BootstrapSharedCodeRepositoryIndex(t, "basic", location, "", "")
codeRepositoryIndexId := acctest.BootstrapSharedCodeRepositoryIndex(t, "basic", location, "", map[string]string{"ccfe_debug_note": "terraform_e2e_should_be_deleted"})
developerConnectionId := acctest.BootstrapDeveloperConnection(t, "basic", location, "projects/502367051001/secrets/tf-test-cloudaicompanion-github-oauthtoken-c42e5c/versions/1", 54180648)
gitRepositoryLinkId := acctest.BootstrapGitRepository(t, "basic", location, "https://github.com/CC-R-github-robot/tf-test.git", developerConnectionId)
repositoryGroupId := acctest.BoostrapSharedRepositoryGroup(t, "basic", location, "", codeRepositoryIndexId,
Expand Down

0 comments on commit 2eec99a

Please sign in to comment.