terratest
terratest copied to clipboard
Can terratests be run against existing AWS resources created with terraform?
Are there any examples to accomplish testing with terratest the AWS infrastructure that was created before and now is being updated? How can terratest know about the details of the existing infrastructure?
I don't think we have examples of it, but it would be more or less identical to the examples out there, such as the hello world example, except perhaps instead of calling terraform.InitAndApply, you'd only call terraform.Init, as the infra is already deployed.
I'm new to terratest, but it seems to pick up the existing state file. And then go ahead and delete everything in it, and recreate, and then delete again.
That's what happened in my test environment. I ran apply, and then tests with all resource names using vars and parametrised with random().
Expectation: create a new test env, test, tear it down. Do not touch existing provisioned infra in use. Reality: infra in use got deleted by Terratest.
So I guess Terratest really is for modules and not for running against already deployed infra. There are other tools if you want to test against deployed infra like awspec.
On a side note, I have a Terraform state that deploys resources in multiple accounts. The only way using CLI profiles I found was to set AWS_PROFILE=account2 env var before the test steps involving resources created in account2.
I'm new to terratest, but it seems to pick up the existing state file. And then go ahead and delete everything in it, and recreate, and then delete again.
Terratest runs the Terraform code you tell it to run! So if you pointed it at a Terraform module that had a backend configured with a state file, then it'll run against that state. If you want to override that, see the backend config options in terraform.Options.
Yeah, you would need to create and store multiple tfstate files if you want to test entire infra without affecting existing stack. You would also need to namespace the actual AWS resources to avoid collision.