Skip to content

Commit

Permalink
fix deleting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Dec 12, 2024
1 parent 6b62018 commit b820090
Show file tree
Hide file tree
Showing 76 changed files with 3,274 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
Expand Down Expand Up @@ -350,12 +351,19 @@ func (r ArcKubernetesProvisionedClusterResource) Delete() sdk.ResourceFunc {
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ArcKubernetes.ArcKubernetesClient
provisionedClusterInstanceClient := metadata.Client.ArcKubernetes.ProvisionedClusterInstancesClient

id, err := arckubernetes.ParseConnectedClusterID(metadata.ResourceData.Id())
if err != nil {
return err
}

// workaround for Deleted cluster still visible https://learn.microsoft.com/en-us/azure/aks/hybrid/deleted-cluster-visible#workaround
scopeId := commonids.NewScopeID(id.ID())
if err := provisionedClusterInstanceClient.ProvisionedClusterInstancesDeleteThenPoll(ctx, scopeId); err != nil {
return fmt.Errorf("deleting child Provisioned Cluster Instance: %+v", err)
}

if err := client.ConnectedClusterDeleteThenPoll(ctx, *id); err != nil {
return fmt.Errorf("deleting %s: %+v", id, err)
}
Expand Down
21 changes: 15 additions & 6 deletions internal/services/arckubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/hybridazurekubernetesservice/2024-01-01/provisionedclusterinstances"
"github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2024-01-01/connectedclusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/kubernetesconfiguration/2022-11-01/extensions"
"github.com/hashicorp/go-azure-sdk/resource-manager/kubernetesconfiguration/2022-11-01/fluxconfiguration"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
ArcKubernetesClient *connectedclusters.ConnectedClustersClient
ExtensionsClient *extensions.ExtensionsClient
FluxConfigurationClient *fluxconfiguration.FluxConfigurationClient
ArcKubernetesClient *connectedclusters.ConnectedClustersClient
ExtensionsClient *extensions.ExtensionsClient
FluxConfigurationClient *fluxconfiguration.FluxConfigurationClient
ProvisionedClusterInstancesClient *provisionedclusterinstances.ProvisionedClusterInstancesClient
}

func NewClient(o *common.ClientOptions) (*Client, error) {
Expand All @@ -37,9 +39,16 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(fluxConfigurationClient.Client, o.Authorizers.ResourceManager)

provisionedClusterInstancesClientClient, err := provisionedclusterinstances.NewProvisionedClusterInstancesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ProvisionedClusterInstancesClient client: %+v", err)
}
o.Configure(provisionedClusterInstancesClientClient.Client, o.Authorizers.ResourceManager)

return &Client{
ArcKubernetesClient: arcKubernetesClient,
ExtensionsClient: extensionsClient,
FluxConfigurationClient: fluxConfigurationClient,
ArcKubernetesClient: arcKubernetesClient,
ExtensionsClient: extensionsClient,
FluxConfigurationClient: fluxConfigurationClient,
ProvisionedClusterInstancesClient: provisionedClusterInstancesClientClient,
}, nil
}
Loading

0 comments on commit b820090

Please sign in to comment.