Small utility Terraform provider for command-like data source conveniences.
Currently the following data sources are supported:
smallutil_http_req
- Performs a HTTP request (think
curl
) to obtain a value. Currently onlytext/plain
andapplication/json
are supported, and only string value from one level of object nesting is supported. This data source allows for bothoverride
value (i.e. if specified, it will just use this value) and alsodefault
value (i.e. if specified, if the HTTP request fails, it will fall back to this value).
- Performs a HTTP request (think
For Linux and Mac OSX users, simply run:
curl -sL https://raw.githubusercontent.com/guangie88/terraform-provider-smallutil/master/install_from_release.sh | bash
This will install the latest version of the plugin and place it into your Terraform plugin directory (creates the directory if it doesn't exist).
Alternatively, you can visit the Releases page and download the zip file corresponding to your OS and architecture.
Unzip the plugin binary into ~/.terraform.d/plugins
, or
%APPDATA%\terraform.d\plugins
for Windows. You may check the official
guide
If you prefer to build the plugin from scratch, follow the step here.
provider "smallutil" {}
data "smallutil_http_req" "plain_tag" {
url = "http://localhost:8080/plain"
}
data "smallutil_http_req" "json_tag" {
url = "http://localhost:8080/json"
response_content_type = "application/json"
response_content_json_key = ".tag"
}
data "smallutil_http_req" "failed_tag" {
url = "http://localhost:8080/no-such-endpoint"
default = "failed-tag"
}
data "smallutil_http_req" "override_tag" {
url = "http://localhost:8080/no-such-endpoint"
override = "override-tag"
}
You will need Go compiler >= 1.11 (because this use Go modules).
Simply run at the repo root directory:
go build
This will generate terraform-provider-smallutil
binary, which is the compiled
Terraform provider module.
You will need Terraform CLI.
After building, run the following to move the Terraform provider module to the test directory:
mv terraform-provider-smallutil tf_test/
After that, you will need to terminals, one to run the test server, and one
to run terraform
commands.
Navigate to tf_test/server
. Run the following:
go build
./server
Navigate to tf_test/
. Run the following:
terraform init
terraform apply
You should see that the terraform apply
command run successfully and shows
a list of Terraform outputs.