From 544951ee0b30f593945ebf4e7c21fe58aef08552 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:22:05 +0800 Subject: [PATCH 1/4] fix apim subnet id case --- internal/services/apimanagement/api_management_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/services/apimanagement/api_management_resource.go b/internal/services/apimanagement/api_management_resource.go index 96ba8ebfa78f..acabea9ce8bb 100644 --- a/internal/services/apimanagement/api_management_resource.go +++ b/internal/services/apimanagement/api_management_resource.go @@ -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" @@ -1732,7 +1733,8 @@ func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.Virtua virtualNetworkConfiguration := make(map[string]interface{}) if input.SubnetResourceID != nil { - virtualNetworkConfiguration["subnet_id"] = *input.SubnetResourceID + subnetId, _ := networkParse.SubnetID(*input.SubnetResourceID) + virtualNetworkConfiguration["subnet_id"] = subnetId.ID() } return []interface{}{virtualNetworkConfiguration} From a6655a5655b31eec2bd7cc4afc942ace86d69a61 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 26 Oct 2022 15:05:02 +0800 Subject: [PATCH 2/4] return err --- .../apimanagement/api_management_resource.go | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/internal/services/apimanagement/api_management_resource.go b/internal/services/apimanagement/api_management_resource.go index acabea9ce8bb..d1e99598a14b 100644 --- a/internal/services/apimanagement/api_management_resource.go +++ b/internal/services/apimanagement/api_management_resource.go @@ -1025,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) } @@ -1436,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 { @@ -1472,7 +1479,10 @@ 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, @@ -1480,13 +1490,13 @@ func flattenApiManagementAdditionalLocations(input *[]apimanagement.AdditionalLo "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.Flatten(prop.Zones), "gateway_disabled": gatewayDisabled, }) } - return results + return results, nil } func expandIdentity(input []interface{}) (*apimanagement.ServiceIdentity, error) { @@ -1725,19 +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 { - subnetId, _ := networkParse.SubnetID(*input.SubnetResourceID) + subnetId, err := networkParse.SubnetID(*input.SubnetResourceID) + if err != nil { + return []interface{}{}, nil + } virtualNetworkConfiguration["subnet_id"] = subnetId.ID() } - return []interface{}{virtualNetworkConfiguration} + return []interface{}{virtualNetworkConfiguration}, nil } func parseApiManagementNilableDictionary(input map[string]*string, key string) bool { From 4a557625c7abf7db0f8a1becdde71293ed50b320 Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 27 Oct 2022 13:12:19 +0800 Subject: [PATCH 3/4] fix typo --- internal/services/apimanagement/api_management_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/apimanagement/api_management_resource.go b/internal/services/apimanagement/api_management_resource.go index d1e99598a14b..0cc41c312397 100644 --- a/internal/services/apimanagement/api_management_resource.go +++ b/internal/services/apimanagement/api_management_resource.go @@ -1745,7 +1745,7 @@ func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.Virtua if input.SubnetResourceID != nil { subnetId, err := networkParse.SubnetID(*input.SubnetResourceID) if err != nil { - return []interface{}{}, nil + return []interface{}{}, err } virtualNetworkConfiguration["subnet_id"] = subnetId.ID() } From 962a545b2804857beb48ae666c635f465b32a9de Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:41:25 +0800 Subject: [PATCH 4/4] fix --- internal/services/apimanagement/api_management_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/apimanagement/api_management_resource.go b/internal/services/apimanagement/api_management_resource.go index 0cc41c312397..bbce4f87a756 100644 --- a/internal/services/apimanagement/api_management_resource.go +++ b/internal/services/apimanagement/api_management_resource.go @@ -1743,7 +1743,7 @@ func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.Virtua virtualNetworkConfiguration := make(map[string]interface{}) if input.SubnetResourceID != nil { - subnetId, err := networkParse.SubnetID(*input.SubnetResourceID) + subnetId, err := networkParse.SubnetIDInsensitively(*input.SubnetResourceID) if err != nil { return []interface{}{}, err }