Open thinkingserious opened 3 years ago
I used the following code to try and reproduce the error message we see in terraform, but the following produces no error:
package main
import (
"encoding/json"
"fmt"
"os"
twilio "github.com/twilio/twilio-go"
conversations "github.com/twilio/twilio-go/rest/conversations/v1"
)
func main() {
accountSid := os.Getenv("TWILIO_ACCOUNT_SID")
authToken := os.Getenv("TWILIO_AUTH_TOKEN")
client := twilio.NewRestClient(accountSid, authToken)
conversation_params := &conversations.CreateConversationParams{}
conversation_params.SetFriendlyName("Conversation 00")
resp0, err := client.ConversationsV1.CreateConversation(conversation_params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
response, _ := json.Marshal(*resp0)
fmt.Println("Response: " + string(response))
}
participant_00_params := &conversations.CreateConversationParticipantParams{}
participant_00_params.SetMessagingBindingAddress(<User 00 Personal Mobile Number>)
participant_00_params.SetMessagingBindingProxyAddress(<Your purchased Twilio Phone Number>)
resp1, err := client.ConversationsV1.CreateConversationParticipant(*resp0.Sid, participant_00_params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
response, _ := json.Marshal(*resp1)
fmt.Println("Response: " + string(response))
}
participant_01_params := &conversations.CreateConversationParticipantParams{}
participant_01_params.SetMessagingBindingAddress(<User 01 Personal Mobile Number>)
participant_01_params.SetMessagingBindingProxyAddress(<Your purchased Twilio Phone Number>)
resp2, err := client.ConversationsV1.CreateConversationParticipant(*resp0.Sid, participant_01_params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
response, _ := json.Marshal(*resp2)
fmt.Println("Response: " + string(response))
}
}
No, I was asked to try and reproduce with cURL. I did that and also with twilio-go
with no error. But in all those cases, including with terraform, the system ultimately gets setup correctly. 😕
Circling back with the conversations team for additional guidance.
hi 👋
I was looking through the provider and the team has done a really good job on the provider. I noticed this PR and I had a quick look at the issue you described and I think I may have identified the root cause of the issue.
After you add/ create a participant to a conversation you immediately call the updateConversationsParticipants function as seen here. The update participant API call is returning the error Status: 400 - ApiError 50441: Failed to add a proxy address to a participant (null) More info: https://www.twilio.com/docs/errors/50441
and not the original create participant call hence you can see the participant is correctly configured in the Twilio console.
I'm not 100% clear on why the update participant call is returning this error but if you don't call the updateConversationsParticipants
function and replace line 328 with the following code
err = MarshalSchema(d, r)
if err != nil {
return diag.FromErr(err)
}
return nil
then no error is thrown and the provider continues executing successfully. Although, if you modify the messaging_binding_proxy_address
argument to use another Twilio phone number, then you do see the error you specified, so I will continue digging to see what causes this error to occur.
This is also reproducible using the Go SDK with the following code. The code below has been slightly adapted from the example you shared. Now it only configures 1 participant and uses the updated NewRestClient
function in the main branch of the Go SDK repo
package main
import (
"encoding/json"
"fmt"
twilio "github.com/twilio/twilio-go"
conversations "github.com/twilio/twilio-go/rest/conversations/v1"
)
func main() {
client := twilio.NewRestClient()
conversation_params := &conversations.CreateConversationParams{}
conversation_params.SetFriendlyName("Conversation 00")
resp0, err := client.ConversationsV1.CreateConversation(conversation_params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
response, _ := json.Marshal(*resp0)
fmt.Println("Response: " + string(response))
}
participant_00_params := &conversations.CreateConversationParticipantParams{}
participant_00_params.SetMessagingBindingAddress(<User 00 Personal Mobile Number>)
participant_00_params.SetMessagingBindingProxyAddress(<Your purchased Twilio Phone Number>)
resp1, err := client.ConversationsV1.CreateConversationParticipant(*resp0.Sid, participant_00_params)
if err != nil {
fmt.Println(err.Error())
err = nil
} else {
response, _ := json.Marshal(*resp1)
fmt.Println("Response: " + string(response))
}
update_participant_00_params := &conversations.UpdateConversationParticipantParams{}
// the message binding address cannot be set on an update
update_participant_00_params.SetMessagingBindingProxyAddress(<Your purchased Twilio Phone Number>)
updateResp1, updateErr := client.ConversationsV1.UpdateConversationParticipant(*resp0.Sid, *resp1.Sid, update_participant_00_params)
if updateErr != nil {
fmt.Println("Update Error Response: " + updateErr.Error())
updateErr = nil
} else {
response, _ := json.Marshal(*updateResp1)
fmt.Println("Update Response: " + string(response))
}
}
Hope this helps
Thank you for taking a look and providing awesome feedback @RJPearson94!
With respect to "Although, if you modify the messaging_binding_proxy_address
argument to use another Twilio phone number" ... I'm not quite sure what you mean. Are you saying that after you successfully setup a conversation, setting up a second one fails? Can you please walk me through that scenario so I can try to also reproduce? Thank you!!
Hi @thinkingserious.
I have included the steps to reproduce this issue below. Apologies, I should have included it in my original message.
When I said, "Although, if you modify the messaging_binding_proxy_address argument to use another Twilio phone number" I meant that once you have provisioned your conversation and 1 or more participants using Terraform. If you make a change to one of your twilio_conversations_conversations_participants_v1
resources that Terraform detects as a difference, between your configuration and what is held in the state i.e. changing the messaging_binding_proxy_address
value to be a different Twilio phone number. When the changes are applied and the participant is updated then an error will be thrown.
These steps assume that there is no pre-existing Terraform state and resources deployed.
terraform init
then terraform apply
and approve the changes. You will need to wait for all the changes to apply and the outputs to be displayedmessaging_binding_proxy_address
argument to use another Twilio phone numberterraform apply
and you should see Terraform is showing you there is 1 change to apply (similar to Figure 3) Note: this is not limited to just modifying the messaging_binding_proxy_address
argument, this error occurs by any change which causes Terraform to detect a change on the resource and attempt to update the participant.
I also get a similar error when I try to modify an existing participant via the API too
Figure 1
err = MarshalSchema(d, r)
if err != nil {
return diag.FromErr(err)
}
return nil
Figure 2
terraform {
required_providers {
twilio = {
source = "local/twilio/twilio"
version = ">=0.4.0"
}
}
}
provider "twilio" {
}
resource "twilio_conversations_conversations_v1" "create_conversation" {
friendly_name = "Deep Conversation 00"
}
resource "twilio_conversations_conversations_participants_v1" "add_user_00_to_conversation" {
conversation_sid = twilio_conversations_conversations_v1.create_conversation.sid
messaging_binding_address = "<User 00 Personal Mobile Number>"
messaging_binding_proxy_address = "Twilio Phone Number 1"
}
output "create_conversation" {
value = twilio_conversations_conversations_v1.create_conversation
}
output "add_user_00_to_conversation" {
value = twilio_conversations_conversations_participants_v1.add_user_00_to_conversation
}
Figure 3
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# twilio_conversations_conversations_participants_v1.add_user_01_to_conversation will be updated in-place
~ resource "twilio_conversations_conversations_participants_v1" "add_user_01_to_conversation" {
id = "CHxxxxxxxxxxxxxxxxxxx/MBxxxxxxxxxxxxxxxxxx"
~ messaging_binding_address = "Twilio Phone Number 1" -> "Twilio Phone Number 2"
# (8 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Changes to Outputs:
~ add_user_01_to_conversation = {
~ messaging_binding_address = "Twilio Phone Number 1" -> "Twilio Phone Number 2"
# (13 unchanged elements hidden)
}
Thank you @RJPearson94, fantastic explanation! Very much appreciated!!
I'm circling back with the conversations API team to help determine the best path forward.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Checklist
When running the
terraform apply
you will receive the following error; however, the error is not correct. Meaning, the demo works as expected.