-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datastream check private connection state after create and update (#6862
) * Add desired state field to make sure PC is created in CREATED - b/260057913 * Revert virtual field * Add state field check to make sure PC is created in CREATED - b/260057913 * Add error details and message in failure cases. * Fix message formatting * Added a post import impl
- Loading branch information
1 parent
9372b5d
commit ff00705
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
mmv1/templates/terraform/constants/private_connection.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<% unless compiler == "terraformvalidator-codegen" -%> | ||
|
||
func extractError(d *schema.ResourceData) error { | ||
// Casts are not safe since the logic that populate it is type deterministic. | ||
error := d.Get("error").([]interface{})[0].(map[string]interface{}) | ||
message := error["message"].(string) | ||
details := error["details"].(map[string]interface{}) | ||
detailsJSON, _ := json.Marshal(details) | ||
return fmt.Errorf("Failed to create PrivateConnection. %s details = %s", message, string(detailsJSON)) | ||
} | ||
|
||
// waitForPrivateConnectionReady waits for a private connection state to become | ||
// CREATED, if the state is FAILED propegate the error to the user. | ||
func waitForPrivateConnectionReady(d *schema.ResourceData, config *Config, timeout time.Duration) error { | ||
return resource.Retry(timeout, func() *resource.RetryError { | ||
if err := resourceDatastreamPrivateConnectionRead(d, config); err != nil { | ||
return resource.NonRetryableError(err) | ||
} | ||
|
||
name := d.Get("name").(string) | ||
state := d.Get("state").(string) | ||
if state == "CREATING" { | ||
return resource.RetryableError(fmt.Errorf("PrivateConnection %q has state %q.", name, state)) | ||
} else if state == "CREATED" { | ||
log.Printf("[DEBUG] PrivateConnection %q has state %q.", name, state) | ||
return nil | ||
} else if state == "FAILED" { | ||
return resource.NonRetryableError(extractError(d)) | ||
} else { | ||
return resource.NonRetryableError(fmt.Errorf("PrivateConnection %q has state %q.", name, state)) | ||
} | ||
}) | ||
} | ||
<% end -%> |
3 changes: 3 additions & 0 deletions
3
mmv1/templates/terraform/post_create/private_connection.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if err := waitForPrivateConnectionReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { | ||
return fmt.Errorf("Error waiting for PrivateConnection %q to be CREATED. %q", d.Get("name").(string), err) | ||
} |
3 changes: 3 additions & 0 deletions
3
mmv1/templates/terraform/post_import/private_connection.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if err := waitForPrivateConnectionReady(d, config, d.Timeout(schema.TimeoutCreate) - time.Minute); err != nil { | ||
return nil, fmt.Errorf("Error waiting for PrivateConnection %q to be CREATED during importing: %q", d.Get("name").(string), err) | ||
} |