terraform-provider-scripted

command module
v3.6.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 4 Imported by: 0

README

terraform-provider-scripted

This is a terraform provider that lets you wrap shell/interpreter based tools to Terraform resources in a simple way.

Installing

Copied from the Terraform documentation:

To install a plugin, put the binary somewhere on your filesystem, then configure Terraform to be able to find it. The configuration where plugins are defined is ~/.terraformrc for Unix-like systems and %APPDATA%/terraform.rc for Windows.

Build it from source (instructions below) and move the binary terraform-provider-scripted to bin/ and it should work.

Using the provider

First, an simple example that is used in tests too

provider "scripted" {
  commands_create = "echo \"hi\" > test_file"
  commands_read = "echo -n \"out=$(cat test_file)\""
  commands_delete = "rm test_file"
}

resource "scripted_resource" "test" {
}
$ terraform plan
$ terraform apply
$ terraform destroy

To create a more complete example add this to the sample example file

provider "scripted" {
  alias = "file"
  commands_needs_update = <<EOF
[ "$(cat '{{ .Cur.path }}')" == '{{ .Cur.content }}' ] || exit 1
EOF
  commands_create = "echo -n '{{ .Cur.content }}' > '{{ .Cur.path }}'"
  commands_read = "echo -n \"out=$(cat '{{ .Cur.path }}')\""
  commands_delete = "rm '{{ .Cur.path }}'"
}

resource "scripted_resource" "test" {
  provider = "scripted.file"
  context {
    path = "test_file"
    content = "hi"
  }
}

Parameters can be used to change the resources. More info in docs and examples.

Building from source

  1. Install Go on your machine
  2. go get github.com/daftcode/terraform-provider-scripted
  3. make build. You will now find the binary at dist/terraform-provider-scripted.

Running acceptance tests

make test

Known Problems

  • The provider will error instead of removing the resource if the delete command fails. However, this is a safe default.
  • Changes in provider do not issue resource rebuilds. Please parametrize all parameters that will change.

Authors

  • Krzysztof Nazarewski

Based on terraform-provider-shell by Toni Ylenius.

License

  • MIT, See LICENSE file

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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