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

2.0 Final Package Deprecations #5823

Merged
merged 21 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
88 changes: 22 additions & 66 deletions azurerm/helpers/azure/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ package azure
import (
"fmt"
"log"
"net"
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

const (
// TODO: switch back once https://github.com/Azure/azure-rest-api-specs/pull/8435 has been fixed
SystemAssignedUserAssigned web.ManagedServiceIdentityType = "SystemAssigned, UserAssigned"
)

func SchemaAppServiceAadAuthSettings() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -225,7 +230,7 @@ func SchemaAppServiceIdentity() *schema.Schema {
ValidateFunc: validation.StringInSlice([]string{
string(web.ManagedServiceIdentityTypeNone),
string(web.ManagedServiceIdentityTypeSystemAssigned),
string(web.ManagedServiceIdentityTypeSystemAssignedUserAssigned),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
string(SystemAssignedUserAssigned),
string(web.ManagedServiceIdentityTypeUserAssigned),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
Expand Down Expand Up @@ -302,25 +307,15 @@ func SchemaAppServiceSiteConfig() *schema.Schema {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validate.CIDR,
},
"virtual_network_subnet_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"subnet_mask": {
Type: schema.TypeString,
Optional: true,
Computed: true,
// TODO we should fix this in 2.0
// This attribute was made with the assumption that `ip_address` was the only valid option
// but `virtual_network_subnet_id` is being added and doesn't need a `subnet_mask`.
// We'll assume a default of "255.255.255.255" in the expand code when `ip_address` is specified
// and `subnet_mask` is not.
// Default: "255.255.255.255",
},
},
},
},
Expand Down Expand Up @@ -477,11 +472,6 @@ func SchemaAppServiceSiteConfig() *schema.Schema {
}, false),
},

"virtual_network_name": {
Type: schema.TypeString,
Optional: true,
},

"cors": SchemaWebCorsSettings(),

"auto_swap_slot_name": {
Expand Down Expand Up @@ -689,10 +679,6 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"subnet_mask": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -777,11 +763,6 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema {
Computed: true,
},

"virtual_network_name": {
Type: schema.TypeString,
Computed: true,
},

"cors": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -1334,7 +1315,7 @@ func ExpandAppServiceIdentity(input []interface{}) *web.ManagedServiceIdentity {
Type: identityType,
}

if managedServiceIdentity.Type == web.ManagedServiceIdentityTypeUserAssigned || managedServiceIdentity.Type == web.ManagedServiceIdentityTypeSystemAssignedUserAssigned {
if managedServiceIdentity.Type == web.ManagedServiceIdentityTypeUserAssigned || managedServiceIdentity.Type == SystemAssignedUserAssigned {
managedServiceIdentity.UserAssignedIdentities = identityIds
}

Expand Down Expand Up @@ -1439,31 +1420,20 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) {
ipAddress := restriction["ip_address"].(string)
vNetSubnetID := restriction["virtual_network_subnet_id"].(string)
if vNetSubnetID != "" && ipAddress != "" {
return siteConfig, fmt.Errorf(fmt.Sprintf("only one of `ip_address` or `virtual_network_subnet_id` can set set for `site_config.0.ip_restriction.%d`", i))
return siteConfig, fmt.Errorf(fmt.Sprintf("only one of `ip_address` or `virtual_network_subnet_id` can be set for `site_config.0.ip_restriction.%d`", i))
}

if vNetSubnetID == "" && ipAddress == "" {
return siteConfig, fmt.Errorf(fmt.Sprintf("one of `ip_address` or `virtual_network_subnet_id` must be set set for `site_config.0.ip_restriction.%d`", i))
return siteConfig, fmt.Errorf(fmt.Sprintf("one of `ip_address` or `virtual_network_subnet_id` must be set for `site_config.0.ip_restriction.%d`", i))
}

ipSecurityRestriction := web.IPSecurityRestriction{}
if ipAddress == "Any" {
continue
}

if ipAddress != "" {
mask := restriction["subnet_mask"].(string)
if mask == "" {
mask = "255.255.255.255"
}
// the 2018-02-01 API expects a blank subnet mask and an IP address in CIDR format: a.b.c.d/x
// so translate the IP and mask if necessary
restrictionMask := ""
cidrAddress := ipAddress
if mask != "" {
ipNet := net.IPNet{IP: net.ParseIP(ipAddress), Mask: net.IPMask(net.ParseIP(mask))}
cidrAddress = ipNet.String()
} else if !strings.Contains(ipAddress, "/") {
cidrAddress += "/32"
}
ipSecurityRestriction.IPAddress = &cidrAddress
ipSecurityRestriction.SubnetMask = &restrictionMask
ipSecurityRestriction.IPAddress = &ipAddress
}

if vNetSubnetID != "" {
Expand Down Expand Up @@ -1519,10 +1489,6 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) {
siteConfig.MinTLSVersion = web.SupportedTLSVersions(v.(string))
}

if v, ok := config["virtual_network_name"]; ok {
siteConfig.VnetName = utils.String(v.(string))
}

if v, ok := config["cors"]; ok {
corsSettings := v.(interface{})
expand := ExpandWebCorsSettings(corsSettings)
Expand Down Expand Up @@ -1587,20 +1553,14 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
if vs := input.IPSecurityRestrictions; vs != nil {
for _, v := range *vs {
block := make(map[string]interface{})

if ip := v.IPAddress; ip != nil {
// the 2018-02-01 API uses CIDR format (a.b.c.d/x), so translate that back to IP and mask
if strings.Contains(*ip, "/") {
ipAddr, ipNet, _ := net.ParseCIDR(*ip)
block["ip_address"] = ipAddr.String()
mask := net.IP(ipNet.Mask)
block["subnet_mask"] = mask.String()
if *ip == "Any" {
continue
} else {
block["ip_address"] = *ip
}
}
if subnet := v.SubnetMask; subnet != nil {
block["subnet_mask"] = *subnet
}
if vNetSubnetID := v.VnetSubnetResourceID; vNetSubnetID != nil {
block["virtual_network_subnet_id"] = *vNetSubnetID
}
Expand Down Expand Up @@ -1643,10 +1603,6 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
result["windows_fx_version"] = *input.WindowsFxVersion
}

if input.VnetName != nil {
result["virtual_network_name"] = *input.VnetName
}

result["scm_type"] = string(input.ScmType)
result["ftps_state"] = string(input.FtpsState)
result["min_tls_version"] = string(input.MinTLSVersion)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/app_service_schedule_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/Azure/go-autorest/autorest/date"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
)
Expand Down
11 changes: 0 additions & 11 deletions azurerm/helpers/azure/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ func SchemaLocationForDataSource() *schema.Schema {
}
}

func SchemaLocationDeprecated() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Optional: true,
StateFunc: NormalizeLocation,
DiffSuppressFunc: SuppressLocationDiff,
Deprecated: "location is no longer used",
}
}

// azure.NormalizeLocation is a function which normalises human-readable region/location
// names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus").
// In state we track the API internal version as it is easier to go from the human form
Expand Down
9 changes: 0 additions & 9 deletions azurerm/helpers/azure/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ func SchemaResourceGroupName() *schema.Schema {
}
}

func SchemaResourceGroupNameDeprecated() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Deprecated: "This field has been deprecated and is no longer used - will be removed in 2.0 of the Azure Provider",
}
}

func SchemaResourceGroupNameDiffSuppress() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/web.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package azure

import (
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down
7 changes: 3 additions & 4 deletions azurerm/internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ func AzureProvider() terraform.ResourceProvider {
},

"disable_correlation_request_id": {
Type: schema.TypeBool,
Optional: true,
// TODO: add an ARM_ prefix in 2.0w
DefaultFunc: schema.EnvDefaultFunc("DISABLE_CORRELATION_REQUEST_ID", false),
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_DISABLE_CORRELATION_REQUEST_ID", false),
Description: "This will disable the x-ms-correlation-request-id header.",
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -38,17 +37,6 @@ func dataSourceArmClientConfig() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"service_principal_application_id": {
Type: schema.TypeString,
Computed: true,
Deprecated: "This has been deprecated in favour of the `client_id` property",
},
"service_principal_object_id": {
Type: schema.TypeString,
Computed: true,
Deprecated: "This has been deprecated in favour of the unified `authenticated_object_id` property",
},
},
}
}
Expand All @@ -58,7 +46,6 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

var servicePrincipal *graphrbac.ServicePrincipal
if client.Account.AuthenticatedAsAServicePrincipal {
spClient := client.Authorization.ServicePrincipalsClient
// Application & Service Principal is 1:1 per tenant. Since we know the appId (client_id)
Expand All @@ -73,8 +60,6 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err
if listResult.Values() == nil || len(listResult.Values()) != 1 {
return fmt.Errorf("Unexpected Service Principal query result: %#v", listResult.Values())
}

servicePrincipal = &(listResult.Values())[0]
}

d.SetId(time.Now().UTC().String())
Expand All @@ -83,13 +68,5 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err
d.Set("subscription_id", client.Account.SubscriptionId)
d.Set("tenant_id", client.Account.TenantId)

if principal := servicePrincipal; principal != nil {
d.Set("service_principal_application_id", client.Account.ClientId)
d.Set("service_principal_object_id", principal.ObjectID)
} else {
d.Set("service_principal_application_id", "")
d.Set("service_principal_object_id", "")
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func TestAccDataSourceAzureRMClientConfig_basic(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "tenant_id", tenantId),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_id", subscriptionId),
testAzureRMClientConfigGUIDAttr(data.ResourceName, "object_id"),
testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_application_id"),
testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_object_id"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,19 @@ func resourceArmVirtualMachineExtensionsCreateUpdate(d *schema.ResourceData, met
defer cancel()

name := d.Get("name").(string)
virtualMachineId := d.Get("virtual_machine_id").(string)
v, err := ParseVirtualMachineID(virtualMachineId)
virtualMachineId, err := ParseVirtualMachineID(d.Get("virtual_machine_id").(string))
if err != nil {
return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", virtualMachineId, err)
}

virtualMachineName := v.Name
resourceGroup := v.ResourceGroup
virtualMachineName := virtualMachineId.Name
resourceGroup := virtualMachineId.ResourceGroup

virtualMachine, err := vmClient.Get(ctx, resourceGroup, virtualMachineName, "")
if err != nil {
return fmt.Errorf("Error getting Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err)
}

location := ""
if virtualMachine.Location != nil {
location = *virtualMachine.Location
}
location := *virtualMachine.Location
if location == "" {
return fmt.Errorf("Error reading location of Virtual Machine %q", virtualMachineName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ func testCheckAzureRMVirtualMachineExtensionExists(resourceName string) resource
}

name := rs.Primary.Attributes["name"]
vmId := rs.Primary.Attributes["virtual_machine_id"]
v, err := compute.ParseVirtualMachineID(vmId)
virtualMachineId, err := compute.ParseVirtualMachineID(rs.Primary.Attributes["virtual_machine_id"])
if err != nil {
return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", vmId, err)
return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", virtualMachineId, err)
}
vmName := v.Name
resourceGroup := rs.Primary.Attributes["resource_group_name"]
vmName := virtualMachineId.Name
resourceGroup := virtualMachineId.ResourceGroup

resp, err := client.Get(ctx, resourceGroup, vmName, name, "")
if err != nil {
Expand All @@ -152,13 +151,12 @@ func testCheckAzureRMVirtualMachineExtensionDestroy(s *terraform.State) error {
}

name := rs.Primary.Attributes["name"]
vmId := rs.Primary.Attributes["virtual_machine_id"]
v, err := compute.ParseVirtualMachineID(vmId)
virtualMachineId, err := compute.ParseVirtualMachineID(rs.Primary.Attributes["virtual_machine_id"])
if err != nil {
return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", vmId, err)
return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", virtualMachineId, err)
}
vmName := v.Name
resourceGroup := rs.Primary.Attributes["resource_group_name"]
vmName := virtualMachineId.Name
resourceGroup := virtualMachineId.ResourceGroup

resp, err := client.Get(ctx, resourceGroup, vmName, name, "")

Expand Down
Loading