RJPearson94 / terraform-provider-twilio

Terraform Twilio provider
https://registry.terraform.io/providers/RJPearson94/twilio/latest/docs
Mozilla Public License 2.0
32 stars 7 forks source link

Create a TwiML Bin #49

Open mcrobbj-SilverBullet opened 2 years ago

mcrobbj-SilverBullet commented 2 years ago

Is your feature request related to a problem

There doesn't seem to be a way to create a TwiML Bin

Describe the solution you'd like

resource "twilio_twiml_app" "app" { account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" friendly_name = "myName" twiml = "<?xml version="1.0" encoding="UTF-8"?>

Your code is {{otp}}" } ## Additional context This is for the test integration with OKTA: https://developer.okta.com/docs/guides/telephony-inline-hook/nodejs/main/
RJPearson94 commented 2 years ago

Hi @mcrobbj-SilverBullet, Thanks for raising the feature request. Unfortunately Twilio doesn't currently provide a public API for creating, updating or deleting TwiML bins, TwiML bins can only be managed via the console. So I cannot add this to the provider.

Due to this limitation, I tend to use Assets for any static TwiML and Functions for any complex or dynamic TwiML that I need to generate. The example that you shared, would require you to create a small Twilio function to achieve this.

The function code would look like

exports.handler = function(context, event, callback) {
  const twiml = new Twilio.twiml.VoiceResponse();
  twiml.say(`Your code is ${event.otp}`);
  return callback(null, twiml);
};

This code could be inline in the terraform, an example can be seen at https://github.com/RJPearson94/terraform-provider-twilio/blob/main/examples/serverless/function/content/main.tf#L16-L17 or in a JS file which is referenced from the terraform code, an example can be seen at https://github.com/RJPearson94/terraform-provider-twilio/blob/main/examples/serverless/function/source/main.tf#L16

A complete example of deploying a function can be seen at https://github.com/RJPearson94/terraform-provider-twilio/blob/main/examples/serverless/deployment/main.tf (the asset configuration can be removed)

once the function is deployed you can make a GET request to the function url and pass the otp as a query string param

I know this isn't the answer you were hoping for but I hope it helps. If you have any further questions then let me know.