Skip to content

Commit

Permalink
azurerm_management_group_subscription_association - correctly mark …
Browse files Browse the repository at this point in the history
…as gone if not found during read (#23335)

* fix read

* fix
  • Loading branch information
teowa authored Sep 21, 2023
1 parent d9383de commit 1f0865c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-01/managementgroups" // nolint: staticcheck
Expand Down Expand Up @@ -87,7 +88,7 @@ func resourceManagementGroupSubscriptionAssociationCreate(d *pluginsdk.ResourceD

if props.Children != nil {
for _, v := range *props.Children {
if v.Type == managementgroups.Type1Subscriptions && v.Name != nil && *v.Name == id.SubscriptionId {
if v.Type == managementgroups.Type1Subscriptions && v.Name != nil && strings.EqualFold(*v.Name, id.SubscriptionId) {
return tf.ImportAsExistsError("azurerm_management_group_subscription_association", id.ID())
}
}
Expand Down Expand Up @@ -119,13 +120,9 @@ func resourceManagementGroupSubscriptionAssociationRead(d *pluginsdk.ResourceDat
}
found := false
if props := managementGroup.Properties; props != nil {
if props.Children == nil {
return fmt.Errorf("could not read properties for Management Group %q", id.ManagementGroup)
}

for _, v := range *props.Children {
if v.Type == managementgroups.Type1Subscriptions {
if v.Name != nil && *v.Name == id.SubscriptionId {
if props.Children != nil {
for _, v := range *props.Children {
if v.Type == managementgroups.Type1Subscriptions && v.Name != nil && strings.EqualFold(*v.Name, id.SubscriptionId) {
found = true
}
}
Expand Down Expand Up @@ -196,7 +193,7 @@ func subscriptionAssociationRefreshFunc(ctx context.Context, client *managementg
if props := managementGroup.Properties; props != nil && props.Children != nil {
for _, v := range *props.Children {
if v.Type == managementgroups.Type1Subscriptions {
if v.Name != nil && *v.Name == id.SubscriptionId {
if v.Name != nil && strings.EqualFold(*v.Name, id.SubscriptionId) {
return managementGroup, "Exists", nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"os"
"strings"
"testing"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-01/managementgroups" // nolint: staticcheck
Expand Down Expand Up @@ -124,7 +125,7 @@ func (r ManagementGroupSubscriptionAssociation) Exists(ctx context.Context, clie

present := false
for _, v := range *resp.Children {
if v.Type == managementgroups.Type1Subscriptions && v.Name != nil && *v.Name == id.SubscriptionId {
if v.Type == managementgroups.Type1Subscriptions && v.Name != nil && strings.EqualFold(*v.Name, id.SubscriptionId) {
present = true
}
}
Expand Down

0 comments on commit 1f0865c

Please sign in to comment.