1

https://learn.microsoft.com/en-us/azure/developer/terraform/test-modules-using-terratest#unit-test

Following along with the above link (code shown below). I am able to get a Terraform Plan with the out being specified as a certain name, but what if I had a loop and the tfplan was actually iterating and was for example, terraform.tfplan1, 2, 3, etc.

`tfPlanOutput := "terraform.tfplan"
terraform.Init(t, tfOptions)
terraform.RunTerraformCommand(t, tfOptions, terraform.FormatArgs(tfOptions, "plan", "-out="+tfPlanOutput)...)`

Is there a known way to then have the apply directly reference the specified terraform.tfplan(###) I want? I see the Terraform.apply, but i'm having a hard time specific pointing to 1 "-out=" file. Maybe I don't want to apply each tfplan, but for a given moment, just 1 of them. How do I Isolate the choice?

aseb
  • 274
  • 2
  • 11
  • 1
    This is not really how you do acceptance testing with Terratest. You do not need plan preservation in acceptance testing, because everything is ephemeral and on-demand anyway, and there is only one user and one state. You only need the `init` and `apply` related functions here, or even `InitAndApply` from `terratest/modules/terraform`. – Matthew Schuchard Jul 20 '22 at 21:29
  • Thanks Matt, I am realizing that 'terraform.InitAndApplyAndIdempotent' is probably wht I want to use here. Thanks for the additional comments. – aseb Jul 20 '22 at 21:32
  • 1
    Yes I would agree that `InitAndApplyAndIdempotent` function from the `terraform` module from `terratest` will probably be very helpful for you. It should hopefully get you straight to the finish line even. – Matthew Schuchard Jul 20 '22 at 21:35
  • Yes! My biggest problem was I was trying to run an array of tests in parallel, but like you mentioned, i only had 1 state, so that wasnt jiving well. Thought maybe I could separate it all out, but it became over complex. Ill just let the array parse through 1 at a time all the way through. Thanks again! – aseb Jul 20 '22 at 21:39

0 Answers0