Skip to content

Commit

Permalink
fix: use the response when creating or updating a studio flow to miti…
Browse files Browse the repository at this point in the history
…gate an eventual consistency issue which cause the provider to panic
  • Loading branch information
RJPearson94 committed Oct 29, 2023
1 parent 6f9f186 commit 101cb1e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.26.1 (2023-10-29)

FIXES

- Change `twilio_studio_flow` resource to use the output of the create and update functions instead of re-fetching the data to mitigate an eventual consistency issue which cause the provider to panic. Detailed decription can be found at https://github.com/RJPearson94/terraform-provider-twilio/issues/86#issuecomment-1784152926

# v0.26.0 (2023-10-23)

BREAKING CHANGES
Expand Down
51 changes: 48 additions & 3 deletions twilio/internal/services/studio/resource_studio_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,30 @@ func resourceStudioFlowCreate(ctx context.Context, d *schema.ResourceData, meta
}

d.SetId(createResult.Sid)
return resourceStudioFlowRead(ctx, d, meta)

// This is a duplicate of resourceStudioFlowRead as the API is eventually consistent and was causing issues with the provider
d.Set("sid", createResult.Sid)
d.Set("account_sid", createResult.AccountSid)
d.Set("friendly_name", createResult.FriendlyName)

json, err := structure.FlattenJsonToString(createResult.Definition)
if err != nil {
return diag.Errorf("Unable to flatten definition json to string")
}
d.Set("definition", json)
d.Set("status", createResult.Status)
d.Set("revision", createResult.Revision)
d.Set("commit_message", createResult.CommitMessage)
d.Set("valid", createResult.Valid)
d.Set("date_created", createResult.DateCreated.Format(time.RFC3339))

if createResult.DateUpdated != nil {
d.Set("date_updated", createResult.DateUpdated.Format(time.RFC3339))
}

d.Set("url", createResult.URL)
d.Set("webhook_url", createResult.WebhookURL)
return nil
}

func resourceStudioFlowRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down Expand Up @@ -171,7 +194,6 @@ func resourceStudioFlowRead(ctx context.Context, d *schema.ResourceData, meta in

d.Set("url", getResponse.URL)
d.Set("webhook_url", getResponse.WebhookURL)

return nil
}

Expand All @@ -195,7 +217,30 @@ func resourceStudioFlowUpdate(ctx context.Context, d *schema.ResourceData, meta
}

d.SetId(updateResp.Sid)
return resourceStudioFlowRead(ctx, d, meta)

// This is a duplicate of resourceStudioFlowRead as the API is eventually consistent and was causing issues with the provider
d.Set("sid", updateResp.Sid)
d.Set("account_sid", updateResp.AccountSid)
d.Set("friendly_name", updateResp.FriendlyName)

json, err := structure.FlattenJsonToString(updateResp.Definition)
if err != nil {
return diag.Errorf("Unable to flatten definition json to string")
}
d.Set("definition", json)
d.Set("status", updateResp.Status)
d.Set("revision", updateResp.Revision)
d.Set("commit_message", updateResp.CommitMessage)
d.Set("valid", updateResp.Valid)
d.Set("date_created", updateResp.DateCreated.Format(time.RFC3339))

if updateResp.DateUpdated != nil {
d.Set("date_updated", updateResp.DateUpdated.Format(time.RFC3339))
}

d.Set("url", updateResp.URL)
d.Set("webhook_url", updateResp.WebhookURL)
return nil
}

func resourceStudioFlowDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down

0 comments on commit 101cb1e

Please sign in to comment.