Skip to content

Commit

Permalink
Merge pull request #24654 from hashicorp/f/updating-service-fabric-ma…
Browse files Browse the repository at this point in the history
…naged-cluster-to-new-base-layer

dependencies: updating to `v0.20240126.1105227` of `github.com/hashicorp/go-azure-sdk`
  • Loading branch information
tombuildsstuff authored Jan 26, 2024
2 parents 7518216 + c44fb6b commit 65cd4ca
Show file tree
Hide file tree
Showing 38 changed files with 1,286 additions and 1,558 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.1
github.com/hashicorp/go-azure-helpers v0.66.1
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240125.1172517
github.com/hashicorp/go-azure-sdk/sdk v0.20240125.1172517
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240126.1105227
github.com/hashicorp/go-azure-sdk/sdk v0.20240126.1105227
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.66.1 h1:SokAckK9hvQ9PZO2TmZY/CGru8KWJ4A7hcRUggHMEus=
github.com/hashicorp/go-azure-helpers v0.66.1/go.mod h1:kJxXrFtJKJdOEqvad8pllAe7dhP4DbN8J6sqFZe47+4=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240125.1172517 h1:rn92aAwo5mMKsTOLxqaKAKKDd4Ghp2u/rxdT/1GVzZQ=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240125.1172517/go.mod h1:h/IYK9S53fPaC20MTcqqfvjmJG5cA4xK8iRcpLY+hvY=
github.com/hashicorp/go-azure-sdk/sdk v0.20240125.1172517 h1:TGsRzbJPEc78A6rk6RDJhFym5LvvNoVacgRnBIrTqfQ=
github.com/hashicorp/go-azure-sdk/sdk v0.20240125.1172517/go.mod h1:6jgkzx26qtPndLSW5u7pKIw4m3iiFiLnHlp7yDQ2Crc=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240126.1105227 h1:r5JUEkrm6D6FxXfbJgRhMPfZnA+25J5md6B0/K0VqEQ=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240126.1105227/go.mod h1:fDIHULaDyn6a7c9uq2MpMcKJMpony6193JYdWf4Jbgs=
github.com/hashicorp/go-azure-sdk/sdk v0.20240126.1105227 h1:Tk57tCWsQWkfeWuabogTCSQEwDR0d+/9t3ld4tI9/Dw=
github.com/hashicorp/go-azure-sdk/sdk v0.20240126.1105227/go.mod h1:6jgkzx26qtPndLSW5u7pKIw4m3iiFiLnHlp7yDQ2Crc=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
4 changes: 3 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
return fmt.Errorf("building clients for ServiceConnector: %+v", err)
}
client.ServiceFabric = serviceFabric.NewClient(o)
client.ServiceFabricManaged = serviceFabricManaged.NewClient(o)
if client.ServiceFabricManaged, err = serviceFabricManaged.NewClient(o); err != nil {
return fmt.Errorf("building clients for ServiceFabricManagedCluster: %+v", err)
}
if client.ServiceNetworking, err = serviceNetworking.NewClient(o); err != nil {
return fmt.Errorf("building clients for ServiceNetworking: %+v", err)
}
Expand Down
24 changes: 16 additions & 8 deletions internal/services/servicefabricmanaged/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package client

import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicefabricmanagedcluster/2021-05-01/managedcluster"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicefabricmanagedcluster/2021-05-01/nodetype"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand All @@ -14,15 +16,21 @@ type Client struct {
NodeTypeClient *nodetype.NodeTypeClient
}

func NewClient(o *common.ClientOptions) *Client {
managedCluster := managedcluster.NewManagedClusterClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&managedCluster.Client, o.ResourceManagerAuthorizer)
func NewClient(o *common.ClientOptions) (*Client, error) {
managedCluster, err := managedcluster.NewManagedClusterClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ManagedCluster client: %+v", err)
}
o.Configure(managedCluster.Client, o.Authorizers.ResourceManager)

nodeType := nodetype.NewNodeTypeClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&nodeType.Client, o.ResourceManagerAuthorizer)
nodeType, err := nodetype.NewNodeTypeClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building NodeType client: %+v", err)
}
o.Configure(nodeType.Client, o.Authorizers.ResourceManager)

return &Client{
ManagedClusterClient: &managedCluster,
NodeTypeClient: &nodeType,
}
ManagedClusterClient: managedCluster,
NodeTypeClient: nodeType,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,8 @@ func (k ClusterResource) Create() sdk.ResourceFunc {
return metadata.ResourceRequiresImport("azurerm_service_fabric_managed_cluster", managedClusterId)
}

resp, err := clusterClient.CreateOrUpdate(ctx, managedClusterId, cluster)
if err != nil {
return fmt.Errorf("while creating cluster %q: %+v", model.Name, err)
}
// Wait for the cluster creation operation to be completed
err = resp.Poller.PollUntilDone()
if err != nil {
return fmt.Errorf("while waiting for cluster %q to get created: : %+v", model.Name, err)
if err := clusterClient.CreateOrUpdateThenPoll(ctx, managedClusterId, cluster); err != nil {
return fmt.Errorf("creating %s: %+v", managedClusterId, err)
}

toDelete := make([]string, 0)
Expand Down Expand Up @@ -309,68 +303,27 @@ func (k ClusterResource) Create() sdk.ResourceFunc {
}
}

deleteResponses := make([]nodetype.DeleteOperationResponse, 0)
// Delete the old nodetypes
for _, nt := range toDelete {
resp, err := nodeTypeClient.Delete(ctx, nodetype.NewNodeTypeID(subscriptionId, model.ResourceGroup, model.Name, nt))
if err != nil {
return fmt.Errorf("while deleting node type %q of cluster %q: %+v", nt, model.Name, err)
}

if resp.HttpResponse != nil {
deleteResponses = append(deleteResponses, resp)
// Delete the old Node Types
for _, nodeType := range toDelete {
nodeTypeId := nodetype.NewNodeTypeID(subscriptionId, model.ResourceGroup, model.Name, nodeType)
if err := nodeTypeClient.DeleteThenPoll(ctx, nodeTypeId); err != nil {
return fmt.Errorf("deleting %s: %+v", nodeTypeId, err)
}
}

if len(deleteResponses) > 0 {
lastResp := deleteResponses[len(model.NodeTypes)-1]
if err = lastResp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for deletion of node type %q in cluster %q: %+v", model.NodeTypes[len(model.NodeTypes)-1].Name, model.Name, err)
}

for idx, resp := range deleteResponses {
if idx == len(deleteResponses)-1 {
continue
}
if err = resp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for deletion of node type %q in cluster %q: %+v", model.NodeTypes[idx].Name, model.Name, err)
}
}
}

// Send all Create NodeType requests, and store all responses to a list.
nodeTypeResponses := make([]nodetype.CreateOrUpdateOperationResponse, len(model.NodeTypes))
for idx, nt := range model.NodeTypes {
// Then provision the Node Types
for _, nt := range model.NodeTypes {
nodeTypeProperties, err := expandNodeTypeProperties(&nt)
if err != nil {
return fmt.Errorf("while expanding node type %q: %+v", nt.Name, err)
}

nodeTypeId := nodetype.NewNodeTypeID(subscriptionId, model.ResourceGroup, model.Name, nt.Name)
nodeTypeInput := nodetype.NodeType{
Name: nil,
payload := nodetype.NodeType{
Properties: nodeTypeProperties,
}

if resp, err := nodeTypeClient.CreateOrUpdate(ctx, nodeTypeId, nodeTypeInput); err == nil {
nodeTypeResponses[idx] = resp
} else {
return fmt.Errorf("while adding node type %q to cluster %q: %+v", nt.Name, model.Name, err)
}
}

if len(nodeTypeResponses) > 0 {
lastResp := nodeTypeResponses[len(model.NodeTypes)-1]
if err = lastResp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for node type %q in cluster %q: %+v", model.NodeTypes[len(model.NodeTypes)-1].Name, model.Name, err)
}

for idx, resp := range nodeTypeResponses {
if idx == len(nodeTypeResponses)-1 {
continue
}
if err = resp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for node type %q in cluster %q: %+v", model.NodeTypes[idx].Name, model.Name, err)
}
if err := nodeTypeClient.CreateOrUpdateThenPoll(ctx, nodeTypeId, payload); err != nil {
return fmt.Errorf("adding %s: %+v", nodeTypeId, err)
}
}

Expand All @@ -385,34 +338,35 @@ func (k ClusterResource) Create() sdk.ResourceFunc {
func (k ClusterResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
resourceId, err := managedcluster.ParseManagedClusterID(metadata.ResourceData.Id())
if err != nil {
return fmt.Errorf("while parsing resourceID: %+v", err)
}
clusterClient := metadata.Client.ServiceFabricManaged.ManagedClusterClient
nodeTypeClient := metadata.Client.ServiceFabricManaged.NodeTypeClient

cluster, err := clusterClient.Get(ctx, *resourceId)
id, err := managedcluster.ParseManagedClusterID(metadata.ResourceData.Id())
if err != nil {
return err
}

cluster, err := clusterClient.Get(ctx, *id)
if err != nil {
if response.WasNotFound(cluster.HttpResponse) {
return metadata.MarkAsGone(resourceId)
return metadata.MarkAsGone(id)
}
return fmt.Errorf("while reading data for cluster %q: %+v", resourceId.ManagedClusterName, err)
return fmt.Errorf("while reading data for cluster %q: %+v", id.ManagedClusterName, err)
}

nts, err := nodeTypeClient.ListByManagedClustersComplete(ctx, nodetype.ManagedClusterId{
SubscriptionId: resourceId.SubscriptionId,
ResourceGroupName: resourceId.ResourceGroupName,
ManagedClusterName: resourceId.ManagedClusterName,
SubscriptionId: id.SubscriptionId,
ResourceGroupName: id.ResourceGroupName,
ManagedClusterName: id.ManagedClusterName,
})
if err != nil {
return fmt.Errorf("while listing NodeTypes for cluster %q: +%v", resourceId.ManagedClusterName, err)
return fmt.Errorf("while listing NodeTypes for cluster %q: +%v", id.ManagedClusterName, err)
}

model := flattenClusterProperties(cluster.Model)
// Password is read-only
model.Password = metadata.ResourceData.Get("password").(string)
model.ResourceGroup = resourceId.ResourceGroupName
model.ResourceGroup = id.ResourceGroupName
model.NodeTypes = make([]NodeType, 0)
for _, nt := range nts.Items {
provState := nt.Properties.ProvisioningState
Expand All @@ -438,14 +392,18 @@ func (k ClusterResource) Update() sdk.ResourceFunc {
clusterClient := metadata.Client.ServiceFabricManaged.ManagedClusterClient
nodeTypeClient := metadata.Client.ServiceFabricManaged.NodeTypeClient

subscriptionId := metadata.Client.Account.SubscriptionId
id, err := managedcluster.ParseManagedClusterID(metadata.ResourceData.Id())
if err != nil {
return err
}

managedClusterId := managedcluster.NewManagedClusterID(subscriptionId, model.ResourceGroup, model.Name)
cluster := managedcluster.ManagedCluster{
Location: model.Location,
Name: utils.String(model.Name),
Properties: expandClusterProperties(&model),
Sku: &managedcluster.Sku{Name: model.Sku},
Sku: &managedcluster.Sku{
Name: model.Sku,
},
}

tagsMap := make(map[string]string)
Expand All @@ -454,14 +412,8 @@ func (k ClusterResource) Update() sdk.ResourceFunc {
}
cluster.Tags = &tagsMap

resp, err := clusterClient.CreateOrUpdate(ctx, managedClusterId, cluster)
if err != nil {
return fmt.Errorf("while creating cluster %q: %+v", model.Name, err)
}
// Wait for the cluster creation operation to be completed
err = resp.Poller.PollUntilDone()
if err != nil {
return fmt.Errorf("while waiting for cluster %q to get created: : %+v", model.Name, err)
if err := clusterClient.CreateOrUpdateThenPoll(ctx, *id, cluster); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

toDelete := make([]string, 0)
Expand Down Expand Up @@ -489,68 +441,27 @@ func (k ClusterResource) Update() sdk.ResourceFunc {
}
}

deleteResponses := make([]nodetype.DeleteOperationResponse, 0)
// Delete the old nodetypes
for _, nt := range toDelete {
resp, err := nodeTypeClient.Delete(ctx, nodetype.NewNodeTypeID(subscriptionId, model.ResourceGroup, model.Name, nt))
if err != nil {
return fmt.Errorf("while deleting node type %q of cluster %q: %+v", nt, model.Name, err)
}
// Delete the old Node Types
for _, nodeType := range toDelete {
nodeTypeId := nodetype.NewNodeTypeID(id.SubscriptionId, id.ResourceGroupName, id.ManagedClusterName, nodeType)

if resp.HttpResponse != nil {
deleteResponses = append(deleteResponses, resp)
if err := nodeTypeClient.DeleteThenPoll(ctx, nodeTypeId); err != nil {
return fmt.Errorf("deleting %s: %+v", nodeTypeId, err)
}
}

if len(deleteResponses) > 0 {
lastResp := deleteResponses[len(model.NodeTypes)-1]
if err = lastResp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for deletion of node type %q in cluster %q: %+v", model.NodeTypes[len(model.NodeTypes)-1].Name, model.Name, err)
}

for idx, resp := range deleteResponses {
if idx == len(deleteResponses)-1 {
continue
}
if err = resp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for deletion of node type %q in cluster %q: %+v", model.NodeTypes[idx].Name, model.Name, err)
}
}
}

// Send all Create NodeType requests, and store all responses to a list.
nodeTypeResponses := make([]nodetype.CreateOrUpdateOperationResponse, len(model.NodeTypes))
for idx, nt := range model.NodeTypes {
nodeTypeProperties, err := expandNodeTypeProperties(&nt)
// Ensure the remaining Node Types are up-to-date
for _, nodeType := range model.NodeTypes {
props, err := expandNodeTypeProperties(&nodeType)
if err != nil {
return fmt.Errorf("while expanding node type %q: %+v", nt.Name, err)
}
nodeTypeId := nodetype.NewNodeTypeID(subscriptionId, model.ResourceGroup, model.Name, nt.Name)
nodeTypeInput := nodetype.NodeType{
Name: nil,
Properties: nodeTypeProperties,
return fmt.Errorf("while expanding node type %q: %+v", nodeType.Name, err)
}

if resp, err := nodeTypeClient.CreateOrUpdate(ctx, nodeTypeId, nodeTypeInput); err == nil {
nodeTypeResponses[idx] = resp
} else {
return fmt.Errorf("while adding node type %q to cluster %q: %+v", nt.Name, model.Name, err)
}
}

if len(nodeTypeResponses) > 0 {
lastResp := nodeTypeResponses[len(model.NodeTypes)-1]
if err = lastResp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for node type %q in cluster %q: %+v", model.NodeTypes[len(model.NodeTypes)-1].Name, model.Name, err)
nodeTypeId := nodetype.NewNodeTypeID(id.SubscriptionId, id.ResourceGroupName, id.ManagedClusterName, nodeType.Name)
payload := nodetype.NodeType{
Properties: props,
}

for idx, resp := range nodeTypeResponses {
if idx == len(nodeTypeResponses)-1 {
continue
}
if err = resp.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("while polling for node type %q in cluster %q: %+v", model.NodeTypes[idx].Name, model.Name, err)
}
if err := nodeTypeClient.CreateOrUpdateThenPoll(ctx, nodeTypeId, payload); err != nil {
return fmt.Errorf("adding/updating %s: %+v", nodeTypeId, err)
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 65cd4ca

Please sign in to comment.