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

resource - fix various tests #27544

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 10 additions & 3 deletions internal/services/resource/resource_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -193,13 +194,16 @@ func resourceResourceGroupDelete(d *pluginsdk.ResourceData, meta interface{}) er
resourceClient := meta.(*clients.Client).Resource.ResourcesClient
// Resource groups sometimes hold on to resource information after the resources have been deleted. We'll retry this check to account for that eventual consistency.
err = pluginsdk.Retry(10*time.Minute, func() *pluginsdk.RetryError {
results, err := resourceClient.ListByResourceGroupComplete(ctx, id.ResourceGroup, "", "provisioningState", utils.Int32(500))
results, err := resourceClient.ListByResourceGroup(ctx, id.ResourceGroup, "", "provisioningState", utils.Int32(500))
if err != nil {
if response.WasNotFound(results.Response().Response.Response) {
return nil
}
return pluginsdk.NonRetryableError(fmt.Errorf("listing resources in %s: %v", *id, err))
}
nestedResourceIds := make([]string, 0)
for results.NotDone() {
val := results.Value()
for _, value := range results.Values() {
val := value
if val.ID != nil {
nestedResourceIds = append(nestedResourceIds, *val.ID)
}
Expand All @@ -222,6 +226,9 @@ func resourceResourceGroupDelete(d *pluginsdk.ResourceData, meta interface{}) er

deleteFuture, err := client.Delete(ctx, id.ResourceGroup, "")
if err != nil {
if strings.Contains(err.Error(), "could not be found") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry should have left a comment here as well, could apply the same check on the Response here like we did above?

return nil
}
return fmt.Errorf("deleting %s: %+v", *id, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type ResourceManagementPrivateLinkAssociationTestResource struct{}
func TestAccResourceManagementPrivateLinkAssociation_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_resource_management_private_link_association", "test")
r := ResourceManagementPrivateLinkAssociationTestResource{}
randomUUID, _ := uuid.GenerateUUID()

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, randomUUID),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -37,15 +38,18 @@ func TestAccResourceManagementPrivateLinkAssociation_basic(t *testing.T) {
func TestAccResourceManagementPrivateLinkAssociation_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_resource_management_private_link_association", "test")
r := ResourceManagementPrivateLinkAssociationTestResource{}
randomUUID, _ := uuid.GenerateUUID()

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, randomUUID),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
data.RequiresImportErrorStep(func(data acceptance.TestData) string {
return r.requiresImport(data, randomUUID)
}),
})
}

Expand Down Expand Up @@ -78,8 +82,7 @@ func (r ResourceManagementPrivateLinkAssociationTestResource) Exists(ctx context
return utils.Bool(resp.Model != nil), nil
}

func (r ResourceManagementPrivateLinkAssociationTestResource) basic(data acceptance.TestData) string {
randomUUID, _ := uuid.GenerateUUID()
func (r ResourceManagementPrivateLinkAssociationTestResource) basic(data acceptance.TestData, uuid string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -93,7 +96,7 @@ resource "azurerm_resource_management_private_link_association" "test" {
resource_management_private_link_id = azurerm_resource_management_private_link.test.id
public_network_access_enabled = true
}
`, r.template(data), randomUUID)
`, r.template(data), uuid)
}

func (r ResourceManagementPrivateLinkAssociationTestResource) generateName(data acceptance.TestData) string {
Expand All @@ -115,7 +118,7 @@ resource "azurerm_resource_management_private_link_association" "test" {
`, r.template(data))
}

func (r ResourceManagementPrivateLinkAssociationTestResource) requiresImport(data acceptance.TestData) string {
func (r ResourceManagementPrivateLinkAssociationTestResource) requiresImport(data acceptance.TestData, uuid string) string {
return fmt.Sprintf(`
%s

Expand All @@ -125,7 +128,7 @@ resource "azurerm_resource_management_private_link_association" "import" {
resource_management_private_link_id = azurerm_resource_management_private_link_association.test.resource_management_private_link_id
public_network_access_enabled = azurerm_resource_management_private_link_association.test.public_network_access_enabled
}
`, r.basic(data))
`, r.basic(data, uuid))
}

func (r ResourceManagementPrivateLinkAssociationTestResource) template(data acceptance.TestData) string {
Expand Down
Loading