Skip to content

Commit

Permalink
azurerm_api_management - fix subnet_id case sensitivity (#18988)
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa authored Nov 2, 2022
1 parent 80a841d commit 1a6f070
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions internal/services/apimanagement/api_management_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz"
apimValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
networkParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -1024,12 +1025,19 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{
if err := d.Set("hostname_configuration", hostnameConfigs); err != nil {
return fmt.Errorf("setting `hostname_configuration`: %+v", err)
}

if err := d.Set("additional_location", flattenApiManagementAdditionalLocations(props.AdditionalLocations)); err != nil {
additionalLocation, err := flattenApiManagementAdditionalLocations(props.AdditionalLocations)
if err != nil {
return err
}
if err := d.Set("additional_location", additionalLocation); err != nil {
return fmt.Errorf("setting `additional_location`: %+v", err)
}

if err := d.Set("virtual_network_configuration", flattenApiManagementVirtualNetworkConfiguration(props.VirtualNetworkConfiguration)); err != nil {
virtualNetworkConfiguration, err := flattenApiManagementVirtualNetworkConfiguration(props.VirtualNetworkConfiguration)
if err != nil {
return err
}
if err := d.Set("virtual_network_configuration", virtualNetworkConfiguration); err != nil {
return fmt.Errorf("setting `virtual_network_configuration`: %+v", err)
}

Expand Down Expand Up @@ -1435,10 +1443,10 @@ func expandAzureRmApiManagementAdditionalLocations(d *pluginsdk.ResourceData, sk
return &additionalLocations, nil
}

func flattenApiManagementAdditionalLocations(input *[]apimanagement.AdditionalLocation) []interface{} {
func flattenApiManagementAdditionalLocations(input *[]apimanagement.AdditionalLocation) ([]interface{}, error) {
results := make([]interface{}, 0)
if input == nil {
return results
return results, nil
}

for _, prop := range *input {
Expand Down Expand Up @@ -1471,21 +1479,24 @@ func flattenApiManagementAdditionalLocations(input *[]apimanagement.AdditionalLo
if prop.DisableGateway != nil {
gatewayDisabled = *prop.DisableGateway
}

virtualNetworkConfiguration, err := flattenApiManagementVirtualNetworkConfiguration(prop.VirtualNetworkConfiguration)
if err != nil {
return results, err
}
results = append(results, map[string]interface{}{
"capacity": capacity,
"gateway_regional_url": gatewayRegionalUrl,
"location": location.NormalizeNilable(prop.Location),
"private_ip_addresses": privateIPAddresses,
"public_ip_address_id": publicIpAddressId,
"public_ip_addresses": publicIPAddresses,
"virtual_network_configuration": flattenApiManagementVirtualNetworkConfiguration(prop.VirtualNetworkConfiguration),
"virtual_network_configuration": virtualNetworkConfiguration,
"zones": zones.FlattenUntyped(prop.Zones),
"gateway_disabled": gatewayDisabled,
})
}

return results
return results, nil
}

func expandIdentity(input []interface{}) (*apimanagement.ServiceIdentity, error) {
Expand Down Expand Up @@ -1724,18 +1735,22 @@ func flattenApiManagementProtocolsCustomProperties(input map[string]*string) []i
return []interface{}{output}
}

func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.VirtualNetworkConfiguration) []interface{} {
func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.VirtualNetworkConfiguration) ([]interface{}, error) {
if input == nil {
return []interface{}{}
return []interface{}{}, nil
}

virtualNetworkConfiguration := make(map[string]interface{})

if input.SubnetResourceID != nil {
virtualNetworkConfiguration["subnet_id"] = *input.SubnetResourceID
subnetId, err := networkParse.SubnetIDInsensitively(*input.SubnetResourceID)
if err != nil {
return []interface{}{}, err
}
virtualNetworkConfiguration["subnet_id"] = subnetId.ID()
}

return []interface{}{virtualNetworkConfiguration}
return []interface{}{virtualNetworkConfiguration}, nil
}

func parseApiManagementNilableDictionary(input map[string]*string, key string) bool {
Expand Down

0 comments on commit 1a6f070

Please sign in to comment.