2021-05-14 00:58:30 +03:00
# Twilio Terraform Provider
2021-07-02 00:35:21 +03:00
[![GitHub release (latest by date including pre-releases) ](https://img.shields.io/github/v/release/twilio/terraform-provider-twilio? )](https://github.com/Twilio/terraform-provider-twilio/releases/latest)
[![Terraform Registry ](https://img.shields.io/badge/registry-twilio-green?logo=terraform&style=flat )](https://registry.terraform.io/providers/twilio/twilio/latest)
2020-01-30 21:12:18 +03:00
2021-06-28 16:59:53 +03:00
## Project Status
2021-07-02 00:35:21 +03:00
:warning: This project is currently in **PILOT** and under active development. If you would like to participate in the pilot, please sign up for [Twilio Insiders ](https://twil.io/insiders ).
2020-03-10 00:07:30 +03:00
## Requirements
2021-06-25 17:04:34 +03:00
- [Terraform ](https://www.terraform.io/downloads.html ) v0.15.x
- [Go ](https://golang.org/doc/install ) 1.15+ (to build the provider plugin)
## Resource Documentation
Documentation on the available resources that can be managed by this provider and their parameters can be found [here ](twilio/resources/README.md ).
Note that file upload resources are currently not available.
2020-03-10 00:07:30 +03:00
## Building The Provider
2021-04-26 23:53:20 +03:00
Clone repository:
2020-03-10 00:07:30 +03:00
```sh
2021-06-25 17:04:34 +03:00
git clone git@github.com:twilio/terraform-provider-twilio
2020-01-30 21:12:18 +03:00
```
2021-05-14 00:58:30 +03:00
Enter the provider directory and build the provider:
2020-02-06 00:40:45 +03:00
2020-03-10 00:07:30 +03:00
```sh
2021-06-25 17:04:34 +03:00
make build
2020-01-30 21:12:18 +03:00
```
2020-03-10 00:07:30 +03:00
2021-05-14 00:58:30 +03:00
## Installing and Using the Provider
2021-06-25 17:04:34 +03:00
2021-05-14 00:58:30 +03:00
1. Run `make install` to install and build the twilio-terraform-provider.
2021-05-14 21:28:42 +03:00
2. Configure the Twilio provider with your twilio credentials in your Terraform configuration file (e.g. main.tf). These can also be set via `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` environment variables.
2021-05-14 00:58:30 +03:00
3. Add your resource configurations to your Terraform configuration file (e.g. main.tf).
2021-06-30 17:37:05 +03:00
2021-05-14 00:58:30 +03:00
```terraform
terraform {
2021-06-29 21:41:11 +03:00
required_providers {
twilio = {
2021-07-02 17:23:27 +03:00
source = "twilio/twilio"
version = ">=0.4.0"
2021-05-14 00:58:30 +03:00
}
2021-06-29 21:41:11 +03:00
}
2021-05-14 00:58:30 +03:00
}
# Credentials can be found at www.twilio.com/console.
provider "twilio" {
2021-07-02 17:23:27 +03:00
// account_sid defaults to TWILIO_ACCOUNT_SID env var
// auth_token defaults to TWILIO_AUTH_TOKEN env var
2021-05-14 00:58:30 +03:00
}
2021-06-21 18:58:33 +03:00
resource "twilio_api_accounts_keys_v2010" "key_name" {
2021-06-29 21:41:11 +03:00
friendly_name = "terraform key"
2021-05-14 00:58:30 +03:00
}
output "messages" {
2021-06-29 21:41:11 +03:00
value = twilio_api_accounts_keys_v2010.key_name
2021-05-14 00:58:30 +03:00
}
```
2021-05-20 01:16:58 +03:00
2021-06-30 17:37:05 +03:00
4. Run `terraform init` and `terraform apply` to initialize and apply changes to your Twilio infrastructure.
2021-06-28 17:18:51 +03:00
2021-06-30 17:37:05 +03:00
## Examples
2021-06-26 00:36:04 +03:00
2021-06-30 17:37:05 +03:00
For usage examples, checkout the [documentation in usage.md ](usage.md ) and the [examples folder ](examples ).
2021-06-26 00:36:04 +03:00
2020-03-10 00:07:30 +03:00
## Developing the Provider
2021-04-26 23:53:20 +03:00
The boilerplate includes the following:
2021-06-30 17:37:05 +03:00
2021-05-14 00:58:30 +03:00
- `Makefile` contains helper functions used to build, package and install the Twilio Terraform Provider. It's currently written for MacOS Terraform provider development, but you can change the variables at the top of the file to match your OS_ARCH.
2021-04-26 23:53:20 +03:00
2021-07-08 23:04:16 +03:00
The `install` function is configured to install the provider into the ~/.terraform.d/plugins/ folder. To use the locally installed provider, prefix the source path with `local` in your Terraform configuration file (i.e., `source = "local/twilio/twilio"` ). Then run `terraform init` to use the locally built provider.
2021-06-30 17:37:05 +03:00
2021-05-14 00:58:30 +03:00
- `examples` contains sample Terraform configuration that can be used to test the Twilio provider
- `twilio` contains the main provider code. This will be where the provider's resources and data source implementations will be defined.
2021-04-26 23:53:20 +03:00
2021-06-30 17:37:05 +03:00
If you wish to work on the provider, you'll first need [Go ](http://www.golang.org ) installed on your machine (version 1.15+ is _required_ ).
2020-03-10 00:07:30 +03:00
To compile the provider, run `make build` . This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
```sh
2021-06-25 17:04:34 +03:00
make build
2020-03-10 00:07:30 +03:00
...
2021-06-25 17:04:34 +03:00
$GOPATH/bin/terraform-provider-twilio
2020-03-10 00:07:30 +03:00
...
```
2020-03-11 01:06:59 +03:00
In order to run the full suite of Acceptance tests, run `make testacc` . Provide your Account SID and Auth Token as environment variables to properly configure the test suite.
2020-03-10 00:07:30 +03:00
2021-06-30 17:37:05 +03:00
_Note:_ Acceptance tests create real resources, and often cost money to run.
2020-03-10 00:07:30 +03:00
```sh
2021-06-25 17:04:34 +03:00
make testacc ACCOUNT_SID=YOUR_ACCOUNT_SID AUTH_TOKEN=YOUR_AUTH_TOKEN
2020-01-30 21:12:18 +03:00
```
2021-06-30 17:37:05 +03:00
2021-06-21 18:58:33 +03:00
You can also specify a particular suite to run like so:
2021-06-30 17:37:05 +03:00
2021-06-21 18:58:33 +03:00
```shell
2021-06-25 17:04:34 +03:00
make testacc TEST=./twilio/ ACCOUNT_SID=YOUR_ACCOUNT_SID AUTH_TOKEN=YOUR_AUTH_TOKEN
2021-06-21 18:58:33 +03:00
```
2020-01-30 21:12:18 +03:00
2021-06-22 22:48:50 +03:00
An example test file can be found [here ](https://github.com/twilio/terraform-provider-twilio/blob/main/twilio/resources_flex_test.go ).
2020-03-17 22:23:02 +03:00
2020-03-10 00:07:30 +03:00
### Debugging
2021-06-28 17:18:51 +03:00
2020-01-30 21:12:18 +03:00
First:
2021-06-30 17:37:05 +03:00
2020-03-10 01:08:14 +03:00
```sh
2021-06-25 17:04:34 +03:00
export TF_LOG=TRACE
2020-01-30 21:12:18 +03:00
```
2021-06-30 17:37:05 +03:00
2021-05-14 00:58:30 +03:00
then refer to the [Terraform Debugging Documentation ](https://www.terraform.io/docs/internals/debugging.html ).