Skip to content

Commit

Permalink
azurerm_eventhub_namespace_disaster_recovery_config: fixing breakin…
Browse files Browse the repository at this point in the history
…g pair logic (#19030)
  • Loading branch information
xiaxyi authored Oct 31, 2022
1 parent 495507f commit d8181e5
Showing 1 changed file with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,30 @@ func resourceEventHubNamespaceDisasterRecoveryConfigUpdate(d *pluginsdk.Resource
locks.ByName(id.NamespaceName, eventHubNamespaceResourceName)
defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceResourceName)

if d.HasChange("partner_namespace_id") {
pairingStatus, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("checking the status of eventhub disaster recovery error: %+v", err)
}

// need to check if DCR needs pair-breaking first
breakPairFirst := false
if model := pairingStatus.Model; model != nil {
if model.Properties != nil {
if model.Properties.PartnerNamespace != nil && *model.Properties.PartnerNamespace != "" {
breakPairFirst = true
}
}
}

if d.HasChange("partner_namespace_id") && breakPairFirst {
// break pairing
if _, err := client.BreakPairing(ctx, *id); err != nil {
return fmt.Errorf("breaking the pairing for %s: %+v", *id, err)
}
}

if err := resourceEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, *id); err != nil {
return fmt.Errorf("waiting for the pairing to be broken for %s: %+v", *id, err)
}
if err := resourceEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, *id); err != nil {
return fmt.Errorf("waiting for the pairing to be broken for %s: %+v", *id, err)
}

parameters := disasterrecoveryconfigs.ArmDisasterRecovery{
Expand Down Expand Up @@ -194,12 +209,28 @@ func resourceEventHubNamespaceDisasterRecoveryConfigDelete(d *pluginsdk.Resource
locks.ByName(id.NamespaceName, eventHubNamespaceResourceName)
defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceResourceName)

if _, err := client.BreakPairing(ctx, *id); err != nil {
return fmt.Errorf("breaking pairing of %s: %+v", *id, err)
pairingStatus, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("checking the status of eventhub disaster recovery error: %+v", err)
}

if err := resourceEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, *id); err != nil {
return fmt.Errorf("waiting for pairing to break for %s: %+v", *id, err)
// need to check if DCR needs pair-breaking first
breakPairFirst := false
if model := pairingStatus.Model; model != nil {
if model.Properties != nil {
if model.Properties.PartnerNamespace != nil && *model.Properties.PartnerNamespace != "" {
breakPairFirst = true
}
}
}

if breakPairFirst {
if _, err := client.BreakPairing(ctx, *id); err != nil {
return fmt.Errorf("breaking pairing of %s: %+v", *id, err)
}
if err := resourceEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, *id); err != nil {
return fmt.Errorf("waiting for pairing to break for %s: %+v", *id, err)
}
}

if _, err := client.Delete(ctx, *id); err != nil {
Expand Down

0 comments on commit d8181e5

Please sign in to comment.