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

aws_workspaces_workspace replace (destroy/create) race condition #14517

Closed
fweep opened this issue Aug 7, 2020 · 5 comments · Fixed by #15705
Closed

aws_workspaces_workspace replace (destroy/create) race condition #14517

fweep opened this issue Aug 7, 2020 · 5 comments · Fixed by #15705
Labels
bug Addresses a defect in current functionality. service/workspaces Issues and PRs that pertain to the workspaces service.
Milestone

Comments

@fweep
Copy link

fweep commented Aug 7, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue 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 issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.28

provider "aws" {
  version = "2.70.0"
}

Affected Resource(s)

  • aws_workspaces_workspace

Terraform Configuration Files

resource "aws_workspaces_workspace" "client_jstewart" {
  directory_id = aws_workspaces_directory.client.id
  bundle_id = data.aws_workspaces_bundle.client.id
  user_name = "jstewart"

  root_volume_encryption_enabled = true
  user_volume_encryption_enabled = true
  volume_encryption_key = aws_kms_alias.client_workspaces.arn

  workspace_properties {
    compute_type_name = "STANDARD"
    user_volume_size_gib = var.client_workspaces_user_volume_size
    root_volume_size_gib = var.client_workspaces_root_volume_size
    running_mode = "AUTO_STOP"
    running_mode_auto_stop_timeout_in_minutes = var.client_workspaces_auto_stop_timeout
  }

  tags = {
    Department = "wherescape-${var.environment_abbrv}-client"
  }
}

Debug Output

Panic Output

Expected Behavior

Resource should be destroyed and re-created.

Actual Behavior

Resource is destroyed, but re-create fails due to namespace still being in use.

module.wherescape.aws_workspaces_workspace.client_jstewart: Destroying... [id=ws-jc9p9tcss]
...
module.wherescape.aws_workspaces_workspace.client_jstewart: Still destroying... [id=ws-jc9p9tcss, 1m20s elapsed]
module.wherescape.aws_workspaces_workspace.client_jstewart: Destruction complete after 1m26s
module.wherescape.aws_workspaces_workspace.client_jstewart: Creating...
Error: workspace creation failed: A WorkSpace already exists for the specified user.
  on modules/wherescape/client_workspace_users.tf line 1, in resource "aws_workspaces_workspace" "client_jstewart":
   1: resource "aws_workspaces_workspace" "client_jstewart" {

If I immediately run the apply again, it succeeds. It seems that AWS or Terraform is not waiting for true completion of the destroy before it attempts to create.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000
@ghost ghost added the service/workspaces Issues and PRs that pertain to the workspaces service. label Aug 7, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Aug 7, 2020
@Tensho
Copy link
Contributor

Tensho commented Oct 5, 2020

@fweep Thank you for submitting this issue 🙇 Let me consult AWS Support regarding TerminateWorkspaces API eventual consistency first. Plan B will be adding retries for the failed workspace creation/termination attempts.

@Tensho
Copy link
Contributor

Tensho commented Oct 6, 2020

This operation is asynchronous and returns before the WorkSpaces have been completely terminated. After a WorkSpace is terminated, the TERMINATED state is returned only briefly before the WorkSpace directory metadata is cleaned up, so this state is rarely returned. To confirm that a WorkSpace is terminated, check for the WorkSpace ID by using DescribeWorkSpaces. If the WorkSpace ID isn't returned, then the WorkSpace has been successfully terminated.

https://docs.aws.amazon.com/workspaces/latest/api/API_TerminateWorkspaces.html

I guess the workspace resource state waiter should be adjusted, but I still want to clarify this with AWS. Stay tuned.

@Tensho
Copy link
Contributor

Tensho commented Oct 8, 2020

I've confirmed we have to switch to disappearing workspace ID instead of TERMINATED status with AWS Support. I'm going to fix current waiting behaviour the next week.

@breathingdust breathingdust added this to the v3.12.0 milestone Oct 22, 2020
@breathingdust breathingdust added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 22, 2020
@ghost
Copy link

ghost commented Oct 22, 2020

This has been released in version 3.12.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 for triage. Thanks!

@ghost
Copy link

ghost commented Nov 21, 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 as resolved and limited conversation to collaborators Nov 21, 2020
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/workspaces Issues and PRs that pertain to the workspaces service.
Projects
None yet
3 participants