-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Redshift snapshot copy grant #5134
Conversation
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.
Hi @f0rk 👋 Thanks for submitting this! Please see the below for some initial feedback and let us know if you have any questions or do not have time to implement it.
|
||
var out *redshift.CreateSnapshotCopyGrantOutput | ||
|
||
err := resource.Retry(3*time.Minute, func() *resource.RetryError { |
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.
Given there are no resource.RetryableError()
calls, the resource.Retry
logic should be removed.
|
||
log.Printf("[DEBUG] Created new Redshift SnapshotCopyGrant: %s", *out.SnapshotCopyGrant.SnapshotCopyGrantName) | ||
d.SetId(grantName) | ||
d.Set("snapshot_copy_grant_name", out.SnapshotCopyGrant.SnapshotCopyGrantName) |
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.
d.Set()
calls should only occur in the read function. This allows us to ensure we have successfully created and can read back the API object.
return nil | ||
} | ||
|
||
if *grant.KmsKeyId != "" { |
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.
To prevent nil
dereferencing panics, this if
statement should either check against nil
or be removed (as d.Set()
can appropriately handle same type pointers (e.g. *string
with TypeString
))
grant, err := findAwsRedshiftSnapshotCopyGrantWithRetry(conn, grantName) | ||
|
||
if err != nil { | ||
return true, err |
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.
While the error should take precedence, this should probably return false, err
return nil, NewAwsRedshiftSnapshotCopyGrantMissingError(fmt.Sprintf("[DEBUG] Grant %s not found", grantName)) | ||
} | ||
|
||
// Custom error, so we don't have to rely on |
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.
We can remove this in preference of using the existing upstream resource.NotFoundError
|
||
func testAccAWSRedshiftSnapshotCopyGrant_Basic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_redshift_snapshot_copy_grant" "%s" { |
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.
Minor nitpick: the resource name should be static, e.g. basic
or test
CheckDestroy: testAccCheckAWSRedshiftSnapshotCopyGrantDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSRedshiftSnapshotCopyGrant_Basic("basic"), |
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.
The random name being passed in should be randomized to prevent issues with concurrent testing or a failed run, e.g.
rName := acctest.RandomWithPrefix("tf-acc-test")
// ...
testAccAWSRedshiftSnapshotCopyGrant_Basic(rName)
// ...
resource.TestCheckResourceAttr("aws_redshift_snapshot_copy_grant.basic", "snapshot_copy_grant_name", rName),
snapshot_copy_grant_name = "my-grant" | ||
} | ||
|
||
resource "aws_redshift_parameter_group" "test" { |
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.
We prefer to only show very relevant example configuration in our documentation in case other resources/attributes/implementations change, e.g.
resource "aws_redshift_snapshot_copy_grant" "example" {
snapshot_copy_grant_name = "example"
}
resource "aws_redshift_cluster" "example" {
# ... other configuration ...
snapshot_copy {
destination_region = "us-east-2"
grant_name = "${aws_redshift_snapshot_copy_grant.example.snapshot_copy_grant_name}"
}
}
Hi @bflad, Thanks for the feedback. I'll work on making these changes. Do you have any pointers about how to implement tags? |
I'd check out how |
Thanks! |
Hey @bflad this is ready for another round of review. |
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.
Looks good, @f0rk! I'll fix the little typo on merge.
--- PASS: TestAccAWSRedshiftSnapshotCopyGrant_Basic (4.58s)
out, err = conn.CreateSnapshotCopyGrant(&input) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] An error occured creating new AWS Redshift SnapshotCopyGrant: %s", err) |
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.
Looks like we caught a minor typo here:
$ make lint
==> Checking source code against linters...
aws/resource_aws_redshift_snapshot_copy_grant.go:67:31:warning: "occured" is a misspelling of "occurred" (misspell)
make: *** [lint] Error 1
That said, we generally prefer to return this type of messaging to the operator directly, instead of just in the debug logging, e.g.
return fmt.Errorf("error creating Redshift Snapshot Copy Grant (%s): %s", grantName, err)
This has been released in version 1.40.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Changes proposed in this pull request:
Output from acceptance testing:
The one open item on this that I am not sure how to tackle is tags. Any pointers there would be appreciated.