This terraform provider allows you to interact with APIs that may not yet have a first-class provider available by implementing a "dumb" REST API client.
This provider is essentially created to be a terraform-wrapped cURL
client. Because of this, you need to know quite a bit about the API you are interacting with as opposed to full-featured terraform providers written with a specific API in mind.
There are a few requirements about how the API must work for this provider to be able to do its thing:
/api/v1/things
...
/api/v1/things
creates a new object/api/v1/things/{id}
manages an existing objectHave a look at the examples directory for some use cases
This provider has only a few moving components, but LOTS of configurable parameters
API_DATA_IS_SENSITIVE=true
.*_path
elements are for very specific use cases where one might initially create an object in one location, but read/update/delete it on another path. For this reason, they allow for substitution to be done by the provider internally by injecting the id
somewhere along the path. This is similar to terraform's substitution syntax in the form of ${variable.name}
, but must be done within the provider due to structure. The only substitution available is to replace the string {id}
with the internal (terraform) id
of the object as learned by the id_attribute
.
Because this provider is just a terraform-wrapped cURL
, the API details and the go implementation of this client are often leaked to you.
This means you, as the user, will have a bit more troubleshooting on your hands than would typically be required of a full-fledged provider if you experience issues.
Here are some tips for troubleshooting that may be helpful...
Rely heavily on the debug log. The debug log, enabled by setting the environment variable TF_LOG=1
and enabling the debug
parameter on the provider, is the best way to figure out what is happening.
If an unexpected error occurs, enable debug log and review the output
This provider supports importing existing resources into the terraform state. Import is done according to the various provider/resource configuation settings to contact the API server and obtain data. That is: if a custom read method, path, or id attribute is defined, the provider will honor those settings to pull data in.
To import data:
terraform import restapi.Name /path/to/resource
See a concrete example here
There are two standard methods of installing this provider detailed in Terraform's documentation. You can place the file in the directory of your .tf file in terraform.d/plugins/{OS}_{ARCH}/
or place it in your home directory at ~/.terraform.d/plugins/{OS}_{ARCH}/
The released binaries are named terraform-provider-restapi_vX.Y.Z-{OS}-{ARCH}
so you know which binary to install. You may need to rename the binary you use during installation to just terraform-provider-restapi_vX.Y.Z
.
Once downloaded, be sure to make the plugin executable by running chmod +x terraform-provider-restapi_vX.Y.Z-{OS}-{ARCH}
.
Pull requests are always welcome! Please be sure the following things are taken care of with your pull request:
go fmt
is run before pushingscripts/test.sh
script to be sure everything worksgo
is in your pathterraform
is in your pathTo make development easy, you can use the Docker image druggeri/tdk as a development environment:
docker run -it --name tdk --rm -v "$HOME/go":/root/go druggeri/tdk
go get github.com/Mastercard/terraform-provider-restapi
cd ~/go/src/github.com/Mastercard/terraform-provider-restapi
#Hack hack hack