Closed danpilch closed 3 years ago
hi @danpilch,
This is already implemented however the Twilio UI provides a nice abstraction over how this works. Under the hood, the Twilio UI builds a webhook URL using the service, environment and path you supply i.e. https://twilio-test-1w3l7hnnwb52x52r-<random_number>.twil.io/test-function
will be set as the messaging/voice/fax URL. When using the Terraform provider you just need to construct the webhook URL and set it as the URL in the corresponding block (messaging/ voice/ fax).
I have included some example Terraform below
resource "random_string" "random" {
length = 16
special = false
}
resource "twilio_serverless_service" "service" {
unique_name = "twilio-test-${random_string.random.result}"
friendly_name = "test"
}
resource "twilio_serverless_function" "function" {
service_sid = twilio_serverless_service.service.sid
friendly_name = "test"
content = <<EOF
exports.handler = function (context, event, callback) {
callback(null, "Hello World");
};
EOF
content_type = "application/javascript"
content_file_name = "helloWorld.js"
path = "/test-function"
visibility = "public"
}
resource "twilio_serverless_build" "build" {
service_sid = twilio_serverless_service.service.sid
function_version {
sid = twilio_serverless_function.function.latest_version_sid
}
dependencies = {
"twilio" : "3.6.3"
"fs" = "0.0.1-security"
"lodash" = "4.17.11"
"util" = "0.11.0"
"xmldom" = "0.1.27"
}
polling {
enabled = true
}
}
resource "twilio_serverless_environment" "environment" {
service_sid = twilio_serverless_service.service.sid
unique_name = "test"
}
resource "twilio_serverless_deployment" "deployment" {
service_sid = twilio_serverless_service.service.sid
environment_sid = twilio_serverless_environment.environment.sid
build_sid = twilio_serverless_build.build.sid
}
resource "twilio_phone_number" "phone_number" {
account_sid = var.account_sid
phone_number = var.phone_number
messaging {
url = "https://${twilio_serverless_environment.environment.domain_name}${twilio_serverless_function.function.path}"
}
}
Please note, this Terraform will purchase a new phone number.
Does this resolve your issue?
This is what I was missing!
messaging {
url = "https://${twilio_serverless_environment.environment.domain_name}${twilio_serverless_function.function.path}"
}
thanks!
Is your feature request related to a problem
I am not sure if this is already implemented, but under phone numbers I want to be able to define my
twilio_serverless_function
like so:thanks