Skip to content

Commit

Permalink
Merge pull request #22479 from ms-zhenhua/upgrade-ni-api
Browse files Browse the repository at this point in the history
`azurerm_network_interface` - upgrade API from `2022-07-01` to `2023-02-01`
  • Loading branch information
tombuildsstuff authored Jul 25, 2023
2 parents 9810861 + 7138dd6 commit 57fe338
Show file tree
Hide file tree
Showing 142 changed files with 6,158 additions and 290 deletions.
9 changes: 9 additions & 0 deletions internal/services/network/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/securityadminconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/securityrules"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/staticmembers"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-02-01/networkinterfaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network"
)
Expand Down Expand Up @@ -59,6 +60,7 @@ type Client struct {
ManagerSecurityAdminConfigurationsClient *securityadminconfigurations.SecurityAdminConfigurationsClient
ManagerStaticMembersClient *staticmembers.StaticMembersClient
NatRuleClient *network.NatRulesClient
NetworkInterfacesClient *networkinterfaces.NetworkInterfacesClient
PointToSiteVpnGatewaysClient *network.P2sVpnGatewaysClient
ProfileClient *network.ProfilesClient
PacketCapturesClient *network.PacketCapturesClient
Expand Down Expand Up @@ -228,6 +230,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
NatRuleClient := network.NewNatRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&NatRuleClient.Client, o.ResourceManagerAuthorizer)

NetworkInterfacesClient, err := networkinterfaces.NewNetworkInterfacesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building network interface client: %+v", err)
}
o.Configure(NetworkInterfacesClient.Client, o.Authorizers.ResourceManager)

pointToSiteVpnGatewaysClient := network.NewP2sVpnGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&pointToSiteVpnGatewaysClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -385,6 +393,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
ManagerSecurityAdminConfigurationsClient: ManagerSecurityAdminConfigurationsClient,
ManagerStaticMembersClient: ManagerStaticMembersClient,
NatRuleClient: &NatRuleClient,
NetworkInterfacesClient: NetworkInterfacesClient,
PointToSiteVpnGatewaysClient: &pointToSiteVpnGatewaysClient,
ProfileClient: &ProfileClient,
PacketCapturesClient: &PacketCapturesClient,
Expand Down
18 changes: 18 additions & 0 deletions internal/services/network/edge_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ func flattenEdgeZone(input *network.ExtendedLocation) string {
}
return edgezones.NormalizeNilable(input.Name)
}

func expandEdgeZoneModel(input string) *edgezones.Model {
normalized := edgezones.Normalize(input)
if normalized == "" {
return nil
}

return &edgezones.Model{
Name: normalized,
}
}

func flattenEdgeZoneModel(input *edgezones.Model) string {
if input == nil || input.Name == "" {
return ""
}
return edgezones.Normalize(input.Name)
}
68 changes: 32 additions & 36 deletions internal/services/network/network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package network

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-02-01/networkinterfaces"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network"
)

type networkInterfaceUpdateInformation struct {
Expand All @@ -16,10 +16,10 @@ type networkInterfaceUpdateInformation struct {
networkSecurityGroupID string
}

func parseFieldsFromNetworkInterface(input network.InterfacePropertiesFormat) networkInterfaceUpdateInformation {
func parseFieldsFromNetworkInterface(input networkinterfaces.NetworkInterfacePropertiesFormat) networkInterfaceUpdateInformation {
networkSecurityGroupId := ""
if input.NetworkSecurityGroup != nil && input.NetworkSecurityGroup.ID != nil {
networkSecurityGroupId = *input.NetworkSecurityGroup.ID
if input.NetworkSecurityGroup != nil && input.NetworkSecurityGroup.Id != nil {
networkSecurityGroupId = *input.NetworkSecurityGroup.Id
}

mapToSlice := func(input map[string]struct{}) []string {
Expand All @@ -39,39 +39,39 @@ func parseFieldsFromNetworkInterface(input network.InterfacePropertiesFormat) ne

if input.IPConfigurations != nil {
for _, v := range *input.IPConfigurations {
if v.InterfaceIPConfigurationPropertiesFormat == nil {
if v.Properties == nil {
continue
}

props := *v.InterfaceIPConfigurationPropertiesFormat
props := *v.Properties
if props.ApplicationSecurityGroups != nil {
for _, asg := range *props.ApplicationSecurityGroups {
if asg.ID != nil {
applicationSecurityGroupIds[*asg.ID] = struct{}{}
if asg.Id != nil {
applicationSecurityGroupIds[*asg.Id] = struct{}{}
}
}
}

if props.ApplicationGatewayBackendAddressPools != nil {
for _, pool := range *props.ApplicationGatewayBackendAddressPools {
if pool.ID != nil {
applicationGatewayBackendAddressPoolIds[*pool.ID] = struct{}{}
if pool.Id != nil {
applicationGatewayBackendAddressPoolIds[*pool.Id] = struct{}{}
}
}
}

if props.LoadBalancerBackendAddressPools != nil {
for _, pool := range *props.LoadBalancerBackendAddressPools {
if pool.ID != nil {
loadBalancerBackendAddressPoolIds[*pool.ID] = struct{}{}
if pool.Id != nil {
loadBalancerBackendAddressPoolIds[*pool.Id] = struct{}{}
}
}
}

if props.LoadBalancerInboundNatRules != nil {
for _, rule := range *props.LoadBalancerInboundNatRules {
if rule.ID != nil {
loadBalancerInboundNatRuleIds[*rule.ID] = struct{}{}
if rule.Id != nil {
loadBalancerInboundNatRuleIds[*rule.Id] = struct{}{}
}
}
}
Expand All @@ -87,50 +87,46 @@ func parseFieldsFromNetworkInterface(input network.InterfacePropertiesFormat) ne
}
}

func mapFieldsToNetworkInterface(input *[]network.InterfaceIPConfiguration, info networkInterfaceUpdateInformation) *[]network.InterfaceIPConfiguration {
func mapFieldsToNetworkInterface(input *[]networkinterfaces.NetworkInterfaceIPConfiguration, info networkInterfaceUpdateInformation) *[]networkinterfaces.NetworkInterfaceIPConfiguration {
output := input

applicationSecurityGroups := make([]network.ApplicationSecurityGroup, 0)
applicationSecurityGroups := make([]networkinterfaces.ApplicationSecurityGroup, 0)
for _, id := range info.applicationSecurityGroupIDs {
applicationSecurityGroups = append(applicationSecurityGroups, network.ApplicationSecurityGroup{
ID: utils.String(id),
applicationSecurityGroups = append(applicationSecurityGroups, networkinterfaces.ApplicationSecurityGroup{
Id: utils.String(id),
})
}

applicationGatewayBackendAddressPools := make([]network.ApplicationGatewayBackendAddressPool, 0)
applicationGatewayBackendAddressPools := make([]networkinterfaces.ApplicationGatewayBackendAddressPool, 0)
for _, id := range info.applicationGatewayBackendAddressPoolIDs {
applicationGatewayBackendAddressPools = append(applicationGatewayBackendAddressPools, network.ApplicationGatewayBackendAddressPool{
ID: utils.String(id),
applicationGatewayBackendAddressPools = append(applicationGatewayBackendAddressPools, networkinterfaces.ApplicationGatewayBackendAddressPool{
Id: utils.String(id),
})
}

loadBalancerBackendAddressPools := make([]network.BackendAddressPool, 0)
loadBalancerBackendAddressPools := make([]networkinterfaces.BackendAddressPool, 0)
for _, id := range info.loadBalancerBackendAddressPoolIDs {
loadBalancerBackendAddressPools = append(loadBalancerBackendAddressPools, network.BackendAddressPool{
ID: utils.String(id),
loadBalancerBackendAddressPools = append(loadBalancerBackendAddressPools, networkinterfaces.BackendAddressPool{
Id: utils.String(id),
})
}

loadBalancerInboundNatRules := make([]network.InboundNatRule, 0)
loadBalancerInboundNatRules := make([]networkinterfaces.InboundNatRule, 0)
for _, id := range info.loadBalancerInboundNatRuleIDs {
loadBalancerInboundNatRules = append(loadBalancerInboundNatRules, network.InboundNatRule{
ID: utils.String(id),
loadBalancerInboundNatRules = append(loadBalancerInboundNatRules, networkinterfaces.InboundNatRule{
Id: utils.String(id),
})
}

for _, config := range *output {
if config.InterfaceIPConfigurationPropertiesFormat == nil {
if config.Properties == nil || config.Properties.PrivateIPAddressVersion == nil || *config.Properties.PrivateIPAddressVersion != networkinterfaces.IPVersionIPvFour {
continue
}

if config.InterfaceIPConfigurationPropertiesFormat.PrivateIPAddressVersion != network.IPVersionIPv4 {
continue
}

config.ApplicationSecurityGroups = &applicationSecurityGroups
config.ApplicationGatewayBackendAddressPools = &applicationGatewayBackendAddressPools
config.LoadBalancerBackendAddressPools = &loadBalancerBackendAddressPools
config.LoadBalancerInboundNatRules = &loadBalancerInboundNatRules
config.Properties.ApplicationSecurityGroups = &applicationSecurityGroups
config.Properties.ApplicationGatewayBackendAddressPools = &applicationGatewayBackendAddressPools
config.Properties.LoadBalancerBackendAddressPools = &loadBalancerBackendAddressPools
config.Properties.LoadBalancerInboundNatRules = &loadBalancerInboundNatRules
}

return output
Expand Down
Loading

0 comments on commit 57fe338

Please sign in to comment.