-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Passing list variables from TerraTest go files to Terraform #200
Comments
Just pass a list :) myList := []string{"foo", "bar", "baz"}
terraformOptions := &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../my-module",
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"my_list": myList,
},
}
What error do you get? Can you share your log output? |
Hi, I think it might be something to do with the body of the http GET as I am trying to test if my sonarqube is up and working and I do get a Response status: 200 along with all the HTML of sonar, but the test stills fails.
The example on the Terratest github with the basic HTML webpage saying "Hello, World!" works grand as it has a basic with some text! But for other applications where the HTML has alot going on I cannot seem to get the test to Pass. |
If you need custom validation, use HttpGetWithRetryWithCustomValidation instead. It lets you pass in a function to check the status code and body of the response any way you want (e.g., via |
@brikis98 Thank you, got both working now!!! Many thanks, Michael |
Great to hear! |
Sorry for opening up this conversation, but just for completeness it seems this issue is correlated with: Just recently I ran into this issue trying to write a test using a list as input. Maybe the connection is helpful for others. |
i tried passing a list to my variable like this :
while this been implemented, i still face issue as when it passes the subnet_ids as the variable it is treated as a string of single unit, for ex. "[subnet-XXXX subnet-YYYY]" is a string and not a list while the output from the module was a list and not a string. is there any way out to take the subnet value from the output as a list and not as string . |
Most likely, Terratest is passing the value as a list, but you need to set the |
I'm am having similar issue as @rishabhanand26 , The destination terraform module variable is configured as list(string): variable "private_subnets" {
description = "Cluster private subnets"
type = list(string)
} I pass the variable in a test stage as follows: "private_subnets": terraform.Output(t, awsNetworkOpts, "private_subnets") Getting an error:
The actual output from the source module looks as follows: The var that is passed to the destination module is -var private_subnets=[subnet-xxx subnet-xxx] For me the workaround was to use the https://github.com/Jeffail/gabs library. awsNetworkOpts := test_structure.LoadTerraformOptions(t, awsNetworkModulePath)
jsonParsed, err := gabs.ParseJSON([]byte(terraform.OutputJson(t, awsNetworkOpts, "")))
if err != nil {
t.Error(err)
}
obj, err := jsonParsed.JSONPointer("/private_subnets/value")
if err != nil {
t.Error(err)
}
var privateSubnets []string
for _, child := range obj.Children() {
privateSubnets = append(privateSubnets, child.Data().(string))
}
vars := map[string]interface{}{"private_subnets": privateSubnets} To view the output in json format just fmt.Println(jsonParsed). Hope it helps someone. |
That's your problem right there: |
Thank you very much! |
I have currently been using TerraTest for testing my Terraform IAC.
Works fine, but in none of the examples I can see how we would pass a list of values, lets say subnet CIDR blocks or a list of Security group ID's from our Go Terratest file to Terraform, as those values expect a list variable type.
Could you also share any information around the httpHelper script? I have been using your examples to base my test files on, but cannot seem get my script working on my own applications such as Jenkins running on port 8080 which was launched using a gold AMI in aws.
I can navigate to the Application on my browser, and curl information from it from my machine where I am running the tests, but still does not seem to work.
There is also logs when I run the test showing the HTML layout, but I think it might be something to do with the InstanceText in which I am passing to the test which makes it fail.
http_helper.HttpGetWithRetry(t, instanceURL, 200, instanceText, maxRetries, timeBetweenRetries)
Thanks,
Michael
The text was updated successfully, but these errors were encountered: