-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update Saas resource in SaasRuntime with applicationTemplate property #17762
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| billingProject := "" | ||
|
|
||
| project, err := tpgresource.GetProject(d, config) | ||
| if err != nil { | ||
| return fmt.Errorf("Error fetching project for Saas: %s", err) | ||
| } | ||
| billingProject = project | ||
| url, err := tpgresource.ReplaceVars(d, config, fmt.Sprintf("%s%s", transport_tpg.BaseUrl(Product, config), "projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}location{{"}}"}}/saas/{{"{{"}}saas_id{{"}}"}}")) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // err == nil indicates that the billing_project value was found | ||
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
| billingProject = bp | ||
| } | ||
|
|
||
| headers := make(http.Header) | ||
|
|
||
| // 1. Wait for the resource to transition out of STATE_RUNNING before deleting | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How long does this reasonably take? Should we set limits here on how long to wait on this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation uses the default timeout of 20 minutes, which we believe is reasonable. Furthermore, leaving the default lets the user configure it if needed; if we set a hardcoded timeout, users would lose the ability to configure a custom value. https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts |
||
| log.Printf("[DEBUG] Waiting for Saas %q to transition out of STATE_RUNNING", d.Id()) | ||
| err = retry.RetryContext(context.Background(), d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { | ||
| res, readErr := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
| Config: config, | ||
| Method: "GET", | ||
| Project: billingProject, | ||
| RawURL: url, | ||
| UserAgent: userAgent, | ||
| Headers: headers, | ||
| }) | ||
| if readErr != nil { | ||
| if transport_tpg.IsGoogleApiErrorWithCode(readErr, 404) { | ||
| return nil // already gone | ||
| } | ||
| return retry.NonRetryableError(readErr) | ||
| } | ||
|
|
||
| state, ok := res["state"].(string) | ||
| if !ok { | ||
| return retry.RetryableError(fmt.Errorf("Saas %q state is not yet populated", d.Id())) | ||
| } | ||
| if state == "STATE_RUNNING" { | ||
| return retry.RetryableError(fmt.Errorf("Saas %q is still in STATE_RUNNING state", d.Id())) | ||
| } | ||
|
|
||
| return nil | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("Error waiting for Saas %q to be ready for deletion: %s", d.Id(), err) | ||
| } | ||
|
|
||
| // 2. Trigger the DELETE request | ||
| log.Printf("[DEBUG] Deleting Saas %q", d.Id()) | ||
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
| Config: config, | ||
| Method: "DELETE", | ||
| Project: billingProject, | ||
| RawURL: url, | ||
| UserAgent: userAgent, | ||
| Timeout: d.Timeout(schema.TimeoutDelete), | ||
| Headers: headers, | ||
| }) | ||
| if err != nil { | ||
| return transport_tpg.HandleNotFoundError(err, d, "Saas") | ||
| } | ||
|
|
||
| log.Printf("[DEBUG] Finished trigger for deleting Saas %q: %#v", d.Id(), res) | ||
|
|
||
| // 3. Wait for the Saas resource to be fully deleted from GCP (eventual consistency) | ||
| err = retry.RetryContext(context.Background(), d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { | ||
| _, readErr := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
| Config: config, | ||
| Method: "GET", | ||
| Project: billingProject, | ||
| RawURL: url, | ||
| UserAgent: userAgent, | ||
| Headers: headers, | ||
| }) | ||
| if readErr != nil { | ||
| if transport_tpg.IsGoogleApiErrorWithCode(readErr, 404) { | ||
| return nil | ||
| } | ||
| return retry.NonRetryableError(readErr) | ||
| } | ||
| return retry.RetryableError(fmt.Errorf("Saas %q still exists", d.Id())) | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("Error waiting for Saas %q to be fully deleted: %s", d.Id(), err) | ||
| } | ||
|
|
||
| return nil | ||
Uh oh!
There was an error while loading. Please reload this page.