Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
820 stars 219 forks source link

Build Status Coverage Status Go Report Card

Terraform provider for generic REST APIs

Maintenance Note

This provider is largely feature-complete and in maintenance mode.

 

About This Provider

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:

Have a look at the examples directory for some use cases.

 

Provider Documentation

This provider has only a few moving components, but LOTS of configurable parameters:

 

Usage

 

Troubleshooting

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...

 

Debug log

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:

 

Importing existing resources

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.

 

Installation

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}.

 

Contributing

Pull requests are always welcome! Please be sure the following things are taken care of with your pull request:

Development environment requirements:

To 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