terraform-provider-validate

command module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 2 Imported by: 0

README

Terraform Provider - Validate

Build Status Coverage Status Go Report Card Release Badge

Maintainers

This provider plugin is maintained by Craig Monson

Requirements

  • Terraform 0.11.x or greater
  • Go 1.11 (to build the provider plugin)

Installation

To install, as this is a 3rd party plugin, you'll need to follow the directions here.

Basically, download the latest, decompress it, and place the executable in your $HOME/.terraform.d/plugins/<OS>_<ARCH>/ directory (for unix based systems), or %APPDATA%\terraform.d\plugins\<OS>_<ARCH> for windows.

The file should be named: terraform-provider-validate_vX.X.X (where X.X.X matches the version) or terraform-provider-validate_vX.X.X.exe` for windows.

terraform init will pull from the above directory.

Example: download the binary for os-x, unzip, and make sure the file is saved as: /Users/<USERNAME>/.terraform.d/plugins/darwin_amd64/terraform-provider-validate_vX.X.X

Or, on windows (possibly): C:\Users\<USERNAME>\AppData\Roaming\terraform.d\plugins\windows_amd64\terraform-provider-validate_vX.X.X.exe

Usage

provider "validate" {}

variable "test_exact" {
  type    = string
  default = "test_exact"
}

variable "test_one_of" {
  type    = string
  default = "test_one_of"
}

variable "test_regex" {
  type    = string
  default = "^test_.*"
}

data "validate" "exact" {
  val   = var.test_exact
  exact = "test_exact"
}

data "validate" "not_exact" {
  val       = var.test_exact
  not_exact = "test_exact"
}

data "validate" "one_of" {
  val    = var.test_one_of
  one_of = ["test_one_of"]
}

data "validate" "not_one_of" {
  val        = var.test_one_of
  not_one_of = ["test_one_of"]
}

data "validate" "regex" {
  val   = var.test_regex
  regex = "test_regex"
}

data "validate" "not_regex" {
  val       = var.test_regex
  not_regex = "test_regex"
}

data "validate" "optional_exact" {
  val      = var.test_optional_exact
  exact    = "This variable is optional, so can be empty"
  optional = true
}

data "validate" "customized_error_message" {
  val       = "This will fail"
  exact     = "Fail me"
  error_msg = "This is a custom error message that will be displayed when this validation fails"
}

The validate data source will validate input values against a validation check. When terraform plan is run, the values will be validated against the check, and will raise an error if it fails. This allows for ensuring any data requirements (tagging for example) meet a desired set of criteria.

Argument Reference

The following arguments are supported:

  • val - (Required) (string) The value to be checked. This should be a variable.
  • optional - (Optional) (bool) (Default: false) If set to true, this will allow the check to be optional. If it's empty, ie: "", then the check will pass, regardless if it passes the underlying check.
  • error_msg - (Optional) (string) This message will be displayed instead of the default one if this validation check fails. This allows more customized error outputs.

At least one of these arguments must also exist, but combinations are possible (see compatability matrix):

  • exact - (Optional) (a string) Check val is an exact match of this argument.
  • not_exact - (Optional) (a string) Check val can not match exactly this argument.
  • one_of - (Optional) (a list) Check val is an exact match of one of the items in this list.
  • not_one_of - (Optional) (a list) Check val can not exactly match one of the items in this list.
  • regex - (Optional) (a string) Check val matches the regular expression expressed as this string. This utilizes the RE2 regular expression syntax, which can be found here.
  • not_regex - (Optional) (a string) Check val does not match the regular expression expressed as this string. This utilizes the RE2 regular expression syntax, which can be found here.
Compatibility Matrix
exact not_exact one_of not_one_of regex not_regex
exact N N N N N
not_exact N N N Y Y
one_of N N N N N
not_one_of N N N Y Y
regex N Y N Y Y
not_regex N Y N Y Y
Attributes Reference

There are no attributes for this data source.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed, and a correctly setup GOPATH.

To compile the provider, run:

make build

This will build the provider, and put the binary in the local directory.

To test, simply run:

make test

To run the integration tests (check that it works through terraform itself), run:

make tf-test

which will execute a terraform template with passing checks. Similarly, to execute a terraform template with failing checks, run:

make tf-test-fail

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL