Skip to main content
Knowledge Base

Need help in reading input for terratest from CLI at run time using prompt way or command line input

Answer

Could you please let me know if it is possible to pass **variable values to golang terratest from CLI** instead terraformOptions Vars:. For example, from below link , i am planning to read line #30 value expectedName from Command line while running go mod or go run etc as value of expectedName is sensitive in my test case hence i am looking for a way to pass the same from Command line , Please advise suitable solution https://github.com/gruntwork-io/terratest/blob/d73ef40c970e1e13d4ce00f770a549ad742d2893/test/terraform_aws_example_test.go#L30 At least let me know , Is it possible to read input from end user through prompt , I tried below code but did not work , It is not pausing and prompting its running without stop hence i am NOT able to pass dynamic input to terratest ` fmt.Print("Enter your name & age: ") fmt.Scanf("%s %d", &name, &age) fmt.Printf("%s is %d years old\n", name, age)`

This is unfortunately by design. Terratest is meant to be a non-interactive testing framework, similar to `npm test`, `pytest`, and others. Under the hood, terratest uses the unit testing framework of golang (in `go test`), and thus stdin is not accessible. It would take considerable effort for us to support this, and thus we are unlikely to support interactive prompts anytime soon. The canonical way to handle what you are describing with secrets is to use environment variables, or a secrets management solution (like AWS Secrets Manager) and pull the data from those sources instead of feeding them in in an interactive manner.