Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure resource state when duplicate tenants are present #1255

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions datadog/resource_datadog_integration_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package datadog
import (
"context"
"fmt"
"sync"

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

Expand All @@ -11,6 +12,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var integrationAzureMutex = sync.Mutex{}

func resourceDatadogIntegrationAzure() *schema.Resource {
return &schema.Resource{
Description: "Provides a Datadog - Microsoft Azure integration resource. This can be used to create and manage the integrations.",
Expand Down Expand Up @@ -53,7 +56,7 @@ func resourceDatadogIntegrationAzureRead(ctx context.Context, d *schema.Resource
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

tenantName, _, err := utils.TenantAndClientFromID(d.Id())
tenantName, clientId, err := utils.TenantAndClientFromID(d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -66,7 +69,7 @@ func resourceDatadogIntegrationAzureRead(ctx context.Context, d *schema.Resource
return diag.FromErr(err)
}
for _, integration := range integrations {
if integration.GetTenantName() == tenantName {
if integration.GetTenantName() == tenantName && integration.GetClientId() == clientId {
d.Set("tenant_name", integration.GetTenantName())
d.Set("client_id", integration.GetClientId())
hostFilters, exists := integration.GetHostFiltersOk()
Expand All @@ -84,6 +87,9 @@ func resourceDatadogIntegrationAzureCreate(ctx context.Context, d *schema.Resour
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

integrationAzureMutex.Lock()
defer integrationAzureMutex.Unlock()

tenantName := d.Get("tenant_name").(string)
clientID := d.Get("client_id").(string)

Expand All @@ -103,6 +109,9 @@ func resourceDatadogIntegrationAzureUpdate(ctx context.Context, d *schema.Resour
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

integrationAzureMutex.Lock()
defer integrationAzureMutex.Unlock()

existingTenantName, existingClientID, err := utils.TenantAndClientFromID(d.Id())
if err != nil {
return diag.FromErr(err)
Expand All @@ -124,6 +133,9 @@ func resourceDatadogIntegrationAzureDelete(ctx context.Context, d *schema.Resour
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

integrationAzureMutex.Lock()
defer integrationAzureMutex.Unlock()

tenantName, clientID, err := utils.TenantAndClientFromID(d.Id())
if err != nil {
return diag.FromErr(err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-06-03T14:53:29.357191+02:00
2021-10-28T16:26:13.057136-04:00
Loading