Skip to content
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

Merged
merged 5 commits into from
Oct 9, 2018

Conversation

f0rk
Copy link
Contributor

@f0rk f0rk commented Jul 10, 2018

Changes proposed in this pull request:

  • Add new Redshift Snapshot Copy Grant resource.

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAWSRedshiftSnapshotCopyGrant_Basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -run=TestAWSRedshiftSnapshotCopyGrant_Basic -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAWSRedshiftSnapshotCopyGrant_Basic
--- PASS: TestAWSRedshiftSnapshotCopyGrant_Basic (20.90s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       20.913s

The one open item on this that I am not sure how to tackle is tags. Any pointers there would be appreciated.

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jul 10, 2018
@bflad bflad added new-resource Introduces a new resource. service/redshift Issues and PRs that pertain to the redshift service. labels Jul 10, 2018
Copy link
Contributor

@bflad bflad left a 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 {
Copy link
Contributor

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)
Copy link
Contributor

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 != "" {
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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" {
Copy link
Contributor

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"),
Copy link
Contributor

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" {
Copy link
Contributor

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}"
  }
}

@f0rk
Copy link
Contributor Author

f0rk commented Jul 17, 2018

Hi @bflad,

Thanks for the feedback. I'll work on making these changes. Do you have any pointers about how to implement tags?

@bflad
Copy link
Contributor

bflad commented Jul 17, 2018

I'd check out how resource_aws_redshift_subnet_group.go is doing it -- briefly looking at the SnapshotCopyGrant SDK operations, it seems the implementation here might be similar. 😄

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 17, 2018
@f0rk
Copy link
Contributor Author

f0rk commented Jul 17, 2018

Thanks!

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed size/L Managed by automation to categorize the size of a PR. labels Oct 8, 2018
@f0rk
Copy link
Contributor Author

f0rk commented Oct 8, 2018

Hey @bflad this is ready for another round of review.

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 9, 2018
Copy link
Contributor

@bflad bflad left a 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)
Copy link
Contributor

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)

@bflad bflad added this to the v1.40.0 milestone Oct 9, 2018
@bflad bflad merged commit 046cc1b into hashicorp:master Oct 9, 2018
bflad added a commit that referenced this pull request Oct 9, 2018
@bflad
Copy link
Contributor

bflad commented Oct 10, 2018

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.

@ghost
Copy link

ghost commented Apr 2, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. service/redshift Issues and PRs that pertain to the redshift service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants