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

hdinsight: refactoring to use hashicorp/go-azure-sdk #24011

Merged
merged 25 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db7d7c4
hdinsight: registering the metaclient from `hashicorp/go-azure-sdk`
tombuildsstuff Nov 23, 2023
43f7ec0
go mod vendor
tombuildsstuff Nov 23, 2023
2910edb
hdinsight: registering the metaclient
tombuildsstuff Nov 23, 2023
072ae85
hdinsight: switching Applications over to use `hashicorp/go-azure-sdk`
tombuildsstuff Nov 23, 2023
15ca750
hdinsight: refactoring `Configurations` over to `hashicorp/go-azure-sdk`
tombuildsstuff Nov 23, 2023
dd86398
hdinsight: refactoring `Extensions` to use `hashicorp/go-azure-sdk`
tombuildsstuff Nov 23, 2023
7ad62a2
hdinsight: refactoring the `ClustersClient` to use `hashicorp/go-azur…
tombuildsstuff Nov 23, 2023
3c85054
hdinsight: removing the old Resource ID type
tombuildsstuff Nov 23, 2023
9efa2a1
hdinsight: removing the local client in favour of the meta client
tombuildsstuff Nov 23, 2023
132d01b
hdinsight: linting
tombuildsstuff Nov 23, 2023
8b9732c
`hdinsight`: `go mod vendor` to remove the old HDInsight SDK
tombuildsstuff Nov 23, 2023
fa322a2
d/hdinsight_cluster: fixing an issue where the `tier` and `kind` were…
tombuildsstuff Nov 24, 2023
262fa65
nit: keeping the linter happy
tombuildsstuff Nov 24, 2023
8caaea6
vendoring the updated sdk
tombuildsstuff Nov 29, 2023
04be29e
hdinsight: updating now that `Kind` is available as a Constant
tombuildsstuff Nov 29, 2023
6d6762f
r/hdinsight_hadoop_cluster: fixing the path to the script
Dec 14, 2023
23b9b35
`hdinsight`: `network` is now always written to the state
Dec 14, 2023
2c28c48
`hdinsight`: `disk_encryption` is now always written to the state
Dec 14, 2023
d588dcc
`hdinsight`: `compute_isolation` is now always written to the state
Dec 14, 2023
e12a1cd
`hdinsight`: moving the GETs up to be consistent with other resources
Dec 14, 2023
a65eaa0
`hdinsight`: refactoring the edge node configuration to load the unin…
Dec 14, 2023
3a219c6
`hdinsight`: updating the vendor
Dec 14, 2023
cefecd8
`hdinsight`: updating to use the Common ID for HDInsight Cluster
Dec 14, 2023
9cfbece
`hdinsight`: linting
Dec 14, 2023
76328c4
`go mod vendor`
tombuildsstuff Jan 25, 2024
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
7 changes: 5 additions & 2 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01"
eventgrid_v2022_06_15 "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2022-06-15"
fluidrelay_2022_05_26 "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26"
hdinsight_v2021_06_01 "github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01"
nginx_2023_09_01 "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2023-09-01"
redis_2023_08_01 "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2023-08-01"
servicenetworking_v2023_05_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-05-01-preview"
Expand Down Expand Up @@ -208,7 +209,7 @@ type Client struct {
Frontdoor *frontdoor.Client
Graph *graph.Client
HSM *hsm.Client
HDInsight *hdinsight.Client
HDInsight *hdinsight_v2021_06_01.Client
HybridCompute *hybridcompute.Client
HealthCare *healthcare.Client
IoTCentral *iotcentral.Client
Expand Down Expand Up @@ -444,7 +445,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
if client.HSM, err = hsm.NewClient(o); err != nil {
return fmt.Errorf("building clients for HSM: %+v", err)
}
client.HDInsight = hdinsight.NewClient(o)
if client.HDInsight, err = hdinsight.NewClient(o); err != nil {
return fmt.Errorf("building clients for HDInsight: %+v", err)
}
if client.HealthCare, err = healthcare.NewClient(o); err != nil {
return fmt.Errorf("building clients for HealthCare: %+v", err)
}
Expand Down
40 changes: 8 additions & 32 deletions internal/services/hdinsight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,16 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/hdinsight/mgmt/2018-06-01/hdinsight" // nolint: staticcheck
hdinsight_v2021_06_01 "github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
ApplicationsClient *hdinsight.ApplicationsClient
ClustersClient *hdinsight.ClustersClient
ConfigurationsClient *hdinsight.ConfigurationsClient
ExtensionsClient *hdinsight.ExtensionsClient
}

func NewClient(o *common.ClientOptions) *Client {
// due to a bug in the HDInsight API we can't reuse client with the same x-ms-correlation-request-id for multiple updates
opts := *o
opts.DisableCorrelationRequestID = true

ApplicationsClient := hdinsight.NewApplicationsClientWithBaseURI(opts.ResourceManagerEndpoint, opts.SubscriptionId)
opts.ConfigureClient(&ApplicationsClient.Client, opts.ResourceManagerAuthorizer)

ClustersClient := hdinsight.NewClustersClientWithBaseURI(opts.ResourceManagerEndpoint, opts.SubscriptionId)
opts.ConfigureClient(&ClustersClient.Client, opts.ResourceManagerAuthorizer)

ConfigurationsClient := hdinsight.NewConfigurationsClientWithBaseURI(opts.ResourceManagerEndpoint, opts.SubscriptionId)
opts.ConfigureClient(&ConfigurationsClient.Client, opts.ResourceManagerAuthorizer)

ExtensionsClient := hdinsight.NewExtensionsClientWithBaseURI(opts.ResourceManagerEndpoint, opts.SubscriptionId)
opts.ConfigureClient(&ExtensionsClient.Client, opts.ResourceManagerAuthorizer)

c := &Client{
ApplicationsClient: &ApplicationsClient,
ClustersClient: &ClustersClient,
ConfigurationsClient: &ConfigurationsClient,
ExtensionsClient: &ExtensionsClient,
}
func NewClient(o *common.ClientOptions) (*hdinsight_v2021_06_01.Client, error) {
return hdinsight_v2021_06_01.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)

return c
// due to a bug in the HDInsight API we can't reuse client with the same x-ms-correlation-request-id for multiple updates
c.CorrelationId = ""
})
}
275 changes: 116 additions & 159 deletions internal/services/hdinsight/common_hdinsight.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package custompollers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/extensions"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &DisableAzureMonitorPoller{}

// DisableAzureMonitorPoller polls until the Azure Monitor for the specified HDInsight Cluster has been disabled
// This works around an issue outlined in https://github.com/hashicorp/go-azure-sdk/issues/518 where the API
// is a LRO which doesn't use `provisioningState`.
type DisableAzureMonitorPoller struct {
client *extensions.ExtensionsClient
clusterId commonids.HDInsightClusterId
}

func NewDisableAzureMonitorPoller(client *extensions.ExtensionsClient, clusterId commonids.HDInsightClusterId) *DisableAzureMonitorPoller {
return &DisableAzureMonitorPoller{
client: client,
clusterId: clusterId,
}
}

func (p *DisableAzureMonitorPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.GetMonitoringStatus(ctx, p.clusterId)
if err != nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: %+v", p.clusterId, err)
}
if resp.Model == nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: `model` was nil", p.clusterId)
}
if resp.Model.ClusterMonitoringEnabled == nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: `model.ClusterMonitoringEnabled` was nil", p.clusterId)
}

status := pollers.PollingStatusInProgress
if !*resp.Model.ClusterMonitoringEnabled {
status = pollers.PollingStatusSucceeded
}

return &pollers.PollResult{
HttpResponse: &client.Response{
OData: resp.OData,
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: status,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package custompollers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/extensions"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &DisableMonitoringPoller{}

// DisableMonitoringPoller polls until the Monitoring for the specified HDInsight Cluster has been disabled
// This works around an issue outlined in https://github.com/hashicorp/go-azure-sdk/issues/518 where the API
// is a LRO which doesn't use `provisioningState`.
type DisableMonitoringPoller struct {
client *extensions.ExtensionsClient
clusterId commonids.HDInsightClusterId
}

func NewDisableMonitoringPoller(client *extensions.ExtensionsClient, clusterId commonids.HDInsightClusterId) *DisableMonitoringPoller {
return &DisableMonitoringPoller{
client: client,
clusterId: clusterId,
}
}

func (p *DisableMonitoringPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.GetMonitoringStatus(ctx, p.clusterId)
if err != nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: %+v", p.clusterId, err)
}
if resp.Model == nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: `model` was nil", p.clusterId)
}
if resp.Model.ClusterMonitoringEnabled == nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: `model.ClusterMonitoringEnabled` was nil", p.clusterId)
}

status := pollers.PollingStatusInProgress
if !*resp.Model.ClusterMonitoringEnabled {
status = pollers.PollingStatusSucceeded
}

return &pollers.PollResult{
HttpResponse: &client.Response{
OData: resp.OData,
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: status,
}, nil
}
68 changes: 68 additions & 0 deletions internal/services/hdinsight/custompollers/edge_node_poller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package custompollers

import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/clusters"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &EdgeNodePoller{}

// EdgeNodePoller polls until the Edge Nodes have finished provisioning
type EdgeNodePoller struct {
client *clusters.ClustersClient
clusterId commonids.HDInsightClusterId
}

func NewEdgeNodePoller(client *clusters.ClustersClient, clusterId commonids.HDInsightClusterId) *EdgeNodePoller {
return &EdgeNodePoller{
client: client,
clusterId: clusterId,
}
}

func (p *EdgeNodePoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.Get(ctx, p.clusterId)
if err != nil {
return nil, fmt.Errorf("retrieving %s: %+v", p.clusterId, err)
}

clusterState := ""
if model := resp.Model; model != nil && model.Properties != nil {
clusterState = pointer.From(model.Properties.ClusterState)
}

if strings.EqualFold(clusterState, "Running") {
return &pollers.PollResult{
HttpResponse: &client.Response{
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: pollers.PollingStatusSucceeded,
}, nil
}

if strings.EqualFold(clusterState, "AzureVMConfiguration") || strings.EqualFold(clusterState, "Accepted") || strings.EqualFold(clusterState, "HdInsightConfiguration") {
return &pollers.PollResult{
HttpResponse: &client.Response{
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: pollers.PollingStatusInProgress,
}, nil
}

return nil, pollers.PollingFailedError{
HttpResponse: &client.Response{
Response: resp.HttpResponse,
},
Message: fmt.Sprintf("unexpected clusterState %q", clusterState),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package custompollers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/extensions"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &EnableAzureMonitorPoller{}

// EnableAzureMonitorPoller polls until the Azure Monitor for the specified HDInsight Cluster has been enabled
// This works around an issue outlined in https://github.com/hashicorp/go-azure-sdk/issues/518 where the API
// is a LRO which doesn't use `provisioningState`.
type EnableAzureMonitorPoller struct {
client *extensions.ExtensionsClient
clusterId commonids.HDInsightClusterId
}

func NewEnableAzureMonitorPoller(client *extensions.ExtensionsClient, clusterId commonids.HDInsightClusterId) *EnableAzureMonitorPoller {
return &EnableAzureMonitorPoller{
client: client,
clusterId: clusterId,
}
}

func (p *EnableAzureMonitorPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.GetAzureMonitorStatus(ctx, p.clusterId)
if err != nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: %+v", p.clusterId, err)
}
if resp.Model == nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: `model` was nil", p.clusterId)
}
if resp.Model.ClusterMonitoringEnabled == nil {
return nil, fmt.Errorf("retrieving Azure Monitor Status for %s: `model.ClusterMonitoringEnabled` was nil", p.clusterId)
}

status := pollers.PollingStatusInProgress
if *resp.Model.ClusterMonitoringEnabled {
status = pollers.PollingStatusSucceeded
}

return &pollers.PollResult{
HttpResponse: &client.Response{
OData: resp.OData,
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: status,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package custompollers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01/extensions"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &EnableMonitoringPoller{}

// EnableMonitoringPoller polls until the Monitoring for the specified HDInsight Cluster has been enabled
// This works around an issue outlined in https://github.com/hashicorp/go-azure-sdk/issues/518 where the API
// is a LRO which doesn't use `provisioningState`.
type EnableMonitoringPoller struct {
client *extensions.ExtensionsClient
clusterId commonids.HDInsightClusterId
}

func NewEnableMonitoringPoller(client *extensions.ExtensionsClient, clusterId commonids.HDInsightClusterId) *EnableMonitoringPoller {
return &EnableMonitoringPoller{
client: client,
clusterId: clusterId,
}
}

func (p *EnableMonitoringPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.GetMonitoringStatus(ctx, p.clusterId)
if err != nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: %+v", p.clusterId, err)
}
if resp.Model == nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: `model` was nil", p.clusterId)
}
if resp.Model.ClusterMonitoringEnabled == nil {
return nil, fmt.Errorf("retrieving Monitoring Status for %s: `model.ClusterMonitoringEnabled` was nil", p.clusterId)
}

status := pollers.PollingStatusInProgress
if *resp.Model.ClusterMonitoringEnabled {
status = pollers.PollingStatusSucceeded
}

return &pollers.PollResult{
HttpResponse: &client.Response{
OData: resp.OData,
Response: resp.HttpResponse,
},
PollInterval: 10 * time.Second,
Status: status,
}, nil
}
Loading
Loading