Terraform data source that can consume YAML input

License: Unlicense

Language: Go

Keywords: json, terraform, terraform-provider, yaml

Terraform YAML Data Source


This provider defines a Terraform data source that can consume YAML input [as a string] and parse a map out of it. Map keys and values should be both strings. If map values are not strings they are going to be serialized using YAML flow style (resembles JSON but less restrictive). Nested maps can be optionally flattened with a given separator.

Please note that JSON is subset of YAML and therefore this data source can be used to parse arbitrary JSON as well.

Data Sources

This plugin defines following data sources:

  • yaml_map_of_strings
  • yaml_list_of_strings



The following arguments are supported:

  • input - (Required) A string that will be parsed. Should be a valid YAML, YAML flow or JSON.
  • flatten - (Optional) [only yaml_map_of_strings] A string that should be used as a separator in order to flatten nested maps. If set to a non-empty value nested maps going to be flattened.


The following attribute is exported:

  • output - Map with keys and values as strings for yaml_map_of_strings and list of strings for yaml_list_of_strings.


Boolean Conversion

The underlying parser converts y into a boolean that can be serialized as a true. For instance {foo: y} will be parsed as {foo: true}. In order to avoid such behavior prefer using explicit string declaration with quotes: {foo: "y"}.


Terraform automatically discovers the Providers when it parses configuration files. This only occurs when the init command is executed.

Currently Terraform is able to automatically download only official plugins distributed by HashiCorp.

All other plugins should be installed manually.

Terraform will search for matching Providers via a Discovery process, including the current local directory.

This means that the plugin should either be placed into current working directory where Terraform will be executed from or it can be installed system-wide.


locals {input="input.yaml"}

data "yaml_map_of_strings"  "normal" { input = "${file(local.input)}"                              }
data "yaml_map_of_strings"  "flat"   { input = "${file(local.input)}" flatten="/"                  }
data "yaml_list_of_strings" "list"   { input = "${data.yaml_map_of_strings.normal.output["list"]}" }

output "normal" { value = "${data.yaml_map_of_strings.normal.output}" }
output "flat"   { value = "${data.yaml_map_of_strings.flat.output}"   }
output "list"   { value = "${data.yaml_list_of_strings.list.output}"  }


$ wget "$(uname -s | tr '[:upper:]' '[:lower:]')-amd64"
$ chmod +x ./terraform-provider-yaml*


$ ls -1

$ terraform init
  Initializing provider plugins...
  The following providers do not have any version constraints in configuration,
  so the latest version was installed.
  To prevent automatic upgrades to new major versions that may contain breaking
  changes, it is recommended to add version = "..." constraints to the
  corresponding provider blocks in configuration, with the constraint strings
  suggested below.
  * provider.yaml: version = "~> 2.0"
  Terraform has been successfully initialized!
  You may now begin working with Terraform. Try running "terraform plan" to see
  any changes that are required for your infrastructure. All Terraform commands
  should now work.
  If you ever set or change modules or backend configuration for Terraform,
  rerun this command to reinitialize your working directory. If you forget, other
  commands will detect it and remind you to do so if necessary.


$ cat > input.yaml << EOF
    c: foobar
 - foo
 - bar

$ terraform apply
  data.yaml_map_of_strings.normal: Refreshing state...
  data.yaml_map_of_strings.flat: Refreshing state...
  data.yaml_list_of_strings.list: Refreshing state...
  Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
  flat = {
    a/b/c = foobar
    list = [foo, bar]
  list = [
  normal = {
    a = {b: {c: foobar}}
    list = [foo, bar]



In order to work on the provider, Go should be installed first (version 1.8+ is required). goenv and gvm are great utilities that can help a lot with that and simplify setup tremendously. GOPATH should be setup correctly and as long as $GOPATH/bin should be added $PATH.

Source Code

Source code can be retrieved either with go get

$ go get -u -d

or with git

$ mkdir -p ${GOPATH}/src/
$ cd ${GOPATH}/src/
$ git clone .


This project uses govendor to manage its dependencies. When adding a dependency on a new package it should be fetched with:

$ govendor fetch +o


$ make test
  go test -v ./...
  ?	[no test files]
  === RUN   TestYamlDataSource
  --- PASS: TestYamlDataSource (0.06s)
  === RUN   TestProvider
  --- PASS: TestProvider (0.00s)
  ok	0.092s
  go vet ./...


In order to build plugin for the current platform use [GNU]make:

$ make build
  go build -o terraform-provider-yaml_v2.0.0

it will build provider from sources and put it into current working directory.

If Terraform was installed (as a binary) or via go get -u it'll pick up the plugin if executed against a configuration in the same directory.


In order to prepare provider binaries for all platforms:

$ make release
  GOOS=darwin GOARCH=amd64 go build -o './release/terraform-provider-yaml_v2.0.0-darwin-amd64'
  GOOS=linux GOARCH=amd64 go build -o './release/terraform-provider-yaml_v2.0.0-linux-amd64'


This project follow Semantic Versioning


This project follows keep a changelog guidelines for changelog.


Please see


This is free and unencumbered software released into the public domain. See LICENSE

Project Statistics

Sourcerank 6
Repository Size 4.26 MB
Stars 44
Forks 6
Watchers 5
Open issues 0
Dependencies 0
Contributors 2
Tags 4
Last updated
Last pushed

Top Contributors See all

Borys Pierov Anton Dessiatov

Recent Tags See all

v2.0.2 April 20, 2019
v2.0.1 April 12, 2019
v2.0.0 June 28, 2018
v1.0.0 June 21, 2018

Something wrong with this page? Make a suggestion

Last synced: 2019-04-23 17:34:28 UTC

Login to resync this repository