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: Wait until RAM resource share available after accepting the invitation #34753

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

kota65535
Copy link
Contributor

@kota65535 kota65535 commented Dec 6, 2023

Description

When a RAM resource share invitation from another account is accepted, there will be a slight delay until the resource share can be found. This PR adds wait for the delay.

Relations

Closes #33701

Output from Acceptance Testing

With AWS_PROFILE env variable:

% make testacc TESTS=TestAccRAMResourceShareAccepter PKG=ram
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ram/... -v -count 1 -parallel 20 -run='TestAccRAMResourceShareAccepter'  -timeout 360m
=== RUN   TestAccRAMResourceShareAccepter_basic
=== PAUSE TestAccRAMResourceShareAccepter_basic
=== RUN   TestAccRAMResourceShareAccepter_disappears
=== PAUSE TestAccRAMResourceShareAccepter_disappears
=== RUN   TestAccRAMResourceShareAccepter_resourceAssociation
=== PAUSE TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_basic
=== CONT  TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_disappears
=== NAME  TestAccRAMResourceShareAccepter_basic
    acctest.go:848: skipping test because at least one environment variable of [AWS_ALTERNATE_PROFILE AWS_ALTERNATE_ACCESS_KEY_ID] must be set. Usage: credentials for running acceptance testing in alternate AWS account.
=== NAME  TestAccRAMResourceShareAccepter_resourceAssociation
    acctest.go:848: skipping test because at least one environment variable of [AWS_ALTERNATE_PROFILE AWS_ALTERNATE_ACCESS_KEY_ID] must be set. Usage: credentials for running acceptance testing in alternate AWS account.
--- SKIP: TestAccRAMResourceShareAccepter_basic (0.47s)
--- SKIP: TestAccRAMResourceShareAccepter_resourceAssociation (0.47s)
=== NAME  TestAccRAMResourceShareAccepter_disappears
    acctest.go:848: skipping test because at least one environment variable of [AWS_ALTERNATE_PROFILE AWS_ALTERNATE_ACCESS_KEY_ID] must be set. Usage: credentials for running acceptance testing in alternate AWS account.
--- SKIP: TestAccRAMResourceShareAccepter_disappears (0.47s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/ram        6.114s

As the warning says, I've also tried setting AWS_ALTERNATE_PROFILE env variable on the latest main branch, but it seems very flaky. Note that the error message of the first failed test is the same as the original issue.

make testacc TESTS=TestAccRAMResourceShareAccepter PKG=ram
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ram/... -v -count 1 -parallel 20 -run='TestAccRAMResourceShareAccepter'  -timeout 360m
=== RUN   TestAccRAMResourceShareAccepter_basic
=== PAUSE TestAccRAMResourceShareAccepter_basic
=== RUN   TestAccRAMResourceShareAccepter_disappears
=== PAUSE TestAccRAMResourceShareAccepter_disappears
=== RUN   TestAccRAMResourceShareAccepter_resourceAssociation
=== PAUSE TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_basic
=== CONT  TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_disappears
    resource_share_accepter_test.go:78: Step 1/1 error: Error running apply: exit status 1
        
        Error: reading RAM Resource Share (arn:aws:ram:us-west-2:433616233360:resource-share/51bcfb61-e944-42da-b306-7fdac02c6d66): couldn't find resource
        
          with aws_ram_resource_share_accepter.test,
          on terraform_plugin_test.tf line 21, in resource "aws_ram_resource_share_accepter" "test":
          21: resource "aws_ram_resource_share_accepter" "test" {
        
--- FAIL: TestAccRAMResourceShareAccepter_disappears (32.52s)
=== NAME  TestAccRAMResourceShareAccepter_resourceAssociation
    resource_share_accepter_test.go:105: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        +       "resources.#": "1",
        +       "resources.0": "arn:aws:codebuild:us-west-2:433616233360:project/tf-acc-test-8943434103236148295",
          }
--- PASS: TestAccRAMResourceShareAccepter_basic (65.69s)
--- FAIL: TestAccRAMResourceShareAccepter_resourceAssociation (76.61s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/ram        82.620s
FAIL
make: *** [testacc] Error 1

After adding my change, the first failed test case become to PASS.

 make testacc TESTS=TestAccRAMResourceShareAccepter PKG=ram
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ram/... -v -count 1 -parallel 20 -run='TestAccRAMResourceShareAccepter'  -timeout 360m
=== RUN   TestAccRAMResourceShareAccepter_basic
=== PAUSE TestAccRAMResourceShareAccepter_basic
=== RUN   TestAccRAMResourceShareAccepter_disappears
=== PAUSE TestAccRAMResourceShareAccepter_disappears
=== RUN   TestAccRAMResourceShareAccepter_resourceAssociation
=== PAUSE TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_basic
=== CONT  TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_disappears
=== NAME  TestAccRAMResourceShareAccepter_resourceAssociation
    resource_share_accepter_test.go:105: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        +       "resources.#": "1",
        +       "resources.0": "arn:aws:codebuild:us-west-2:433616233360:project/tf-acc-test-7733603511406526370",
          }
--- PASS: TestAccRAMResourceShareAccepter_basic (64.24s)
--- FAIL: TestAccRAMResourceShareAccepter_resourceAssociation (73.23s)
=== NAME  TestAccRAMResourceShareAccepter_disappears
    testing_new.go:91: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: leaving RAM resource share: UnknownResourceException: ResourceShare arn:aws:ram:us-west-2:433616233360:resource-share/ed27dfdb-6e5b-408a-be0d-7b13f36123ce could not be found.
        
--- FAIL: TestAccRAMResourceShareAccepter_disappears (171.52s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/ram        176.353s
FAIL
make: *** [testacc] Error 1

Copy link

github-actions bot commented Dec 6, 2023

Community Note

Voting for Prioritization

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

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added size/XS Managed by automation to categorize the size of a PR. service/ram Issues and PRs that pertain to the ram service. labels Dec 6, 2023
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 6, 2023
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 @kota65535 👋

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 CONTRIBUTOR 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 Dec 6, 2023
@Viktork25
Copy link

@kota65535 @justinretzolk is there a plan to merge the fix please?We are waiting for that fix as we are not able to progress the update on the aws providers

@doellerich-splunk
Copy link

I can verify that this fixes the bug in #33701.

Sample output from v5.35.0 (latest at the time of writing):

$ terraform version
Terraform v1.5.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v5.35.0

$ terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_ram_resource_share_accepter.accepter will be created
  + resource "aws_ram_resource_share_accepter" "accepter" {
      + id                  = (known after apply)
      + invitation_arn      = (known after apply)
      + receiver_account_id = (known after apply)
      + resources           = (known after apply)
      + sender_account_id   = (known after apply)
      + share_arn           = "arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54"
      + share_id            = (known after apply)
      + share_name          = (known after apply)
      + status              = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_ram_resource_share_accepter.accepter: Creating...
╷
│ Error: reading RAM Resource Share (arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54): couldn't find resource
│
│   with aws_ram_resource_share_accepter.accepter,
│   on main.tf line 15, in resource "aws_ram_resource_share_accepter" "accepter":
│   15: resource "aws_ram_resource_share_accepter" "accepter" {
│

$ terraform apply
aws_ram_resource_share_accepter.accepter: Refreshing state... [id=arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_ram_resource_share_accepter.accepter is tainted, so must be replaced
-/+ resource "aws_ram_resource_share_accepter" "accepter" {
      ~ id                  = "arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54" -> (known after apply)
      ~ invitation_arn      = "arn:aws:ram:us-east-1:REDACTED:resource-share-invitation/8777159a-REDACTED-b36d-36d46cc0584d" -> (known after apply)
      ~ receiver_account_id = "REDACTED" -> (known after apply)
      ~ resources           = [
          - "arn:aws:glue:us-east-1:REDACTED:catalog",
        ] -> (known after apply)
      ~ sender_account_id   = "REDACTED" -> (known after apply)
      ~ share_id            = "rs-9271dcec-REDACTED-8c0d-b781c8900c54" -> (known after apply)
      ~ share_name          = "test-resource-share" -> (known after apply)
      ~ status              = "ACTIVE" -> (known after apply)
        # (1 unchanged attribute hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_ram_resource_share_accepter.accepter: Destroying... [id=arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54]
aws_ram_resource_share_accepter.accepter: Destruction complete after 1s
aws_ram_resource_share_accepter.accepter: Creating...
aws_ram_resource_share_accepter.accepter: Still creating... [10s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [20s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [30s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [40s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [50s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m0s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m10s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m20s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m30s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m40s elapsed]
aws_ram_resource_share_accepter.accepter: Still creating... [1m50s elapsed]
╷
│ Error: No RAM Resource Share (arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54) invitation found
│
│ NOTE: If both AWS accounts are in the same AWS Organization and RAM Sharing with AWS Organizations is enabled, this resource is not necessary
│
│   with aws_ram_resource_share_accepter.accepter,
│   on main.tf line 15, in resource "aws_ram_resource_share_accepter" "accepter":
│   15: resource "aws_ram_resource_share_accepter" "accepter" {
│

Sample output from patched v5.35.0:

$ terraform apply
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp/aws in /Users/doellerich/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_ram_resource_share_accepter.accepter will be created
  + resource "aws_ram_resource_share_accepter" "accepter" {
      + id                  = (known after apply)
      + invitation_arn      = (known after apply)
      + receiver_account_id = (known after apply)
      + resources           = (known after apply)
      + sender_account_id   = (known after apply)
      + share_arn           = "arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54"
      + share_id            = (known after apply)
      + share_name          = (known after apply)
      + status              = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_ram_resource_share_accepter.accepter: Creating...
aws_ram_resource_share_accepter.accepter: Creation complete after 5s [id=arn:aws:ram:us-east-1:REDACTED:resource-share/9271dcec-REDACTED-8c0d-b781c8900c54]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

@tlkamp
Copy link
Contributor

tlkamp commented Feb 9, 2024

Hoping the maintainers give this issue some love! This is a very simple PR and fixes a critical bug in the current provider release.

Copy link
Collaborator

@AdamTylerLynch AdamTylerLynch left a comment

Choose a reason for hiding this comment

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

Approved for merge. LGTM 🚀

@jar-b jar-b self-assigned this Feb 12, 2024
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Feb 12, 2024
Copy link
Member

@jar-b jar-b 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 TESTS=TestAccRAMResourceShareAccepter PKG=ram
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ram/... -v -count 1 -parallel 20 -run='TestAccRAMResourceShareAccepter'  -timeout 360m
=== RUN   TestAccRAMResourceShareAccepter_basic
=== PAUSE TestAccRAMResourceShareAccepter_basic
=== RUN   TestAccRAMResourceShareAccepter_disappears
=== PAUSE TestAccRAMResourceShareAccepter_disappears
=== RUN   TestAccRAMResourceShareAccepter_resourceAssociation
=== PAUSE TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_basic
=== CONT  TestAccRAMResourceShareAccepter_resourceAssociation
=== CONT  TestAccRAMResourceShareAccepter_disappears
--- PASS: TestAccRAMResourceShareAccepter_basic (28.61s)
=== NAME  TestAccRAMResourceShareAccepter_resourceAssociation
    resource_share_accepter_test.go:105: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.

          map[string]string{
        +       "resources.#": "1",
        +       "resources.0": "arn:aws:codebuild:us-west-2:927163995318:project/tf-acc-test-2871805097709289946",
          }
--- FAIL: TestAccRAMResourceShareAccepter_resourceAssociation (39.35s)
=== NAME  TestAccRAMResourceShareAccepter_disappears
    testing_new.go:91: Error running post-test destroy, there may be dangling resources: exit status 1

        Error: leaving RAM resource share: UnknownResourceException: ResourceShare arn:aws:ram:us-west-2:927163995318:resource-share/2d9dbe34-bba4-49e2-9a01-5aad391d414a could not be found.

--- FAIL: TestAccRAMResourceShareAccepter_disappears (142.49s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/ram        148.820s

@jar-b
Copy link
Member

jar-b commented Feb 13, 2024

Thanks for your contribution, @kota65535! 👏

@jar-b jar-b merged commit 9fc510b into hashicorp:main Feb 13, 2024
73 checks passed
@github-actions github-actions bot added this to the v5.37.0 milestone Feb 13, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Feb 15, 2024
Copy link

This functionality has been released in v5.37.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!

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 Mar 17, 2024
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/ram Issues and PRs that pertain to the ram service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
7 participants