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
- Install Go on your machine
go get github.com/daftcode/terraform-provider-scripted
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
Based on terraform-provider-shell
by Toni Ylenius.
License