This is a terraform provider that lets you wrap shell based tools to Terraform resources in a simple way.
There is also exec provider, but it only implements Create
CRUD operation.
The naming of this provider has been hard. The provider is about wrapping functionality by running shell scripts. Originally the name was generic_shell_wrapper
, but currently the name is just shell
. The naming in code is still inconsistent.
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-shell
to bin/
and it should work.
First, an simple example that is used in tests too
provider "shell" {
create_command = "echo \"hi\" > test_file"
read_command = "awk '{print \"out=\" $0}' test_file"
delete_command = "rm test_file"
}
resource "shell_resource" "test" {
}
$ terraform plan
$ terraform apply
$ terraform destroy
To create a more complete example add this to the sample example file
provider "shell" {
alias = "write_to_file"
create_command = "echo \"%s\" > %s"
create_parameters = [ "input", "file" ]
read_command = "awk '{print \"out=\" $0}' %s"
read_parameters = [ "file" ]
delete_command = "rm %s"
delete_parameters = [ "file" ]
}
resource "shell_resource" "filetest" {
provider = "shell.write_to_file"
arguments {
input = "this to the file"
file = "test_file2"
}
}
Parameters can by used to change the resources.
- Install Go on your machine
- Set up Gopath
git clone
this repository into$GOPATH/src/github.com/toddnni/terraform-provider-shell
- Get the dependencies. Run
go get
make install
. You will now find the binary at$GOPATH/bin/terraform-provider-shell
.
make test
- The provider won't support
Update
CRUD operation. - The provider won't print output of the commands.
- 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.
- Toni Ylenius
The structure is inspired from the Softlayer and libvirt Terraform provider sources.
Some code has been adapted from local-exec provisioner from terraform core.
- MIT, See LICENSE file