-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Terraform test performs progressively slower as more test runs execute #34009
Comments
Thanks for this report! |
Hi @GSDragoon, I can replicate this and I think I've pinpointed the issue. I just wanted to check whether you've seen this with any tests that don't use the The issue is arising from this line:
Basically, the Terraform internal graph is modifying the config by merging the two locations of config together. It then does this on every iteration, and the testing framework is sharing the same config object between all the runs. Every run is therefore basically doubling the size of the If you change the definition of the resource to: resource "tfcoremock_simple_resource" "one" {
provisioner "remote-exec" {
inline = ["echo test"]
connection {
host = "host"
}
}
} We don't see this behaviour as that particular line of code is not being triggered. This is definitely a bug, and we'll try and fix as soon as possible - I just need to look into the best way to do this. I'm not sure if we want to modify the testing framework so it reloads the config for every run block, or maybe we can change Terraform itself so it's not modifying the configuration during the graph execution. Thanks for finding this and reporting it! |
Hi @liamcervante Thanks for looking into this. I have only been able to recreate the issue using a I was having a hard time working around the issue using resource "terraform_data" "slow" {
provisioner "remote-exec" {
inline = ["echo test"]
}
connection {
host = "host"
}
}
resource "terraform_data" "even_slower" {
provisioner "remote-exec" {
inline = ["echo test"]
}
provisioner "remote-exec" {
inline = ["echo test2"]
}
connection {
host = "host"
}
}
resource "terraform_data" "fast" {
provisioner "remote-exec" {
inline = ["echo test"]
connection {
host = "host"
}
}
}
resource "terraform_data" "still_fast" {
provisioner "remote-exec" {
inline = ["echo test"]
connection {
host = "host"
}
}
provisioner "remote-exec" {
inline = ["echo test2"]
connection {
host = "host"
}
}
} |
Hi @GSDragoon, yes - you're exactly right! Sorry, I missed that I'd changed the resource type in my response. Yeah, if there is no root |
Just a quick update here, this will be fixed 1.6.2 rather than 1.6.1. Apologies for the delay! |
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. |
Terraform Version
Terraform Configuration Files
This is the most simple example of recreating the issue that I could come up with. Remote-exe provision is what I found to be the biggest offender and is really easy to recreate with. I have also recreated this issue with more tests and not using a provisioner, but that terraform is a lot more complex and not something I can easily share.
main.tf
./tests/main.tftest.hcl
Debug Output
Debug output from 23 test runs from the example configuration shared here: https://gist.github.com/GSDragoon/3b8b661a377623d269a55233afdb8242
At the end of the file, when things are the slowest, these sections seem to be noteworthy as the time jumps.
Meanwhile, the first time this runs (doing the same exact test), it completes instantly.
Expected Behavior
I would expect each test run to execute within a similar time span.
Actual Behavior
The more test runs that execute, the slower it gets. To the point of taking so long it's unusable. The terraform process memory will also keep increasing. I had it hit 9GB before killing it once. Doing some very rough stopwatching (once things start slowing down, ~15 or so), each test run takes almost twice as long as the previous (12 sec, 27 sec, 56 sec, 1 min 52 sec, 3 min 45 sec).
Steps to Reproduce
Using the provided terraform configuration and terraform 1.6.0:
terraform init
terraform test
Additional Context
Love the new testing features in 1.6. ❤️ The eventual goal is to run this in a CI process and to have a much larger test suite, but right now I've only just begun creating some tests using the new features in 1.6.0 and have been running things locally. It's been recreated on 3 different machines.
References
No response
The text was updated successfully, but these errors were encountered: