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

Fix expired statements during redshift-data state update #26343

Merged
merged 6 commits into from
Apr 27, 2023

Conversation

rockpunk
Copy link
Contributor

@rockpunk rockpunk commented Aug 17, 2022

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #25882

After a redshift data statement is created, aws redshift-data describe-statement will only return a result for a short period of time when refreshing terraform state. After a while, it doesn't actually find the old statement, so terraform plan will fail trying to refresh the state:

aws redshift-data describe-statement --id 346a11c9-9e89-476b-a68a-995a1d3f3a39

An error occurred (ValidationException) when calling the DescribeStatement operation: Could not retrieve the query result as it has expired after 1660423725.

This PR attempts to fix the issue by catching ValidationExceptions related to expired statements, and returning a dummy response that allows terraform state refresh to continue.

One impact of this change is that all expired statements will NOW BE REPLACED (the statements will be re-run) on next plan application.

If you don't want the statements to be re-run, use the ignore_changes lifecycle:

locals { 
  schemas = [ "schema1", "schema2", "schema3" ]
}

resource "aws_redshiftdata_statement" "create_schema" {
  for_each           = local.schemas
  cluster_identifier = "your-instance"
  database           = "yourdb"
  db_user            = "you"
  sql                = "create schema ${each.key}"

  lifecycle {
    ignore_changes = all
  }
}

Output from acceptance testing:

❯ make testacc TESTS=TestAccRedshiftDataStatement_basic PKG=redshiftdata
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/redshiftdata/... -v -count 1 -parallel 20 -run='TestAccRedshiftDataStatement_basic'  -timeout 180m
=== RUN   TestAccRedshiftDataStatement_basic
=== PAUSE TestAccRedshiftDataStatement_basic
=== CONT  TestAccRedshiftDataStatement_basic

--- PASS: TestAccRedshiftDataStatement_basic (332.30s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/redshiftdata	335.469s

…is expired. when this happens, assume the statement exists
@github-actions github-actions bot added service/redshiftdata Issues and PRs that pertain to the redshiftdata service. needs-triage Waiting for first response or review from a maintainer. size/XS Managed by automation to categorize the size of a PR. labels Aug 17, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome @rockpunk 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Aug 17, 2022
@wolfm89
Copy link

wolfm89 commented Mar 27, 2023

Is there a reason why this doesn't get merged?

@rockpunk
Copy link
Contributor Author

Is there a reason why this doesn't get merged?

Probably a lack of community votes. I have raised this to our internal aws reps and will ping them again about it. In the meantime, future readers should continue to add a 👍 to the pr description above if they want this merged.

@wolfm89
Copy link

wolfm89 commented Apr 6, 2023

Any updates so far? The aws_redshiftdata_statement resource is not usable at all in the current state.

@ZMarouani
Copy link

ZMarouani commented Apr 10, 2023

please merge this , the aws_redshiftdata_statement resource is literally unusable !! or at least mention this in terraform documentation

update : As a workaround , you can use terraform rm 'redshiftdata_statement resource' to remove all instances of the expired resource from your terraform state file , then you can run terraform plan apply again without errors ( and add lifecycle to your redshiftdata resource to avoid having the error again )

@Lincon-Freitas
Copy link

Any news on this? It is a big issue!

@github-actions github-actions bot added size/L Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Apr 27, 2023
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccRedshiftDataStatement_' PKG=redshiftdata ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/redshiftdata/... -v -count 1 -parallel 2  -run=TestAccRedshiftDataStatement_ -timeout 180m
=== RUN   TestAccRedshiftDataStatement_basic
=== PAUSE TestAccRedshiftDataStatement_basic
=== RUN   TestAccRedshiftDataStatement_workgroup
=== PAUSE TestAccRedshiftDataStatement_workgroup
=== CONT  TestAccRedshiftDataStatement_basic
=== CONT  TestAccRedshiftDataStatement_workgroup
--- PASS: TestAccRedshiftDataStatement_basic (505.04s)
--- PASS: TestAccRedshiftDataStatement_workgroup (621.16s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/redshiftdata	626.763s

@ewbankkit
Copy link
Contributor

@rockpunk Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit dc1d4bc into hashicorp:main Apr 27, 2023
@github-actions github-actions bot added this to the v4.65.0 milestone Apr 27, 2023
@github-actions
Copy link

This functionality has been released in v4.65.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/redshiftdata Issues and PRs that pertain to the redshiftdata service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refreshing aws_redshiftdata_statement after query result expires fails
6 participants