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

using random.UniqueId() for resource naming prevents destroy #1444

Closed
2 tasks
cgradwohl-playq opened this issue Sep 16, 2024 · 2 comments
Closed
2 tasks

using random.UniqueId() for resource naming prevents destroy #1444

cgradwohl-playq opened this issue Sep 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cgradwohl-playq
Copy link

Describe the bug
A common pattern I see when writing tests with Terratest, is to use random.UniqueId() for resource naming so that naming collisions will not conflict during parallel testing.

However, during the destroy phase, if the call to AWS api's is retried then a new random.UniqueId() is generated and passed to the destroy call to AWS. This of course will not exist and ultimately the destroy with fail.

This mean that for resources with random.UniqueId() identifiers, the destroy will either work the first time or not at all.

To Reproduce
Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.

t.Parallel()

workingDir := "../examples/complete_mysql"
instanceId := fmt.Sprintf("complete-mysql-%s", uniqueId)

terraformOpts := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: workingDir,
Vars: map[string]interface{}{
	"env_name":        env_name,
	"identifier":      instanceId,
	"private_zone_id": privateZoneId,
	"public_zone_id":  publicZoneId,
	"vpc_id":          vpcId,
},
})

defer terraform.Destroy(t, terraformOpts)

Expected behavior
The destroy should work, even if the underlying call to AWS fails or retries.

Nice to have

  • Terminal output
  • Screenshots

Versions

  • Terratest version: 1.5.7
  • Environment details (Ubuntu 20.04, Windows 10, etc.): ubuntu-latest

Additional context
Add any other context about the problem here.

@cgradwohl-playq cgradwohl-playq added the bug Something isn't working label Sep 16, 2024
@james03160927 james03160927 self-assigned this Oct 15, 2024
@james03160927
Copy link
Contributor

Hi @cgradwohl-playq, based on the code you shared, I don't see where the random ID is generated. During terraform destroy, it should use the ID stored in the state from when the resources were applied, so it shouldn't behave as you're describing. Could you provide more details on how to reproduce the issue you're experiencing?

@james03160927
Copy link
Contributor

Closing this issue if you no longer experience this issue. Feel free to reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants