Skip to content

Commit

Permalink
use mutex to only operate on one reosurce at a time (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
skarimo authored Mar 11, 2021
1 parent 06bd141 commit 75d9b95
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions datadog/resource_datadog_integration_slack_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package datadog

import (
"fmt"
"sync"

"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"

datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

// creating/modifying/deleting Slack Channel integration in parallel on one account
// is unsupported by the API right now; therefore we use the mutex to only operate on one at a time
var integrationSlackChannelMutex = sync.Mutex{}

func resourceDatadogIntegrationSlackChannel() *schema.Resource {
return &schema.Resource{
Description: "Resource for interacting with the Datadog Slack channel API",
Expand Down Expand Up @@ -94,6 +100,9 @@ func resourceDatadogIntegrationSlackChannelCreate(d *schema.ResourceData, meta i
datadogClient := providerConf.DatadogClientV1
auth := providerConf.AuthV1

integrationSlackChannelMutex.Lock()
defer integrationSlackChannelMutex.Unlock()

ddSlackChannel, err := buildDatadogSlackChannel(d)
accountName := d.Get("account_name").(string)

Expand Down Expand Up @@ -133,6 +142,9 @@ func resourceDatadogIntegrationSlackChannelUpdate(d *schema.ResourceData, meta i
datadogClient := providerConf.DatadogClientV1
auth := providerConf.AuthV1

integrationSlackChannelMutex.Lock()
defer integrationSlackChannelMutex.Unlock()

ddObject, err := buildDatadogSlackChannel(d)
accountName, channelName, err := utils.AccountNameAndChannelNameFromID(d.Id())
if err != nil {
Expand All @@ -155,6 +167,9 @@ func resourceDatadogIntegrationSlackChannelDelete(d *schema.ResourceData, meta i
datadogClient := providerConf.DatadogClientV1
auth := providerConf.AuthV1

integrationSlackChannelMutex.Lock()
defer integrationSlackChannelMutex.Unlock()

accountName, channelName, err := utils.AccountNameAndChannelNameFromID(d.Id())
if err != nil {
return err
Expand Down

0 comments on commit 75d9b95

Please sign in to comment.