github.com/mponton/terratest@v0.44.0/modules/terraform/validate.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/mponton/terratest/modules/testing"
     5  	"github.com/stretchr/testify/require"
     6  )
     7  
     8  // Validate calls terraform validate and returns stdout/stderr.
     9  func Validate(t testing.TestingT, options *Options) string {
    10  	out, err := ValidateE(t, options)
    11  	require.NoError(t, err)
    12  	return out
    13  }
    14  
    15  // ValidateInputs calls terragrunt validate and returns stdout/stderr.
    16  func ValidateInputs(t testing.TestingT, options *Options) string {
    17  	out, err := ValidateInputsE(t, options)
    18  	require.NoError(t, err)
    19  	return out
    20  }
    21  
    22  // ValidateE calls terraform validate and returns stdout/stderr.
    23  func ValidateE(t testing.TestingT, options *Options) (string, error) {
    24  	return RunTerraformCommandE(t, options, FormatArgs(options, "validate")...)
    25  }
    26  
    27  // ValidateInputsE calls terragrunt validate-inputs and returns stdout/stderr
    28  func ValidateInputsE(t testing.TestingT, options *Options) (string, error) {
    29  	if options.TerraformBinary != "terragrunt" {
    30  		return "", TgInvalidBinary(options.TerraformBinary)
    31  	}
    32  	return RunTerraformCommandE(t, options, FormatArgs(options, "validate-inputs")...)
    33  }
    34  
    35  // InitAndValidate runs terraform init and validate with the given options and returns stdout/stderr from the validate command.
    36  // This will fail the test if there is an error in the command.
    37  func InitAndValidate(t testing.TestingT, options *Options) string {
    38  	out, err := InitAndValidateE(t, options)
    39  	require.NoError(t, err)
    40  	return out
    41  }
    42  
    43  // InitAndValidateInputs runs terragrunt init and validate-inputs with the given options and returns stdout/stderr from the validate command.
    44  func InitAndValidateInputs(t testing.TestingT, options *Options) string {
    45  	out, err := InitAndValidateInputsE(t, options)
    46  	require.NoError(t, err)
    47  	return out
    48  }
    49  
    50  // InitAndValidateE runs terraform init and validate with the given options and returns stdout/stderr from the validate command.
    51  func InitAndValidateE(t testing.TestingT, options *Options) (string, error) {
    52  	if _, err := InitE(t, options); err != nil {
    53  		return "", err
    54  	}
    55  
    56  	return ValidateE(t, options)
    57  }
    58  
    59  // InitAndValidateInputsE runs terragrunt init and validate with the given options and rerutns stdout/stderr
    60  func InitAndValidateInputsE(t testing.TestingT, options *Options) (string, error) {
    61  	if _, err := InitE(t, options); err != nil {
    62  		return "", err
    63  	}
    64  	return ValidateInputsE(t, options)
    65  }