From a9258cb98ef8269bbfd2b2f62169666c955c592c Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 21 May 2019 14:40:09 -0700 Subject: [PATCH 1/6] data.azurerm_virtual_network: add network_space property to match resource --- azurerm/data_source_virtual_network.go | 57 +++++++++++-------- .../data_source_virtual_network_gateway.go | 53 +++++------------ azurerm/resource_arm_virtual_network.go | 14 +++-- .../resource_arm_virtual_network_gateway.go | 24 +++----- azurerm/utils/common_marshal.go | 2 + website/docs/d/virtual_network.html.markdown | 2 +- 6 files changed, 66 insertions(+), 86 deletions(-) diff --git a/azurerm/data_source_virtual_network.go b/azurerm/data_source_virtual_network.go index 20f2bbd47068..dcb55b1cd689 100644 --- a/azurerm/data_source_virtual_network.go +++ b/azurerm/data_source_virtual_network.go @@ -29,6 +29,14 @@ func dataSourceArmVirtualNetwork() *schema.Resource { }, }, + "address_space": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "dns_servers": { Type: schema.TypeList, Computed: true, @@ -69,51 +77,46 @@ func dataSourceArmVnetRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error making Read request on Virtual Network %q (resource group %q): %+v", name, resGroup, err) } + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("API returns a nil/empty id on Virtual Network %q (resource group %q): %+v", name, resGroup, err) + } d.SetId(*resp.ID) if props := resp.VirtualNetworkPropertiesFormat; props != nil { - addressSpaces := flattenVnetAddressPrefixes(props.AddressSpace.AddressPrefixes) - if err := d.Set("address_spaces", addressSpaces); err != nil { - return err + if as := props.AddressSpace; as != nil { + if err := d.Set("address_spaces", utils.FlattenStringArray(as.AddressPrefixes)); err != nil { //todo remove in 2.0 + return fmt.Errorf("error setting `address_spaces`: %v", err) + } + if err := d.Set("address_space", utils.FlattenStringArray(as.AddressPrefixes)); err != nil { + return fmt.Errorf("error setting `address_space`: %v", err) + } } if options := props.DhcpOptions; options != nil { - dnsServers := flattenVnetAddressPrefixes(options.DNSServers) - if err := d.Set("dns_servers", dnsServers); err != nil { - return err + if err := d.Set("dns_servers", utils.FlattenStringArray(options.DNSServers)); err != nil { + return fmt.Errorf("error setting `dns_servers`: %v", err) } } - subnets := flattenVnetSubnetsNames(props.Subnets) - if err := d.Set("subnets", subnets); err != nil { - return err + if err := d.Set("subnets", flattenVnetSubnetsNames(props.Subnets)); err != nil { + return fmt.Errorf("error setting `subnets`: %v", err) } - vnetPeerings := flattenVnetPeerings(props.VirtualNetworkPeerings) - if err := d.Set("vnet_peerings", vnetPeerings); err != nil { - return err + if err := d.Set("vnet_peerings", flattenVnetPeerings(props.VirtualNetworkPeerings)); err != nil { + return fmt.Errorf("error setting `vnet_peerings`: %v", err) } } return nil } -func flattenVnetAddressPrefixes(input *[]string) []interface{} { - prefixes := make([]interface{}, 0) - - if myprefixes := input; myprefixes != nil { - for _, prefix := range *myprefixes { - prefixes = append(prefixes, prefix) - } - } - return prefixes -} - func flattenVnetSubnetsNames(input *[]network.Subnet) []interface{} { subnets := make([]interface{}, 0) if mysubnets := input; mysubnets != nil { for _, subnet := range *mysubnets { - subnets = append(subnets, *subnet.Name) + if v := subnet.Name; v != nil { + subnets = append(subnets, *v) + } } } return subnets @@ -124,12 +127,16 @@ func flattenVnetPeerings(input *[]network.VirtualNetworkPeering) map[string]inte if peerings := input; peerings != nil { for _, vnetpeering := range *peerings { + if vnetpeering.Name == nil || vnetpeering.RemoteVirtualNetwork == nil || vnetpeering.RemoteVirtualNetwork.ID == nil { + continue + } + key := *vnetpeering.Name value := *vnetpeering.RemoteVirtualNetwork.ID output[key] = value - } } + return output } diff --git a/azurerm/data_source_virtual_network_gateway.go b/azurerm/data_source_virtual_network_gateway.go index a0e1a8f36058..6febab07821e 100644 --- a/azurerm/data_source_virtual_network_gateway.go +++ b/azurerm/data_source_virtual_network_gateway.go @@ -3,10 +3,7 @@ package azurerm import ( "fmt" - "bytes" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network" - "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -94,7 +91,7 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource { }, "root_certificate": { - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -109,11 +106,10 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource { }, }, }, - Set: hashVirtualNetworkGatewayDataSourceRootCert, }, "revoked_certificate": { - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -128,7 +124,6 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource { }, }, }, - Set: hashVirtualNetworkGatewayDataSourceRevokedCert, }, "radius_server_address": { @@ -287,19 +282,18 @@ func flattenArmVirtualNetworkGatewayDataSourceVpnClientConfig(cfg *network.VpnCl flat := make(map[string]interface{}) - addressSpace := make([]interface{}, 0) if pool := cfg.VpnClientAddressPool; pool != nil { - if prefixes := pool.AddressPrefixes; prefixes != nil { - for _, addr := range *prefixes { - addressSpace = append(addressSpace, addr) - } - } + flat["address_space"] = utils.FlattenStringArray(pool.AddressPrefixes) + } else { + flat["address_space"] = []interface{}{} } - flat["address_space"] = addressSpace rootCerts := make([]interface{}, 0) if certs := cfg.VpnClientRootCertificates; certs != nil { for _, cert := range *certs { + if cert.Name == nil || cert.VpnClientRootCertificatePropertiesFormat == nil || cert.VpnClientRootCertificatePropertiesFormat.PublicCertData == nil { + continue + } v := map[string]interface{}{ "name": *cert.Name, "public_cert_data": *cert.VpnClientRootCertificatePropertiesFormat.PublicCertData, @@ -307,11 +301,14 @@ func flattenArmVirtualNetworkGatewayDataSourceVpnClientConfig(cfg *network.VpnCl rootCerts = append(rootCerts, v) } } - flat["root_certificate"] = schema.NewSet(hashVirtualNetworkGatewayDataSourceRootCert, rootCerts) + flat["root_certificate"] = rootCerts revokedCerts := make([]interface{}, 0) if certs := cfg.VpnClientRevokedCertificates; certs != nil { for _, cert := range *certs { + if cert.Name == nil || cert.VpnClientRevokedCertificatePropertiesFormat == nil || cert.VpnClientRevokedCertificatePropertiesFormat.Thumbprint == nil { + continue + } v := map[string]interface{}{ "name": *cert.Name, "thumbprint": *cert.VpnClientRevokedCertificatePropertiesFormat.Thumbprint, @@ -319,12 +316,12 @@ func flattenArmVirtualNetworkGatewayDataSourceVpnClientConfig(cfg *network.VpnCl revokedCerts = append(revokedCerts, v) } } - flat["revoked_certificate"] = schema.NewSet(hashVirtualNetworkGatewayDataSourceRevokedCert, revokedCerts) + flat["revoked_certificate"] = revokedCerts - vpnClientProtocols := &schema.Set{F: schema.HashString} + vpnClientProtocols := make([]interface{}, 0) if vpnProtocols := cfg.VpnClientProtocols; vpnProtocols != nil { for _, protocol := range *vpnProtocols { - vpnClientProtocols.Add(string(protocol)) + vpnClientProtocols = append(vpnClientProtocols, string(protocol)) } } flat["vpn_client_protocols"] = vpnClientProtocols @@ -361,23 +358,3 @@ func flattenArmVirtualNetworkGatewayDataSourceBgpSettings(settings *network.BgpS return output } - -func hashVirtualNetworkGatewayDataSourceRootCert(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - - buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["public_cert_data"].(string))) - - return hashcode.String(buf.String()) -} - -func hashVirtualNetworkGatewayDataSourceRevokedCert(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - - buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["thumbprint"].(string))) - - return hashcode.String(buf.String()) -} diff --git a/azurerm/resource_arm_virtual_network.go b/azurerm/resource_arm_virtual_network.go index 968fc70e115b..701cab86badd 100644 --- a/azurerm/resource_arm_virtual_network.go +++ b/azurerm/resource_arm_virtual_network.go @@ -62,6 +62,7 @@ func resourceArmVirtualNetwork() *schema.Resource { Required: true, ValidateFunc: azure.ValidateResourceID, }, + "enable": { Type: schema.TypeBool, Required: true, @@ -90,15 +91,18 @@ func resourceArmVirtualNetwork() *schema.Resource { Required: true, ValidateFunc: validate.NoEmptyStrings, }, + "address_prefix": { Type: schema.TypeString, Required: true, ValidateFunc: validate.NoEmptyStrings, }, + "security_group": { Type: schema.TypeString, Optional: true, }, + "id": { Type: schema.TypeString, Computed: true, @@ -137,6 +141,7 @@ func resourceArmVirtualNetworkCreateUpdate(d *schema.ResourceData, meta interfac location := azureRMNormalizeLocation(d.Get("location").(string)) tags := d.Get("tags").(map[string]interface{}) + vnetProperties, vnetPropsErr := expandVirtualNetworkProperties(ctx, d, meta) if vnetPropsErr != nil { return vnetPropsErr @@ -216,23 +221,20 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err if props := resp.VirtualNetworkPropertiesFormat; props != nil { if space := props.AddressSpace; space != nil { - d.Set("address_space", space.AddressPrefixes) + d.Set("address_space", utils.FlattenStringArray(space.AddressPrefixes)) } if err := d.Set("ddos_protection_plan", flattenVirtualNetworkDDoSProtectionPlan(props)); err != nil { return fmt.Errorf("Error setting `ddos_protection_plan`: %+v", err) } - subnets := flattenVirtualNetworkSubnets(props.Subnets) - if err := d.Set("subnet", subnets); err != nil { + if err := d.Set("subnet", flattenVirtualNetworkSubnets(props.Subnets)); err != nil { return fmt.Errorf("Error setting `subnets`: %+v", err) } - dnsServers := flattenVirtualNetworkDNSServers(props.DhcpOptions) - if err := d.Set("dns_servers", dnsServers); err != nil { + if err := d.Set("dns_servers", flattenVirtualNetworkDNSServers(props.DhcpOptions)); err != nil { return fmt.Errorf("Error setting `dns_servers`: %+v", err) } - } flattenAndSetTags(d, resp.Tags) diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index 60faeeae18c9..8f09e695d55f 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -368,13 +368,11 @@ func resourceArmVirtualNetworkGatewayRead(d *schema.ResourceData, meta interface return fmt.Errorf("Error setting `ip_configuration`: %+v", err) } - vpnConfigFlat := flattenArmVirtualNetworkGatewayVpnClientConfig(gw.VpnClientConfiguration) - if err := d.Set("vpn_client_configuration", vpnConfigFlat); err != nil { + if err := d.Set("vpn_client_configuration", flattenArmVirtualNetworkGatewayVpnClientConfig(gw.VpnClientConfiguration)); err != nil { return fmt.Errorf("Error setting `vpn_client_configuration`: %+v", err) } - bgpSettingsFlat := flattenArmVirtualNetworkGatewayBgpSettings(gw.BgpSettings) - if err := d.Set("bgp_settings", bgpSettingsFlat); err != nil { + if err := d.Set("bgp_settings", flattenArmVirtualNetworkGatewayBgpSettings(gw.BgpSettings)); err != nil { return fmt.Errorf("Error setting `bgp_settings`: %+v", err) } } @@ -518,10 +516,9 @@ func expandArmVirtualNetworkGatewayVpnClientConfig(d *schema.ResourceData) *netw configSets := d.Get("vpn_client_configuration").([]interface{}) conf := configSets[0].(map[string]interface{}) - confAddresses := conf["address_space"].([]interface{}) - addresses := make([]string, 0, len(confAddresses)) - for _, addr := range confAddresses { - addresses = append(addresses, addr.(string)) + addresses := make([]string, 0, 0) + if v, ok := d.GetOkExists("address_space"); ok { + addresses = *utils.ExpandStringArray(v.([]interface{})) } var rootCerts []network.VpnClientRootCertificate @@ -640,18 +637,13 @@ func flattenArmVirtualNetworkGatewayVpnClientConfig(cfg *network.VpnClientConfig if cfg == nil { return []interface{}{} } - flat := make(map[string]interface{}) - addressSpace := make([]interface{}, 0) if pool := cfg.VpnClientAddressPool; pool != nil { - if prefixes := pool.AddressPrefixes; prefixes != nil { - for _, addr := range *prefixes { - addressSpace = append(addressSpace, addr) - } - } + flat["address_space"] = utils.FlattenStringArray(pool.AddressPrefixes) + } else { + flat["address_space"] = []interface{}{} } - flat["address_space"] = addressSpace rootCerts := make([]interface{}, 0) if certs := cfg.VpnClientRootCertificates; certs != nil { diff --git a/azurerm/utils/common_marshal.go b/azurerm/utils/common_marshal.go index 296f0e854554..f111abc63d71 100644 --- a/azurerm/utils/common_marshal.go +++ b/azurerm/utils/common_marshal.go @@ -1,5 +1,6 @@ package utils +// todo array -> slice ? func ExpandStringArray(input []interface{}) *[]string { result := make([]string, 0) for _, item := range input { @@ -8,6 +9,7 @@ func ExpandStringArray(input []interface{}) *[]string { return &result } +// todo array -> slice ? func FlattenStringArray(input *[]string) []interface{} { result := make([]interface{}, 0) if input != nil { diff --git a/website/docs/d/virtual_network.html.markdown b/website/docs/d/virtual_network.html.markdown index cc296340185b..277366f38855 100644 --- a/website/docs/d/virtual_network.html.markdown +++ b/website/docs/d/virtual_network.html.markdown @@ -31,7 +31,7 @@ output "virtual_network_id" { ## Attributes Reference * `id` - The ID of the virtual network. -* `address_spaces` - The list of address spaces used by the virtual network. +* `address_space` - The list of address spaces used by the virtual network. * `dns_servers` - The list of DNS servers used by the virtual network. * `subnets` - The list of name of the subnets that are attached to this virtual network. * `vnet_peerings` - A mapping of name - virtual network id of the virtual network peerings. From 691bba653e1cd215900cef905058508e0700e6a7 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 21 May 2019 14:41:12 -0700 Subject: [PATCH 2/6] [Expand|Flatten]StringArray to Slice --- azurerm/data_source_virtual_network.go | 6 +++--- azurerm/data_source_virtual_network_gateway.go | 2 +- azurerm/helpers/azure/api_management.go | 4 ++-- azurerm/resource_arm_api_management_property.go | 2 +- azurerm/resource_arm_container_group.go | 2 +- .../resource_arm_eventgrid_event_subscription.go | 4 ++-- ...rce_arm_firewall_application_rule_collection.go | 6 +++--- azurerm/resource_arm_iothub.go | 6 +++--- azurerm/resource_arm_key_vault_certificate.go | 14 +++++++------- azurerm/resource_arm_kubernetes_cluster.go | 4 ++-- azurerm/resource_arm_monitor_activity_log_alert.go | 4 ++-- azurerm/resource_arm_monitor_metric_alert.go | 8 ++++---- azurerm/resource_arm_virtual_network.go | 6 +++--- azurerm/resource_arm_virtual_network_gateway.go | 4 ++-- azurerm/utils/common_marshal.go | 6 ++---- 15 files changed, 38 insertions(+), 40 deletions(-) diff --git a/azurerm/data_source_virtual_network.go b/azurerm/data_source_virtual_network.go index dcb55b1cd689..cf3c29e4c826 100644 --- a/azurerm/data_source_virtual_network.go +++ b/azurerm/data_source_virtual_network.go @@ -84,16 +84,16 @@ func dataSourceArmVnetRead(d *schema.ResourceData, meta interface{}) error { if props := resp.VirtualNetworkPropertiesFormat; props != nil { if as := props.AddressSpace; as != nil { - if err := d.Set("address_spaces", utils.FlattenStringArray(as.AddressPrefixes)); err != nil { //todo remove in 2.0 + if err := d.Set("address_spaces", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { //todo remove in 2.0 return fmt.Errorf("error setting `address_spaces`: %v", err) } - if err := d.Set("address_space", utils.FlattenStringArray(as.AddressPrefixes)); err != nil { + if err := d.Set("address_space", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { return fmt.Errorf("error setting `address_space`: %v", err) } } if options := props.DhcpOptions; options != nil { - if err := d.Set("dns_servers", utils.FlattenStringArray(options.DNSServers)); err != nil { + if err := d.Set("dns_servers", utils.FlattenStringSlice(options.DNSServers)); err != nil { return fmt.Errorf("error setting `dns_servers`: %v", err) } } diff --git a/azurerm/data_source_virtual_network_gateway.go b/azurerm/data_source_virtual_network_gateway.go index 6febab07821e..7772b2e5550d 100644 --- a/azurerm/data_source_virtual_network_gateway.go +++ b/azurerm/data_source_virtual_network_gateway.go @@ -283,7 +283,7 @@ func flattenArmVirtualNetworkGatewayDataSourceVpnClientConfig(cfg *network.VpnCl flat := make(map[string]interface{}) if pool := cfg.VpnClientAddressPool; pool != nil { - flat["address_space"] = utils.FlattenStringArray(pool.AddressPrefixes) + flat["address_space"] = utils.FlattenStringSlice(pool.AddressPrefixes) } else { flat["address_space"] = []interface{}{} } diff --git a/azurerm/helpers/azure/api_management.go b/azurerm/helpers/azure/api_management.go index 6f311dddede0..3d1bf66b5490 100644 --- a/azurerm/helpers/azure/api_management.go +++ b/azurerm/helpers/azure/api_management.go @@ -253,7 +253,7 @@ func ExpandApiManagementOperationParameterContract(input []interface{}) *[]apima Type: utils.String(paramType), Required: utils.Bool(required), DefaultValue: utils.String(defaultValue), - Values: utils.ExpandStringArray(valuesRaw), + Values: utils.ExpandStringSlice(valuesRaw), } outputs = append(outputs, output) } @@ -290,7 +290,7 @@ func FlattenApiManagementOperationParameterContract(input *[]apimanagement.Param output["default_value"] = *v.DefaultValue } - output["values"] = schema.NewSet(schema.HashString, utils.FlattenStringArray(v.Values)) + output["values"] = schema.NewSet(schema.HashString, utils.FlattenStringSlice(v.Values)) outputs = append(outputs, output) } diff --git a/azurerm/resource_arm_api_management_property.go b/azurerm/resource_arm_api_management_property.go index 6730203d607c..4d34f9cce050 100644 --- a/azurerm/resource_arm_api_management_property.go +++ b/azurerm/resource_arm_api_management_property.go @@ -88,7 +88,7 @@ func resourceArmApiManagementPropertyCreateUpdate(d *schema.ResourceData, meta i } if tags, ok := d.GetOk("tags"); ok { - parameters.PropertyContractProperties.Tags = utils.ExpandStringArray(tags.([]interface{})) + parameters.PropertyContractProperties.Tags = utils.ExpandStringSlice(tags.([]interface{})) } if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, name, parameters, ""); err != nil { diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index dfffc5454291..9d48cf02ee8e 100755 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -874,7 +874,7 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { commands := probeConfig["exec"].([]interface{}) if len(commands) > 0 { exec := containerinstance.ContainerExec{ - Command: utils.ExpandStringArray(commands), + Command: utils.ExpandStringSlice(commands), } probe.Exec = &exec } diff --git a/azurerm/resource_arm_eventgrid_event_subscription.go b/azurerm/resource_arm_eventgrid_event_subscription.go index 2855e1b31a3e..7d210a1eef18 100644 --- a/azurerm/resource_arm_eventgrid_event_subscription.go +++ b/azurerm/resource_arm_eventgrid_event_subscription.go @@ -240,7 +240,7 @@ func resourceArmEventGridEventSubscriptionCreateUpdate(d *schema.ResourceData, m Filter: expandEventGridEventSubscriptionFilter(d), DeadLetterDestination: expandEventGridEventSubscriptionStorageBlobDeadLetterDestination(d), RetryPolicy: expandEventGridEventSubscriptionRetryPolicy(d), - Labels: utils.ExpandStringArray(d.Get("labels").([]interface{})), + Labels: utils.ExpandStringSlice(d.Get("labels").([]interface{})), EventDeliverySchema: eventgrid.EventDeliverySchema(d.Get("event_delivery_schema").(string)), } @@ -487,7 +487,7 @@ func expandEventGridEventSubscriptionFilter(d *schema.ResourceData) *eventgrid.E filter := &eventgrid.EventSubscriptionFilter{} if includedEvents, ok := d.GetOk("included_event_types"); ok { - filter.IncludedEventTypes = utils.ExpandStringArray(includedEvents.([]interface{})) + filter.IncludedEventTypes = utils.ExpandStringSlice(includedEvents.([]interface{})) } if subjectFilter, ok := d.GetOk("subject_filter"); ok { diff --git a/azurerm/resource_arm_firewall_application_rule_collection.go b/azurerm/resource_arm_firewall_application_rule_collection.go index de2830b76041..1aacadf31fb4 100644 --- a/azurerm/resource_arm_firewall_application_rule_collection.go +++ b/azurerm/resource_arm_firewall_application_rule_collection.go @@ -375,9 +375,9 @@ func expandArmFirewallApplicationRules(inputs []interface{}) ([]network.AzureFir output := network.AzureFirewallApplicationRule{ Name: utils.String(ruleName), Description: utils.String(ruleDescription), - SourceAddresses: utils.ExpandStringArray(ruleSourceAddresses), - FqdnTags: utils.ExpandStringArray(ruleFqdnTags), - TargetFqdns: utils.ExpandStringArray(ruleTargetFqdns), + SourceAddresses: utils.ExpandStringSlice(ruleSourceAddresses), + FqdnTags: utils.ExpandStringSlice(ruleFqdnTags), + TargetFqdns: utils.ExpandStringSlice(ruleTargetFqdns), } ruleProtocols := make([]network.AzureFirewallApplicationRuleProtocol, 0) diff --git a/azurerm/resource_arm_iothub.go b/azurerm/resource_arm_iothub.go index 9b1d7cef9eaf..175b5f291703 100755 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/resource_arm_iothub.go @@ -612,7 +612,7 @@ func expandIoTHubRoutes(d *schema.ResourceData) *[]devices.RouteProperties { Name: &name, Source: source, Condition: &condition, - EndpointNames: utils.ExpandStringArray(endpointNamesRaw), + EndpointNames: utils.ExpandStringSlice(endpointNamesRaw), IsEnabled: &isEnabled, }) } @@ -710,7 +710,7 @@ func expandIoTHubFallbackRoute(d *schema.ResourceData) *devices.FallbackRoutePro return &devices.FallbackRouteProperties{ Source: &source, Condition: &condition, - EndpointNames: utils.ExpandStringArray(fallbackRouteMap["endpoint_names"].([]interface{})), + EndpointNames: utils.ExpandStringSlice(fallbackRouteMap["endpoint_names"].([]interface{})), IsEnabled: &isEnabled, } } @@ -905,7 +905,7 @@ func flattenIoTHubFallbackRoute(input *devices.RoutingProperties) []interface{} output["source"] = *source } - output["endpoint_names"] = utils.FlattenStringArray(route.EndpointNames) + output["endpoint_names"] = utils.FlattenStringSlice(route.EndpointNames) return []interface{}{output} } diff --git a/azurerm/resource_arm_key_vault_certificate.go b/azurerm/resource_arm_key_vault_certificate.go index 4d31a83bd6fc..d2a36b3c981e 100644 --- a/azurerm/resource_arm_key_vault_certificate.go +++ b/azurerm/resource_arm_key_vault_certificate.go @@ -612,7 +612,7 @@ func expandKeyVaultCertificatePolicy(d *schema.ResourceData) keyvault.Certificat cert := v.(map[string]interface{}) ekus := cert["extended_key_usage"].([]interface{}) - extendedKeyUsage := utils.ExpandStringArray(ekus) + extendedKeyUsage := utils.ExpandStringSlice(ekus) keyUsage := make([]keyvault.KeyUsageType, 0) keys := cert["key_usage"].([]interface{}) @@ -629,17 +629,17 @@ func expandKeyVaultCertificatePolicy(d *schema.ResourceData) keyvault.Certificat emails := san["emails"].([]interface{}) if len(emails) > 0 { - subjectAlternativeNames.Emails = utils.ExpandStringArray(emails) + subjectAlternativeNames.Emails = utils.ExpandStringSlice(emails) } dnsNames := san["dns_names"].([]interface{}) if len(dnsNames) > 0 { - subjectAlternativeNames.DNSNames = utils.ExpandStringArray(dnsNames) + subjectAlternativeNames.DNSNames = utils.ExpandStringSlice(dnsNames) } upns := san["upns"].([]interface{}) if len(upns) > 0 { - subjectAlternativeNames.Upns = utils.ExpandStringArray(upns) + subjectAlternativeNames.Upns = utils.ExpandStringSlice(upns) } } } @@ -726,9 +726,9 @@ func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy) []inter if san := props.SubjectAlternativeNames; san != nil { sanOutput := make(map[string]interface{}) - sanOutput["emails"] = utils.FlattenStringArray(san.Emails) - sanOutput["dns_names"] = utils.FlattenStringArray(san.DNSNames) - sanOutput["upns"] = utils.FlattenStringArray(san.Upns) + sanOutput["emails"] = utils.FlattenStringSlice(san.Emails) + sanOutput["dns_names"] = utils.FlattenStringSlice(san.DNSNames) + sanOutput["upns"] = utils.FlattenStringSlice(san.Upns) sanOutputs = append(sanOutputs, sanOutput) } diff --git a/azurerm/resource_arm_kubernetes_cluster.go b/azurerm/resource_arm_kubernetes_cluster.go index 2bd4ff738282..a6a838b3ea18 100644 --- a/azurerm/resource_arm_kubernetes_cluster.go +++ b/azurerm/resource_arm_kubernetes_cluster.go @@ -587,7 +587,7 @@ func resourceArmKubernetesClusterCreateUpdate(d *schema.ResourceData, meta inter rbacEnabled, azureADProfile := expandKubernetesClusterRoleBasedAccessControl(rbacRaw, tenantId) apiServerAuthorizedIPRangesRaw := d.Get("api_server_authorized_ip_ranges").(*schema.Set).List() - apiServerAuthorizedIPRanges := utils.ExpandStringArray(apiServerAuthorizedIPRangesRaw) + apiServerAuthorizedIPRanges := utils.ExpandStringSlice(apiServerAuthorizedIPRangesRaw) parameters := containerservice.ManagedCluster{ Name: &name, @@ -669,7 +669,7 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) d.Set("kubernetes_version", props.KubernetesVersion) d.Set("node_resource_group", props.NodeResourceGroup) - apiServerAuthorizedIPRanges := utils.FlattenStringArray(props.APIServerAuthorizedIPRanges) + apiServerAuthorizedIPRanges := utils.FlattenStringSlice(props.APIServerAuthorizedIPRanges) if err := d.Set("api_server_authorized_ip_ranges", apiServerAuthorizedIPRanges); err != nil { return fmt.Errorf("Error setting `api_server_authorized_ip_ranges`: %+v", err) } diff --git a/azurerm/resource_arm_monitor_activity_log_alert.go b/azurerm/resource_arm_monitor_activity_log_alert.go index fb6bb1e0b77c..e837ffd8434b 100644 --- a/azurerm/resource_arm_monitor_activity_log_alert.go +++ b/azurerm/resource_arm_monitor_activity_log_alert.go @@ -187,7 +187,7 @@ func resourceArmMonitorActivityLogAlertCreateUpdate(d *schema.ResourceData, meta ActivityLogAlert: &insights.ActivityLogAlert{ Enabled: utils.Bool(enabled), Description: utils.String(description), - Scopes: utils.ExpandStringArray(scopesRaw), + Scopes: utils.ExpandStringSlice(scopesRaw), Condition: expandMonitorActivityLogAlertCriteria(criteriaRaw), Actions: expandMonitorActivityLogAlertAction(actionRaw), }, @@ -236,7 +236,7 @@ func resourceArmMonitorActivityLogAlertRead(d *schema.ResourceData, meta interfa if alert := resp.ActivityLogAlert; alert != nil { d.Set("enabled", alert.Enabled) d.Set("description", alert.Description) - if err := d.Set("scopes", utils.FlattenStringArray(alert.Scopes)); err != nil { + if err := d.Set("scopes", utils.FlattenStringSlice(alert.Scopes)); err != nil { return fmt.Errorf("Error setting `scopes`: %+v", err) } if err := d.Set("criteria", flattenMonitorActivityLogAlertCriteria(alert.Condition)); err != nil { diff --git a/azurerm/resource_arm_monitor_metric_alert.go b/azurerm/resource_arm_monitor_metric_alert.go index a5b81bbc5377..c504a15ff66b 100644 --- a/azurerm/resource_arm_monitor_metric_alert.go +++ b/azurerm/resource_arm_monitor_metric_alert.go @@ -250,7 +250,7 @@ func resourceArmMonitorMetricAlertCreateUpdate(d *schema.ResourceData, meta inte Severity: utils.Int32(int32(severity)), EvaluationFrequency: utils.String(frequency), WindowSize: utils.String(windowSize), - Scopes: utils.ExpandStringArray(scopesRaw), + Scopes: utils.ExpandStringSlice(scopesRaw), Criteria: expandMonitorMetricAlertCriteria(criteriaRaw), Actions: expandMonitorMetricAlertAction(actionRaw), }, @@ -303,7 +303,7 @@ func resourceArmMonitorMetricAlertRead(d *schema.ResourceData, meta interface{}) d.Set("severity", alert.Severity) d.Set("frequency", alert.EvaluationFrequency) d.Set("window_size", alert.WindowSize) - if err := d.Set("scopes", utils.FlattenStringArray(alert.Scopes)); err != nil { + if err := d.Set("scopes", utils.FlattenStringSlice(alert.Scopes)); err != nil { return fmt.Errorf("Error setting `scopes`: %+v", err) } if err := d.Set("criteria", flattenMonitorMetricAlertCriteria(alert.Criteria)); err != nil { @@ -349,7 +349,7 @@ func expandMonitorMetricAlertCriteria(input []interface{}) *insights.MetricAlert dimensions = append(dimensions, insights.MetricDimension{ Name: utils.String(dVal["name"].(string)), Operator: utils.String(dVal["operator"].(string)), - Values: utils.ExpandStringArray(dVal["values"].([]interface{})), + Values: utils.ExpandStringSlice(dVal["values"].([]interface{})), }) } @@ -427,7 +427,7 @@ func flattenMonitorMetricAlertCriteria(input insights.BasicMetricAlertCriteria) if dimension.Operator != nil { dVal["operator"] = *dimension.Operator } - dVal["values"] = utils.FlattenStringArray(dimension.Values) + dVal["values"] = utils.FlattenStringSlice(dimension.Values) dimResult = append(dimResult, dVal) } v["dimension"] = dimResult diff --git a/azurerm/resource_arm_virtual_network.go b/azurerm/resource_arm_virtual_network.go index 701cab86badd..a58d608b5b07 100644 --- a/azurerm/resource_arm_virtual_network.go +++ b/azurerm/resource_arm_virtual_network.go @@ -221,7 +221,7 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err if props := resp.VirtualNetworkPropertiesFormat; props != nil { if space := props.AddressSpace; space != nil { - d.Set("address_space", utils.FlattenStringArray(space.AddressPrefixes)) + d.Set("address_space", utils.FlattenStringSlice(space.AddressPrefixes)) } if err := d.Set("ddos_protection_plan", flattenVirtualNetworkDDoSProtectionPlan(props)); err != nil { @@ -316,10 +316,10 @@ func expandVirtualNetworkProperties(ctx context.Context, d *schema.ResourceData, properties := &network.VirtualNetworkPropertiesFormat{ AddressSpace: &network.AddressSpace{ - AddressPrefixes: utils.ExpandStringArray(d.Get("address_space").([]interface{})), + AddressPrefixes: utils.ExpandStringSlice(d.Get("address_space").([]interface{})), }, DhcpOptions: &network.DhcpOptions{ - DNSServers: utils.ExpandStringArray(d.Get("dns_servers").([]interface{})), + DNSServers: utils.ExpandStringSlice(d.Get("dns_servers").([]interface{})), }, Subnets: &subnets, } diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index 8f09e695d55f..4a9c431495f0 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -518,7 +518,7 @@ func expandArmVirtualNetworkGatewayVpnClientConfig(d *schema.ResourceData) *netw addresses := make([]string, 0, 0) if v, ok := d.GetOkExists("address_space"); ok { - addresses = *utils.ExpandStringArray(v.([]interface{})) + addresses = *utils.ExpandStringSlice(v.([]interface{})) } var rootCerts []network.VpnClientRootCertificate @@ -640,7 +640,7 @@ func flattenArmVirtualNetworkGatewayVpnClientConfig(cfg *network.VpnClientConfig flat := make(map[string]interface{}) if pool := cfg.VpnClientAddressPool; pool != nil { - flat["address_space"] = utils.FlattenStringArray(pool.AddressPrefixes) + flat["address_space"] = utils.FlattenStringSlice(pool.AddressPrefixes) } else { flat["address_space"] = []interface{}{} } diff --git a/azurerm/utils/common_marshal.go b/azurerm/utils/common_marshal.go index f111abc63d71..9d3b98bdad3d 100644 --- a/azurerm/utils/common_marshal.go +++ b/azurerm/utils/common_marshal.go @@ -1,7 +1,6 @@ package utils -// todo array -> slice ? -func ExpandStringArray(input []interface{}) *[]string { +func ExpandStringSlice(input []interface{}) *[]string { result := make([]string, 0) for _, item := range input { result = append(result, item.(string)) @@ -9,8 +8,7 @@ func ExpandStringArray(input []interface{}) *[]string { return &result } -// todo array -> slice ? -func FlattenStringArray(input *[]string) []interface{} { +func FlattenStringSlice(input *[]string) []interface{} { result := make([]interface{}, 0) if input != nil { for _, item := range *input { From aef09b3b9a8ebb61485978d6d28ce859b12c3e14 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 21 May 2019 17:26:08 -0700 Subject: [PATCH 3/6] fix linting issue --- azurerm/resource_arm_virtual_network_gateway.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index 4a9c431495f0..7364606626e8 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -516,7 +516,7 @@ func expandArmVirtualNetworkGatewayVpnClientConfig(d *schema.ResourceData) *netw configSets := d.Get("vpn_client_configuration").([]interface{}) conf := configSets[0].(map[string]interface{}) - addresses := make([]string, 0, 0) + addresses := make([]string, 0) if v, ok := d.GetOkExists("address_space"); ok { addresses = *utils.ExpandStringSlice(v.([]interface{})) } From 9283cfbe3cbe88d905655f78062cf1a237be7835 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 21 May 2019 20:54:36 -0700 Subject: [PATCH 4/6] fix test failure --- azurerm/resource_arm_virtual_network_gateway.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index 7364606626e8..1401a04a8816 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -516,9 +516,10 @@ func expandArmVirtualNetworkGatewayVpnClientConfig(d *schema.ResourceData) *netw configSets := d.Get("vpn_client_configuration").([]interface{}) conf := configSets[0].(map[string]interface{}) - addresses := make([]string, 0) - if v, ok := d.GetOkExists("address_space"); ok { - addresses = *utils.ExpandStringSlice(v.([]interface{})) + confAddresses := conf["address_space"].([]interface{}) + addresses := make([]string, 0, len(confAddresses)) + for _, addr := range confAddresses { + addresses = append(addresses, addr.(string)) } var rootCerts []network.VpnClientRootCertificate From 207240ecca09994ffb06d2c57eb9225ec0ce8905 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 22 May 2019 14:39:29 -0700 Subject: [PATCH 5/6] deprecate address_spaces --- azurerm/data_source_virtual_network.go | 1 + website/docs/guides/2.0-upgrade-guide.html.markdown | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/azurerm/data_source_virtual_network.go b/azurerm/data_source_virtual_network.go index cf3c29e4c826..67300d1b4a24 100644 --- a/azurerm/data_source_virtual_network.go +++ b/azurerm/data_source_virtual_network.go @@ -24,6 +24,7 @@ func dataSourceArmVirtualNetwork() *schema.Resource { "address_spaces": { Type: schema.TypeList, Computed: true, + Deprecated: "This resource has been deprecated in favour of `address_space` to be more consistent with the `azurerm_virtual_network` resource", Elem: &schema.Schema{ Type: schema.TypeString, }, diff --git a/website/docs/guides/2.0-upgrade-guide.html.markdown b/website/docs/guides/2.0-upgrade-guide.html.markdown index e47b30635cab..05ce2d46324c 100644 --- a/website/docs/guides/2.0-upgrade-guide.html.markdown +++ b/website/docs/guides/2.0-upgrade-guide.html.markdown @@ -157,6 +157,10 @@ The deprecated field `internal_fqdn` will be removed. Azure Scheduler is being retired in favour of Logic Apps ([more information can be found here](https://docs.microsoft.com/en-us/azure/scheduler/migrate-from-scheduler-to-logic-apps)) - as such this Data Source will be removed. +### Data Source: `azurerm_virtual_network` + +The deprecated field `address_space` will be removed. + ### Resource: `azurerm_app_service_plan` The fields in the `properties` block (`app_service_environment_id`, `reserved` and `per_site_scaling`) have been moved to the top level - as such the `properties` block will be removed. From 38cb845f35552edc8eef01eb9d4530ffb03745a4 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 22 May 2019 15:16:22 -0700 Subject: [PATCH 6/6] make fmt --- azurerm/data_source_virtual_network.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/data_source_virtual_network.go b/azurerm/data_source_virtual_network.go index 67300d1b4a24..28a3481bf71c 100644 --- a/azurerm/data_source_virtual_network.go +++ b/azurerm/data_source_virtual_network.go @@ -22,9 +22,9 @@ func dataSourceArmVirtualNetwork() *schema.Resource { "resource_group_name": resourceGroupNameForDataSourceSchema(), "address_spaces": { - Type: schema.TypeList, - Computed: true, - Deprecated: "This resource has been deprecated in favour of `address_space` to be more consistent with the `azurerm_virtual_network` resource", + Type: schema.TypeList, + Computed: true, + Deprecated: "This resource has been deprecated in favour of `address_space` to be more consistent with the `azurerm_virtual_network` resource", Elem: &schema.Schema{ Type: schema.TypeString, },