-
Notifications
You must be signed in to change notification settings - Fork 231
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
Fix migration to terraform-plugin-testing causes panic in existing test suite #1167
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: ENHANCEMENTS | ||
body: 'helper/id: New `helper/id` package added. `resource.PrefixedUniqueId()` and | ||
`resource.UniqueId()` are deprecated, `helper/id` should be used instead. `helper/resource` | ||
now contains aliases to the migrated code' | ||
time: 2023-03-10T13:23:24.648529Z | ||
custom: | ||
Issue: "1167" |
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,7 @@ | ||
kind: ENHANCEMENTS | ||
body: 'helper/retry: New `helper/retry` package added. `resource.RetryContext()`, | ||
`resource.StateChangeConf`, and associated `*Error` types are deprecated, `helper/retry` | ||
should be used instead. `helper/resource now contains aliases to the migrated code' | ||
time: 2023-03-10T13:25:39.920985Z | ||
custom: | ||
Issue: "1167" |
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,6 @@ | ||
kind: NOTES | ||
body: 'helper/resource: Deprecated `PrefixedUniqueId()` and `UniqueId()`. Use the | ||
`helper/id` package instead. These deprecations are to assist in migrating to terraform-plugin-testing' | ||
time: 2023-03-10T13:15:53.740137Z | ||
custom: | ||
Issue: "1167" |
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,7 @@ | ||
kind: NOTES | ||
body: 'helper/resource: Deprecated `RetryContext()`, `StateChangeConf`, and associated | ||
`*Error` types. Use the `helper/retry` package instead. These deprecations are to | ||
assist in migrating to terraform-plugin-testing' | ||
time: 2023-03-10T13:17:09.544612Z | ||
custom: | ||
Issue: "1167" |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package id | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package id | ||
|
||
import ( | ||
"regexp" | ||
|
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,142 @@ | ||
package resource | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
) | ||
|
||
// Deprecated: Use helper/id package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
const UniqueIdPrefix = id.UniqueIdPrefix | ||
|
||
// Helper for a resource to generate a unique identifier w/ default prefix | ||
// | ||
// Deprecated: Use helper/id package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func UniqueId() string { | ||
return id.UniqueId() | ||
} | ||
|
||
// Deprecated: Use helper/id package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
const UniqueIDSuffixLength = id.UniqueIDSuffixLength | ||
|
||
// Helper for a resource to generate a unique identifier w/ given prefix | ||
// | ||
// After the prefix, the ID consists of an incrementing 26 digit value (to match | ||
// previous timestamp output). After the prefix, the ID consists of a timestamp | ||
// and an incrementing 8 hex digit value The timestamp means that multiple IDs | ||
// created with the same prefix will sort in the order of their creation, even | ||
// across multiple terraform executions, as long as the clock is not turned back | ||
// between calls, and as long as any given terraform execution generates fewer | ||
// than 4 billion IDs. | ||
// | ||
// Deprecated: Use helper/id package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func PrefixedUniqueId(prefix string) string { | ||
return id.PrefixedUniqueId(prefix) | ||
} | ||
|
||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type NotFoundError retry.NotFoundError | ||
|
||
// UnexpectedStateError is returned when Refresh returns a state that's neither in Target nor Pending | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type UnexpectedStateError retry.UnexpectedStateError | ||
|
||
// TimeoutError is returned when WaitForState times out | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type TimeoutError retry.TimeoutError | ||
|
||
// StateRefreshFunc is a function type used for StateChangeConf that is | ||
// responsible for refreshing the item being watched for a state change. | ||
// | ||
// It returns three results. `result` is any object that will be returned | ||
// as the final object after waiting for state change. This allows you to | ||
// return the final updated object, for example an EC2 instance after refreshing | ||
// it. A nil result represents not found. | ||
// | ||
// `state` is the latest state of that object. And `err` is any error that | ||
// may have happened while refreshing the state. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type StateRefreshFunc retry.StateRefreshFunc | ||
|
||
// StateChangeConf is the configuration struct used for `WaitForState`. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type StateChangeConf retry.StateChangeConf | ||
|
||
// RetryFunc is the function retried until it succeeds. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type RetryFunc retry.RetryFunc | ||
|
||
// RetryContext is a basic wrapper around StateChangeConf that will just retry | ||
// a function until it no longer returns an error. | ||
// | ||
// Cancellation from the passed in context will propagate through to the | ||
// underlying StateChangeConf | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func RetryContext(ctx context.Context, timeout time.Duration, f RetryFunc) error { | ||
return retry.RetryContext(ctx, timeout, retry.RetryFunc(f)) | ||
} | ||
|
||
// Retry is a basic wrapper around StateChangeConf that will just retry | ||
// a function until it no longer returns an error. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func Retry(timeout time.Duration, f RetryFunc) error { | ||
return retry.Retry(timeout, retry.RetryFunc(f)) | ||
} | ||
|
||
// RetryError is the required return type of RetryFunc. It forces client code | ||
// to choose whether or not a given error is retryable. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
type RetryError retry.RetryError | ||
|
||
// RetryableError is a helper to create a RetryError that's retryable from a | ||
// given error. To prevent logic errors, will return an error when passed a | ||
// nil error. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func RetryableError(err error) *RetryError { | ||
r := retry.RetryableError(err) | ||
|
||
return &RetryError{ | ||
Err: r.Err, | ||
Retryable: r.Retryable, | ||
} | ||
} | ||
|
||
// NonRetryableError is a helper to create a RetryError that's _not_ retryable | ||
// from a given error. To prevent logic errors, will return an error when | ||
// passed a nil error. | ||
// | ||
// Deprecated: Use helper/retry package instead. This is required for migrating acceptance | ||
// testing to terraform-plugin-testing. | ||
func NonRetryableError(err error) *RetryError { | ||
r := retry.NonRetryableError(err) | ||
|
||
return &RetryError{ | ||
Err: r.Err, | ||
Retryable: r.Retryable, | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package retry | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package retry | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package retry | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package retry | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package resource | ||
package retry | ||
|
||
import ( | ||
"context" | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add the exports from the new
id
package to this set of aliases as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++1