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

applicationgateways - update to use hashicorp/go-azure-sdk #25844

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
296 changes: 151 additions & 145 deletions internal/services/network/application_gateway_data_source.go

Large diffs are not rendered by default.

1,709 changes: 796 additions & 913 deletions internal/services/network/application_gateway_resource.go

Large diffs are not rendered by default.

55 changes: 29 additions & 26 deletions internal/services/network/application_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import (
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-07-01/applicationgateways"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network"
)

type ApplicationGatewayResource struct{}
Expand Down Expand Up @@ -1322,17 +1321,17 @@ func TestAccApplicationGateway_removeFirewallPolicy(t *testing.T) {
}

func (t ApplicationGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ApplicationGatewayID(state.ID)
id, err := applicationgateways.ParseApplicationGatewayID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Network.ApplicationGatewaysClient.Get(ctx, id.ResourceGroup, id.Name)
resp, err := clients.Network.ApplicationGatewaysClient.Get(ctx, *id)
if err != nil {
return nil, fmt.Errorf("reading Application Gateway (%s): %+v", id, err)
return nil, fmt.Errorf("retrieving %s: %+v", id, err)
}

return utils.Bool(resp.ID != nil), nil
return pointer.To(resp.Model != nil), nil
}

func (r ApplicationGatewayResource) basic(data acceptance.TestData) string {
Expand Down Expand Up @@ -5094,12 +5093,21 @@ func (ApplicationGatewayResource) changeCert(certificateName string) acceptance.
ctx, cancel := context.WithTimeout(ctx, time.Minute*90)
defer cancel()

gatewayName := state.Attributes["name"]
resourceGroup := state.Attributes["resource_group_name"]
id, err := applicationgateways.ParseApplicationGatewayID(state.Attributes["id"])
if err != nil {
return err
}

agw, err := clients.Network.ApplicationGatewaysClient.Get(ctx, resourceGroup, gatewayName)
agw, err := clients.Network.ApplicationGatewaysClient.Get(ctx, *id)
if err != nil {
return fmt.Errorf("Bad: Get on ApplicationGatewaysClient: %+v", err)
return fmt.Errorf("retrieving %s: %+v", id, err)
}

if agw.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}
if agw.Model.Properties == nil {
return fmt.Errorf("retrieving %s: `properties` was nil", id)
}

certPfx, err := os.ReadFile("testdata/application_gateway_test.pfx")
Expand All @@ -5108,26 +5116,21 @@ func (ApplicationGatewayResource) changeCert(certificateName string) acceptance.
}
certB64 := base64.StdEncoding.EncodeToString(certPfx)

newSslCertificates := make([]network.ApplicationGatewaySslCertificate, 1)
newSslCertificates[0] = network.ApplicationGatewaySslCertificate{
Name: utils.String(certificateName),
Etag: utils.String("*"),
newSslCertificates := make([]applicationgateways.ApplicationGatewaySslCertificate, 1)
newSslCertificates[0] = applicationgateways.ApplicationGatewaySslCertificate{
Name: pointer.To(certificateName),
Etag: pointer.To("*"),

ApplicationGatewaySslCertificatePropertiesFormat: &network.ApplicationGatewaySslCertificatePropertiesFormat{
Data: utils.String(certB64),
Password: utils.String("terraform"),
Properties: &applicationgateways.ApplicationGatewaySslCertificatePropertiesFormat{
Data: pointer.To(certB64),
Password: pointer.To("terraform"),
},
}

agw.SslCertificates = &newSslCertificates

future, err := clients.Network.ApplicationGatewaysClient.CreateOrUpdate(ctx, resourceGroup, gatewayName, agw)
if err != nil {
return fmt.Errorf("Bad: updating AGW: %+v", err)
}
agw.Model.Properties.SslCertificates = &newSslCertificates

if err := future.WaitForCompletionRef(ctx, clients.Network.ApplicationGatewaysClient.Client); err != nil {
return fmt.Errorf("Bad: waiting for update of AGW: %+v", err)
if err := clients.Network.ApplicationGatewaysClient.CreateOrUpdateThenPoll(ctx, *id, *agw.Model); err != nil {
return fmt.Errorf("updating %s: %+v", id, err)
}

return nil
Expand Down
14 changes: 10 additions & 4 deletions internal/services/network/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package client
import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-07-01/applicationgateways"
network_2023_09_01 "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-09-01"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand All @@ -15,9 +16,11 @@ import (
type Client struct {
*network_2023_09_01.Client

// TODO 4.0 application gateways should be updated to use 2023-09-01 just prior to releasing 4.0
ApplicationGatewaysClient *applicationgateways.ApplicationGatewaysClient

// Usages of the clients below use `Azure/azure-sdk-for-go` and should be updated
// to use `hashicorp/go-azure-sdk` (available above).
ApplicationGatewaysClient *network.ApplicationGatewaysClient
CustomIPPrefixesClient *network.CustomIPPrefixesClient
ExpressRouteAuthsClient *network.ExpressRouteCircuitAuthorizationsClient
ExpressRouteCircuitsClient *network.ExpressRouteCircuitsClient
Expand Down Expand Up @@ -58,8 +61,11 @@ type Client struct {
}

func NewClient(o *common.ClientOptions) (*Client, error) {
ApplicationGatewaysClient := network.NewApplicationGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationGatewaysClient.Client, o.ResourceManagerAuthorizer)
ApplicationGatewaysClient, err := applicationgateways.NewApplicationGatewaysClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Application Gateways Client: %+v", err)
}
o.Configure(ApplicationGatewaysClient.Client, o.Authorizers.ResourceManager)

customIpPrefixesClient := network.NewCustomIPPrefixesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&customIpPrefixesClient.Client, o.ResourceManagerAuthorizer)
Expand Down Expand Up @@ -182,7 +188,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
return &Client{
Client: client,

ApplicationGatewaysClient: &ApplicationGatewaysClient,
ApplicationGatewaysClient: ApplicationGatewaysClient,
CustomIPPrefixesClient: &customIpPrefixesClient,
ExpressRouteAuthsClient: &ExpressRouteAuthsClient,
ExpressRouteCircuitsClient: &ExpressRouteCircuitsClient,
Expand Down
Loading
Loading