terratest | Go library that makes it easier to write automated tests | Infrastructure Automation library

 by   gruntwork-io Go Version: v0.43.0 License: Apache-2.0

kandi X-RAY | terratest Summary

kandi X-RAY | terratest Summary

terratest is a Go library typically used in Devops, Infrastructure Automation, Ansible, Docker, Terraform applications. terratest has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

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

            kandi-support Support

              terratest has a medium active ecosystem.
              It has 6892 star(s) with 1259 fork(s). There are 117 watchers for this library.
              There were 9 major release(s) in the last 12 months.
              There are 176 open issues and 376 have been closed. On average issues are closed in 166 days. There are 51 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of terratest is v0.43.0

            kandi-Quality Quality

              terratest has 0 bugs and 0 code smells.

            kandi-Security Security

              terratest has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              terratest code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              terratest is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              terratest releases are available to install and integrate.
              It has 46310 lines of code, 2079 functions and 590 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of terratest
            Get all kandi verified functions for this library.

            terratest Key Features

            No Key Features are available at this moment for terratest.

            terratest Examples and Code Snippets

            No Code Snippets are available at this moment for terratest.

            Community Discussions

            QUESTION

            How do I implement terratest(golang) with customized "terraform apply" command?
            Asked 2022-Mar-03 at 16:23

            I use the following lines to run my terraform plan & apply in example/ folder:

            ...

            ANSWER

            Answered 2022-Mar-03 at 16:23

            To 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:

            Source https://stackoverflow.com/questions/71316617

            QUESTION

            How to concatenate strings in Terraform output with for loop?
            Asked 2021-Nov-12 at 17:30

            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:30

            It 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:

            Source https://stackoverflow.com/questions/69944595

            QUESTION

            How to convert the string representation of a Terraform set of strings to a slice of strings
            Asked 2021-Sep-25 at 06:58

            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:58

            Actually 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)

            Source https://stackoverflow.com/questions/69316552

            QUESTION

            Terratest utility pkg for func reuse
            Asked 2021-Sep-23 at 14:54

            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:54

            Go 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.

            Source https://stackoverflow.com/questions/69291333

            QUESTION

            VS Code won't let me save a go test file
            Asked 2021-May-06 at 12:05

            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:05

            99.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.

            Source https://stackoverflow.com/questions/67210410

            QUESTION

            Azure pipeline - terratest - ERROR: Please run 'az login' to setup account
            Asked 2021-Apr-16 at 11:30

            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:30

            and 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 :

            So I change my pipeline to this :

            Source https://stackoverflow.com/questions/67109139

            QUESTION

            Azure terratest - Build constraints exclude all Go files
            Asked 2021-Apr-13 at 12:07

            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:07

            accoding to [this issue][1] try using the -tags azure option like this:

            Source https://stackoverflow.com/questions/67028558

            QUESTION

            Converting a string to array
            Asked 2021-Feb-22 at 07:40

            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:49

            You can simply replace all [ and ] and then split them with Fields as:

            Source https://stackoverflow.com/questions/66310802

            QUESTION

            How can I load my AWS EC2 Key pair PEM file to my terratest script to perform AWS EC2 SSH connection validation
            Asked 2020-Dec-23 at 13:39

            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

            https://github.com/gruntwork-io/module-asg/blob/067647b3aaeb24151badbc5a2d9a6b5381dd2041/test/server_group_test.go#L78

            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:39

            This can be achieved by using below Code snippet/functio ..

            GenerateRSAKeyPairE: func RSAKeyPairFromFile(fpath string) (*terrassh.KeyPair, error) { // import crypto/x509 // import enter code hereio/ioutil // import encoding/pem // import "golang.org/x/crypto/ssh" // terrassh "github.com/gruntwork-io/terratest/modules/ssh"

            Source https://stackoverflow.com/questions/65253933

            QUESTION

            Terraform Azure Testing: What is the value that terratest adds?
            Asked 2020-Nov-16 at 13:56

            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:02

            In 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.

            Source https://stackoverflow.com/questions/64838853

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install terratest

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/gruntwork-io/terratest.git

          • CLI

            gh repo clone gruntwork-io/terratest

          • sshUrl

            git@github.com:gruntwork-io/terratest.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Infrastructure Automation Libraries

            terraform

            by hashicorp

            salt

            by saltstack

            pulumi

            by pulumi

            terraformer

            by GoogleCloudPlatform

            Try Top Libraries by gruntwork-io

            terragrunt

            by gruntwork-ioGo

            cloud-nuke

            by gruntwork-ioGo

            git-xargs

            by gruntwork-ioGo

            bash-commons

            by gruntwork-ioShell

            fetch

            by gruntwork-ioGo