terratest | Go library that makes it easier to write automated tests | Infrastructure Automation library
kandi X-RAY | terratest Summary
kandi X-RAY | terratest Summary
Terratest is a Go library that makes it easier to write automated tests for your infrastructure code. It provides a variety of helper functions and patterns for common infrastructure testing tasks, including:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of terratest
terratest Key Features
terratest Examples and Code Snippets
Community Discussions
Trending Discussions on terratest
QUESTION
I use the following lines to run my terraform plan & apply in example/ folder:
...ANSWER
Answered 2022-Mar-03 at 16:23To get rid of the mysterious "The argument "region" is required, but was not set." error. I run the test as follows, the region error is gone:
QUESTION
I have multiple aws_glue_catalog_table
resources and I want to create a single output
that loops over all resources to show the S3 bucket location of each one. The purpose of this is to test if I am using the correct location
(because it is a concatenation of variables) for each resource in Terratest. I cannot use aws_glue_catalog_table.*
or aws_glue_catalog_table.[]
because Terraform does not allow to reference a resource without specifying its name.
So I created a variable "table_names"
with r1
, r2
, rx
. Then, I can loop over the names. I want to create the string aws_glue_catalog_table.r1.storage_descriptor[0].location
dynamically, so I can check if the location
is correct.
ANSWER
Answered 2021-Nov-12 at 17:30It seems like you have an unusual mix of static and dynamic here: you've statically defined a fixed number of aws_glue_catalog_table
resources but you want to use them dynamically based on the value of an input variable.
Terraform doesn't allow dynamic references to resources because its execution model requires building a dependency graph between all of the objects, and so it needs to know which exact resources are involved in a particular expression. However, you can in principle build your own single value that includes all of these objects and then dynamically choose from it:
QUESTION
I've a terratest where I get an output from terraform like so s := "[a b]"
. The terraform output's value = toset([resource.name])
, it's a set of strings.
Apparently fmt.Printf("%T", s)
returns string. I need to iterate to perform further validation.
I tried the below approach but errors!
...ANSWER
Answered 2021-Sep-25 at 06:58Actually your current implementation seems just fine.
You can't use JSON unmarshaling because JSON strings must be enclosed in double quotes "
.
Instead strings.Fields
does just that, it splits a string on one or more characters that match unicode.IsSpace
, which is \t
, \n
, \v
. \f
, \r
and
.
Moeover this works also if terraform sends an empty set as []
, as stated in the documentation:
returning [...] an empty slice if s contains only white space.
...which includes the case of s
being empty ""
altogether.
In case you need additional control over this, you can use strings.FieldsFunc
, which accepts a function of type func(rune) bool
so you can determine yourself what constitutes a "space". But since your input string comes from terraform, I guess it's going to be well-behaved enough.
There may be third-party packages that already implement this functionality, but unless your program already imports them, I think the native solution based on the standard lib is always preferrable.
unicode.IsSpace
actually includes also the higher runes 0x85
and 0xA0
, in which case strings.Fields
calls FieldsFunc(s, unicode.IsSpace)
QUESTION
Folks is there a possibility to create utils.go amongst *_test.go in the terratest test package to utilize a func that performs certain common validation routines across all _test.go.
I tried creating utils/utils.go
and within the *_test.go imported as "../tests/utils"
. This way able to run individual test like go test sample_test.go -v
or go test another_sample_test.go -v
and it yields.
But when I try go test -v
it complains cannot reference a local package.
Am just a beginner to terratest and go lang in general. Any leads is greatly appreciated. Thanks.
...ANSWER
Answered 2021-Sep-23 at 14:54Go packages must in general be imported by fully-qualified paths. The fully-qualified path for a package within your project depends on what module
path you declare in your go.mod
file.
If you're new to Go, How to Write Go Code is a good place to start.
QUESTION
I'm trying to save a file with VS Code.
UPDATE
I guess I should have asked how, independent of what the code is, you can force VS Code to Save a file when you hit Ctrl S rather than editing your file and then saving it?
====
VS Code is reporting a problem here:
...ANSWER
Answered 2021-May-06 at 12:0599.9% of the time you're fine with VS Code.
For that 0.1% of the time when you're having problems saving a file using VS Code and don't have time to waste a few hours on working out why, just use vim.
QUESTION
i'm facing a (it seams) recurent pbm in Azure Pipeline to run terratest.
While resources are well created the destroyed, when I call an azure.ResourceGroupExists function (or whatever else azure.xxx function) i have the following error :
...ANSWER
Answered 2021-Apr-16 at 11:30and thank-you for answering..
As I figure out earlier, it was a configuration mistake and, after having made some deep excavations on Go Terratest Azure module, I've found these lines that gives all the explanations :
- https://github.com/gruntwork-io/terratest/blob/master/modules/azure/authorizer.go#L11 leading to
- https://docs.microsoft.com/en-us/azure/developer/go/azure-sdk-authorization#use-environment-based-authentication
So I change my pipeline to this :
QUESTION
When I run pkg/mod/github.com/gruntwork-io/terratest/test/azure ...
go test -v -run TerraformAzureKeyvaultExample
I'm getting the following error:
package github.com/gruntwork-io/terratest/test/azure: build constraints exclude all Go files....
Has anyone else encountered this issue? How do I disable this so that I can actually run an Azure terratest?
-thai-
...ANSWER
Answered 2021-Apr-13 at 12:07accoding to [this issue][1] try using the -tags azure option like this:
QUESTION
I am working with Go for writing a terratest and I have string "[[IFN_EYE_HUBW_DEV_AUTO_01] [IFN_EW_HUBW_DEV_AUTO_02]]"
. How can I split this to an array to get "IFN_EYE_HUBW_DEV_AUTO_01"
and "IFN_EW_HUBW_DEV_AUTO_02"
as 1st and 2nd element of the array in go?
ANSWER
Answered 2021-Feb-22 at 06:49You can simply replace all [
and ]
and then split them with Fields
as:
QUESTION
I am writing Go terratest script to validate SSH connection for AWS EC2 instance
I already have AWS EC2 keypair PEM file in my local
I am able to launch and destroy EC2 instance using terraform.TgApplyAll() and terraform.TgDestroyAll() methods and fetch the output variables using terraform.Output() method
My local AWS EC2 keypair PEM file is used for creating EC2 instance in AWS
Now I am trying to validate SSH connection Programmatically from terratest Go script.
I am NOT able to load my local AWS EC2 Key pair to sshKeyPair variable in Go terratest script
I used below code snippet but no use
I also tried script present in at https://github.com/gruntwork-io/terratest/blob/907c09f0696083a5ada580debb66bb5c00c19c32/modules/test-structure/save_test_data.go#L66 to load my local EC2 key pair using LoadEc2KeyPair and test EC2 SSH using fmt.Sprintf("SSH to public host %s", publicIP) But getting error while reading EC2 keypair from local in LoadTestData(t testing.TestingT, path string, value interface{}) method at json.Unmarshal(bytes, value) built in call
Error message : Failed to parse JSON for value D:\AWS\KeyPair\pandukeypair.pem: invalid character '-' in numeric literal I am getting this error as I am trying to ream .pem file and code is trying to do json.umarshal on the .pem file
All code snippets available in github/terratest modules talks about creating new keypair and loading AWS EC2 JSON keypair as but i am not getting any approach/Logic for my scenario where already existing keypair JSON is present I just want to load and use it.
Full Code is present in below link
https://www.dropbox.com/sh/dl2mpesidsxitdu/AAAOi4Nmp41CHMSPcyU7a2qva?dl=0
...ANSWER
Answered 2020-Dec-23 at 13:39This can be achieved by using below Code snippet/functio ..
GenerateRSAKeyPairE:
func RSAKeyPairFromFile(fpath string) (*terrassh.KeyPair, error) {
// import crypto/x509
// import enter code here
io/ioutil
// import encoding/pem
// import "golang.org/x/crypto/ssh"
// terrassh "github.com/gruntwork-io/terratest/modules/ssh"
QUESTION
I am going through the following video that shows how to test Terraform "azurerm" provider.
P3 - How to test infrastructure as code - Terraform/TerraTest/Golang/Azure REST API - Hands-on Demos
I am having hard time underestanding what exact value Terratest adds in the approach shown in the video.
To my simplistic view, I can easily write a relatively simple script (Bash, Python, PowerShell Core Linux , etc.) to cal Azure REST API (Azure CLI is a much simpler option) and test verift my deployed infrastructure.
Why do it need to go throough all that golang and Terratest effort that is explained in the video?
...ANSWER
Answered 2020-Nov-16 at 03:02In my opinion, it depends on the different requirements. When you just need to use the REST API quickly and no other requirement, then the simplest way is best. But when you want to execute the REST API in code, here is the golang. Then this video is the example you need.
In fact, I think it's a good thing to learn the process that how does the REST API executes in the code. It makes you clearly know each step it will do. If there is something wrong, then you will know which step causes the error.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install terratest
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page