diff --git a/resourcemanager/commonids/automation_compilation_job.go b/resourcemanager/commonids/automation_compilation_job.go index 142757e..96e9b47 100644 --- a/resourcemanager/commonids/automation_compilation_job.go +++ b/resourcemanager/commonids/automation_compilation_job.go @@ -42,19 +42,19 @@ func ParseAutomationCompilationJobID(input string) (*AutomationCompilationJobId, id := AutomationCompilationJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "automationAccountName", *parsed) } if id.CompilationJobId, ok = parsed.Parsed["compilationJobId"]; !ok { - return nil, fmt.Errorf("the segment 'compilationJobId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "compilationJobId", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseAutomationCompilationJobIDInsensitively(input string) (*AutomationComp id := AutomationCompilationJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.AutomationAccountName, ok = parsed.Parsed["automationAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'automationAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "automationAccountName", *parsed) } if id.CompilationJobId, ok = parsed.Parsed["compilationJobId"]; !ok { - return nil, fmt.Errorf("the segment 'compilationJobId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "compilationJobId", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/cloud_services_ip_configuration.go b/resourcemanager/commonids/cloud_services_ip_configuration.go index 3d65ec8..87069d2 100644 --- a/resourcemanager/commonids/cloud_services_ip_configuration.go +++ b/resourcemanager/commonids/cloud_services_ip_configuration.go @@ -46,27 +46,27 @@ func ParseCloudServicesIPConfigurationID(input string) (*CloudServicesIPConfigur id := CloudServicesIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CloudServiceName, ok = parsed.Parsed["cloudServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'cloudServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "cloudServiceName", *parsed) } if id.RoleInstanceName, ok = parsed.Parsed["roleInstanceName"]; !ok { - return nil, fmt.Errorf("the segment 'roleInstanceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "roleInstanceName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil @@ -78,34 +78,34 @@ func ParseCloudServicesIPConfigurationIDInsensitively(input string) (*CloudServi parser := resourceids.NewParserFromResourceIdType(CloudServicesIPConfigurationId{}) parsed, err := parser.Parse(input, true) if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) + return nil, err } var ok bool id := CloudServicesIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CloudServiceName, ok = parsed.Parsed["cloudServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'cloudServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "cloudServiceName", *parsed) } if id.RoleInstanceName, ok = parsed.Parsed["roleInstanceName"]; !ok { - return nil, fmt.Errorf("the segment 'roleInstanceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "roleInstanceName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/cloud_services_public_ip.go b/resourcemanager/commonids/cloud_services_public_ip.go index ff4c6eb..9c5d61e 100644 --- a/resourcemanager/commonids/cloud_services_public_ip.go +++ b/resourcemanager/commonids/cloud_services_public_ip.go @@ -48,31 +48,31 @@ func ParseCloudServicesPublicIPAddressID(input string) (*CloudServicesPublicIPAd id := CloudServicesPublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CloudServiceName, ok = parsed.Parsed["cloudServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'cloudServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "cloudServiceName", *parsed) } if id.RoleInstanceName, ok = parsed.Parsed["roleInstanceName"]; !ok { - return nil, fmt.Errorf("the segment 'roleInstanceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "roleInstanceName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } if id.PublicIPAddressName, ok = parsed.Parsed["publicIPAddressName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIPAddressName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIPAddressName", *parsed) } return &id, nil @@ -91,31 +91,31 @@ func ParseCloudServicesPublicIPAddressIDInsensitively(input string) (*CloudServi id := CloudServicesPublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CloudServiceName, ok = parsed.Parsed["cloudServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'cloudServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "cloudServiceName", *parsed) } if id.RoleInstanceName, ok = parsed.Parsed["roleInstanceName"]; !ok { - return nil, fmt.Errorf("the segment 'roleInstanceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "roleInstanceName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } if id.PublicIPAddressName, ok = parsed.Parsed["publicIPAddressName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIPAddressName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIPAddressName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/express_route_circuit_peering.go b/resourcemanager/commonids/express_route_circuit_peering.go index 87dac48..ebe9afd 100644 --- a/resourcemanager/commonids/express_route_circuit_peering.go +++ b/resourcemanager/commonids/express_route_circuit_peering.go @@ -42,19 +42,19 @@ func ParseExpressRouteCircuitPeeringID(input string) (*ExpressRouteCircuitPeerin id := ExpressRouteCircuitPeeringId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CircuitName, ok = parsed.Parsed["circuitName"]; !ok { - return nil, fmt.Errorf("the segment 'circuitName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "circuitName", *parsed) } if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { - return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseExpressRouteCircuitPeeringIDInsensitively(input string) (*ExpressRoute id := ExpressRouteCircuitPeeringId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.CircuitName, ok = parsed.Parsed["circuitName"]; !ok { - return nil, fmt.Errorf("the segment 'circuitName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "circuitName", *parsed) } if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { - return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/hyperv_site_job.go b/resourcemanager/commonids/hyperv_site_job.go index 281ac5b..5444dfc 100644 --- a/resourcemanager/commonids/hyperv_site_job.go +++ b/resourcemanager/commonids/hyperv_site_job.go @@ -42,19 +42,19 @@ func ParseHyperVSiteJobID(input string) (*HyperVSiteJobId, error) { id := HyperVSiteJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.JobName, ok = parsed.Parsed["jobName"]; !ok { - return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "jobName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseHyperVSiteJobIDInsensitively(input string) (*HyperVSiteJobId, error) { id := HyperVSiteJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.JobName, ok = parsed.Parsed["jobName"]; !ok { - return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "jobName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/hyperv_site_machine.go b/resourcemanager/commonids/hyperv_site_machine.go index 61bbb66..9b0be9e 100644 --- a/resourcemanager/commonids/hyperv_site_machine.go +++ b/resourcemanager/commonids/hyperv_site_machine.go @@ -42,19 +42,19 @@ func ParseHyperVSiteMachineID(input string) (*HyperVSiteMachineId, error) { id := HyperVSiteMachineId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.MachineName, ok = parsed.Parsed["machineName"]; !ok { - return nil, fmt.Errorf("the segment 'machineName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "machineName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseHyperVSiteMachineIDInsensitively(input string) (*HyperVSiteMachineId, id := HyperVSiteMachineId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.MachineName, ok = parsed.Parsed["machineName"]; !ok { - return nil, fmt.Errorf("the segment 'machineName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "machineName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/hyperv_site_runasaccount.go b/resourcemanager/commonids/hyperv_site_runasaccount.go index 494d3b8..38947a3 100644 --- a/resourcemanager/commonids/hyperv_site_runasaccount.go +++ b/resourcemanager/commonids/hyperv_site_runasaccount.go @@ -42,19 +42,19 @@ func ParseHyperVSiteRunAsAccountID(input string) (*HyperVSiteRunAsAccountId, err id := HyperVSiteRunAsAccountId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.RunAsAccountName, ok = parsed.Parsed["runAsAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'runAsAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "runAsAccountName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseHyperVSiteRunAsAccountIDInsensitively(input string) (*HyperVSiteRunAsA id := HyperVSiteRunAsAccountId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HyperVSiteName, ok = parsed.Parsed["hyperVSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'hyperVSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hyperVSiteName", *parsed) } if id.RunAsAccountName, ok = parsed.Parsed["runAsAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'runAsAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "runAsAccountName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/key_vault.go b/resourcemanager/commonids/key_vault.go index 8a4a408..e4a66ca 100644 --- a/resourcemanager/commonids/key_vault.go +++ b/resourcemanager/commonids/key_vault.go @@ -40,15 +40,15 @@ func ParseKeyVaultID(input string) (*KeyVaultId, error) { id := KeyVaultId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseKeyVaultIDInsensitively(input string) (*KeyVaultId, error) { id := KeyVaultId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/key_vault_key.go b/resourcemanager/commonids/key_vault_key.go index 836fcb3..03c2915 100644 --- a/resourcemanager/commonids/key_vault_key.go +++ b/resourcemanager/commonids/key_vault_key.go @@ -42,19 +42,19 @@ func ParseKeyVaultKeyID(input string) (*KeyVaultKeyId, error) { id := KeyVaultKeyId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { - return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "keyName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseKeyVaultKeyIDInsensitively(input string) (*KeyVaultKeyId, error) { id := KeyVaultKeyId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { - return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "keyName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/key_vault_key_version.go b/resourcemanager/commonids/key_vault_key_version.go index d9e8693..d775ec7 100644 --- a/resourcemanager/commonids/key_vault_key_version.go +++ b/resourcemanager/commonids/key_vault_key_version.go @@ -47,23 +47,23 @@ func ParseKeyVaultKeyVersionID(input string) (*KeyVaultKeyVersionId, error) { id := KeyVaultKeyVersionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { - return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "keyName", *parsed) } if id.VersionName, ok = parsed.Parsed["versionName"]; !ok { - return nil, fmt.Errorf("the segment 'versionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "versionName", *parsed) } return &id, nil @@ -82,23 +82,23 @@ func ParseKeyVaultKeyVersionIDInsensitively(input string) (*KeyVaultKeyVersionId id := KeyVaultKeyVersionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { - return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "keyName", *parsed) } if id.VersionName, ok = parsed.Parsed["versionName"]; !ok { - return nil, fmt.Errorf("the segment 'versionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "versionName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/key_vault_private_endpoint_connection.go b/resourcemanager/commonids/key_vault_private_endpoint_connection.go index 440c908..c8fcd95 100644 --- a/resourcemanager/commonids/key_vault_private_endpoint_connection.go +++ b/resourcemanager/commonids/key_vault_private_endpoint_connection.go @@ -42,19 +42,19 @@ func ParseKeyVaultPrivateEndpointConnectionID(input string) (*KeyVaultPrivateEnd id := KeyVaultPrivateEndpointConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { - return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseKeyVaultPrivateEndpointConnectionIDInsensitively(input string) (*KeyVa id := KeyVaultPrivateEndpointConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VaultName, ok = parsed.Parsed["vaultName"]; !ok { - return nil, fmt.Errorf("the segment 'vaultName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vaultName", *parsed) } if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { - return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/management_group.go b/resourcemanager/commonids/management_group.go index 85b9078..ce8c989 100644 --- a/resourcemanager/commonids/management_group.go +++ b/resourcemanager/commonids/management_group.go @@ -36,7 +36,7 @@ func ParseManagementGroupID(input string) (*ManagementGroupId, error) { id := ManagementGroupId{} if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { - return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "groupId", *parsed) } return &id, nil @@ -55,7 +55,7 @@ func ParseManagementGroupIDInsensitively(input string) (*ManagementGroupId, erro id := ManagementGroupId{} if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { - return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "groupId", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/network_interface.go b/resourcemanager/commonids/network_interface.go index 586fcb9..a2fccd9 100644 --- a/resourcemanager/commonids/network_interface.go +++ b/resourcemanager/commonids/network_interface.go @@ -40,15 +40,15 @@ func ParseNetworkInterfaceID(input string) (*NetworkInterfaceId, error) { id := NetworkInterfaceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseNetworkInterfaceIDInsensitively(input string) (*NetworkInterfaceId, er id := NetworkInterfaceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/network_interface_ip_configuration.go b/resourcemanager/commonids/network_interface_ip_configuration.go index 3c87e07..02b7f4a 100644 --- a/resourcemanager/commonids/network_interface_ip_configuration.go +++ b/resourcemanager/commonids/network_interface_ip_configuration.go @@ -42,19 +42,19 @@ func ParseNetworkInterfaceIPConfigurationID(input string) (*NetworkInterfaceIPCo id := NetworkInterfaceIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseNetworkInterfaceIPConfigurationIDInsensitively(input string) (*Network id := NetworkInterfaceIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/provisioning_service.go b/resourcemanager/commonids/provisioning_service.go index a19f98c..d09f9df 100644 --- a/resourcemanager/commonids/provisioning_service.go +++ b/resourcemanager/commonids/provisioning_service.go @@ -40,15 +40,15 @@ func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { id := ProvisioningServiceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "provisioningServiceName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningService id := ProvisioningServiceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { - return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "provisioningServiceName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/public_ip_address.go b/resourcemanager/commonids/public_ip_address.go index d1f05be..bfbb75a 100644 --- a/resourcemanager/commonids/public_ip_address.go +++ b/resourcemanager/commonids/public_ip_address.go @@ -40,15 +40,15 @@ func ParsePublicIPAddressID(input string) (*PublicIPAddressId, error) { id := PublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.PublicIPAddressesName, ok = parsed.Parsed["publicIPAddressesName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIPAddressesName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIPAddressesName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParsePublicIPAddressIDInsensitively(input string) (*PublicIPAddressId, erro id := PublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.PublicIPAddressesName, ok = parsed.Parsed["publicIPAddressesName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIPAddressesName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIPAddressesName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/resource_group.go b/resourcemanager/commonids/resource_group.go index 688affe..a346420 100644 --- a/resourcemanager/commonids/resource_group.go +++ b/resourcemanager/commonids/resource_group.go @@ -38,11 +38,11 @@ func ParseResourceGroupID(input string) (*ResourceGroupId, error) { id := ResourceGroupId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } return &id, nil @@ -61,11 +61,11 @@ func ParseResourceGroupIDInsensitively(input string) (*ResourceGroupId, error) { id := ResourceGroupId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/scope.go b/resourcemanager/commonids/scope.go index a68c87b..4c00650 100644 --- a/resourcemanager/commonids/scope.go +++ b/resourcemanager/commonids/scope.go @@ -36,7 +36,7 @@ func ParseScopeID(input string) (*ScopeId, error) { id := ScopeId{} if id.Scope, ok = parsed.Parsed["scope"]; !ok { - return nil, fmt.Errorf("the segment 'scope' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "scope", *parsed) } return &id, nil @@ -55,7 +55,7 @@ func ParseScopeIDInsensitively(input string) (*ScopeId, error) { id := ScopeId{} if id.Scope, ok = parsed.Parsed["scope"]; !ok { - return nil, fmt.Errorf("the segment 'scope' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "scope", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/subnet.go b/resourcemanager/commonids/subnet.go index 0e28a37..dc88af5 100644 --- a/resourcemanager/commonids/subnet.go +++ b/resourcemanager/commonids/subnet.go @@ -42,19 +42,19 @@ func ParseSubnetID(input string) (*SubnetId, error) { id := SubnetId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualNetworkName, ok = parsed.Parsed["virtualNetworkName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualNetworkName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkName", *parsed) } if id.SubnetName, ok = parsed.Parsed["subnetName"]; !ok { - return nil, fmt.Errorf("the segment 'subnetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subnetName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseSubnetIDInsensitively(input string) (*SubnetId, error) { id := SubnetId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualNetworkName, ok = parsed.Parsed["virtualNetworkName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualNetworkName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkName", *parsed) } if id.SubnetName, ok = parsed.Parsed["subnetName"]; !ok { - return nil, fmt.Errorf("the segment 'subnetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subnetName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/subscription.go b/resourcemanager/commonids/subscription.go index 2b1b141..873fe3c 100644 --- a/resourcemanager/commonids/subscription.go +++ b/resourcemanager/commonids/subscription.go @@ -36,7 +36,7 @@ func ParseSubscriptionID(input string) (*SubscriptionId, error) { id := SubscriptionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } return &id, nil @@ -55,7 +55,7 @@ func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) { id := SubscriptionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/user_assigned_identity.go b/resourcemanager/commonids/user_assigned_identity.go index e770693..5ac3294 100644 --- a/resourcemanager/commonids/user_assigned_identity.go +++ b/resourcemanager/commonids/user_assigned_identity.go @@ -40,15 +40,15 @@ func ParseUserAssignedIdentityID(input string) (*UserAssignedIdentityId, error) id := UserAssignedIdentityId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.UserAssignedIdentityName, ok = parsed.Parsed["userAssignedIdentityName"]; !ok { - return nil, fmt.Errorf("the segment 'userAssignedIdentityName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "userAssignedIdentityName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseUserAssignedIdentityIDInsensitively(input string) (*UserAssignedIdenti id := UserAssignedIdentityId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.UserAssignedIdentityName, ok = parsed.Parsed["userAssignedIdentityName"]; !ok { - return nil, fmt.Errorf("the segment 'userAssignedIdentityName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "userAssignedIdentityName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_hub_bgp_connection.go b/resourcemanager/commonids/virtual_hub_bgp_connection.go index 7304b7e..13645be 100644 --- a/resourcemanager/commonids/virtual_hub_bgp_connection.go +++ b/resourcemanager/commonids/virtual_hub_bgp_connection.go @@ -42,19 +42,19 @@ func ParseVirtualHubBGPConnectionID(input string) (*VirtualHubBGPConnectionId, e id := VirtualHubBGPConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HubName, ok = parsed.Parsed["hubName"]; !ok { - return nil, fmt.Errorf("the segment 'hubName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hubName", *parsed) } if id.ConnectionName, ok = parsed.Parsed["connectionName"]; !ok { - return nil, fmt.Errorf("the segment 'connectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "connectionName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVirtualHubBGPConnectionIDInsensitively(input string) (*VirtualHubBGPCo id := VirtualHubBGPConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.HubName, ok = parsed.Parsed["hubName"]; !ok { - return nil, fmt.Errorf("the segment 'hubName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "hubName", *parsed) } if id.ConnectionName, ok = parsed.Parsed["connectionName"]; !ok { - return nil, fmt.Errorf("the segment 'connectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "connectionName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_hub_ip_configuration.go b/resourcemanager/commonids/virtual_hub_ip_configuration.go index 9b98938..006d924 100644 --- a/resourcemanager/commonids/virtual_hub_ip_configuration.go +++ b/resourcemanager/commonids/virtual_hub_ip_configuration.go @@ -42,19 +42,19 @@ func ParseVirtualHubIPConfigurationID(input string) (*VirtualHubIPConfigurationI id := VirtualHubIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualHubName, ok = parsed.Parsed["virtualHubName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualHubName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualHubName", *parsed) } if id.IpConfigName, ok = parsed.Parsed["ipConfigName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVirtualHubIPConfigurationIDInsensitively(input string) (*VirtualHubIPC id := VirtualHubIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualHubName, ok = parsed.Parsed["virtualHubName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualHubName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualHubName", *parsed) } if id.IpConfigName, ok = parsed.Parsed["ipConfigName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_machine_scale_set_ip_configuration.go b/resourcemanager/commonids/virtual_machine_scale_set_ip_configuration.go index 2b60f86..609bf7f 100644 --- a/resourcemanager/commonids/virtual_machine_scale_set_ip_configuration.go +++ b/resourcemanager/commonids/virtual_machine_scale_set_ip_configuration.go @@ -46,27 +46,27 @@ func ParseVirtualMachineScaleSetIPConfigurationId(input string) (*VirtualMachine id := VirtualMachineScaleSetIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil @@ -85,27 +85,27 @@ func ParseVirtualMachineScaleSetIPConfigurationIdInsensitively(input string) (*V id := VirtualMachineScaleSetIPConfigurationId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_machine_scale_set_network_interface.go b/resourcemanager/commonids/virtual_machine_scale_set_network_interface.go index b097c60..3fbc15b 100644 --- a/resourcemanager/commonids/virtual_machine_scale_set_network_interface.go +++ b/resourcemanager/commonids/virtual_machine_scale_set_network_interface.go @@ -44,23 +44,23 @@ func ParseVirtualMachineScaleSetNetworkInterfaceID(input string) (*VirtualMachin id := VirtualMachineScaleSetNetworkInterfaceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } return &id, nil @@ -79,23 +79,23 @@ func ParseVirtualMachineScaleSetNetworkInterfaceIDInsensitively(input string) (* id := VirtualMachineScaleSetNetworkInterfaceId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_machine_scale_set_public_ip_address.go b/resourcemanager/commonids/virtual_machine_scale_set_public_ip_address.go index 08bd433..d75b2a3 100644 --- a/resourcemanager/commonids/virtual_machine_scale_set_public_ip_address.go +++ b/resourcemanager/commonids/virtual_machine_scale_set_public_ip_address.go @@ -48,31 +48,31 @@ func ParseVirtualMachineScaleSetPublicIPAddressID(input string) (*VirtualMachine id := VirtualMachineScaleSetPublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } if id.PublicIpAddressName, ok = parsed.Parsed["publicIpAddressName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIpAddressName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIpAddressName", *parsed) } return &id, nil @@ -91,31 +91,31 @@ func ParseVirtualMachineScaleSetPublicIPAddressIDInsensitively(input string) (*V id := VirtualMachineScaleSetPublicIPAddressId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualMachineScaleSetName, ok = parsed.Parsed["virtualMachineScaleSetName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineScaleSetName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineScaleSetName", *parsed) } if id.VirtualMachineIndex, ok = parsed.Parsed["virtualMachineIndex"]; !ok { - return nil, fmt.Errorf("the segment 'virtualMachineIndex' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualMachineIndex", *parsed) } if id.NetworkInterfaceName, ok = parsed.Parsed["networkInterfaceName"]; !ok { - return nil, fmt.Errorf("the segment 'networkInterfaceName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "networkInterfaceName", *parsed) } if id.IpConfigurationName, ok = parsed.Parsed["ipConfigurationName"]; !ok { - return nil, fmt.Errorf("the segment 'ipConfigurationName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "ipConfigurationName", *parsed) } if id.PublicIpAddressName, ok = parsed.Parsed["publicIpAddressName"]; !ok { - return nil, fmt.Errorf("the segment 'publicIpAddressName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "publicIpAddressName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_network.go b/resourcemanager/commonids/virtual_network.go index 41e79ec..94177ac 100644 --- a/resourcemanager/commonids/virtual_network.go +++ b/resourcemanager/commonids/virtual_network.go @@ -40,15 +40,15 @@ func ParseVirtualNetworkID(input string) (*VirtualNetworkId, error) { id := VirtualNetworkId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualNetworkName, ok = parsed.Parsed["virtualNetworkName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualNetworkName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseVirtualNetworkIDInsensitively(input string) (*VirtualNetworkId, error) id := VirtualNetworkId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualNetworkName, ok = parsed.Parsed["virtualNetworkName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualNetworkName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_router_peering.go b/resourcemanager/commonids/virtual_router_peering.go index 015bf68..722c7b5 100644 --- a/resourcemanager/commonids/virtual_router_peering.go +++ b/resourcemanager/commonids/virtual_router_peering.go @@ -42,19 +42,19 @@ func ParseVirtualRouterPeeringID(input string) (*VirtualRouterPeeringId, error) id := VirtualRouterPeeringId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualRouterName, ok = parsed.Parsed["virtualRouterName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualRouterName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualRouterName", *parsed) } if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { - return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVirtualRouterPeeringIDInsensitively(input string) (*VirtualRouterPeeri id := VirtualRouterPeeringId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VirtualRouterName, ok = parsed.Parsed["virtualRouterName"]; !ok { - return nil, fmt.Errorf("the segment 'virtualRouterName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "virtualRouterName", *parsed) } if id.PeeringName, ok = parsed.Parsed["peeringName"]; !ok { - return nil, fmt.Errorf("the segment 'peeringName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway.go b/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway.go index b410e13..0e0ac76 100644 --- a/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway.go +++ b/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway.go @@ -40,15 +40,15 @@ func ParseVirtualWANP2SVPNGatewayID(input string) (*VirtualWANP2SVPNGatewayId, e id := VirtualWANP2SVPNGatewayId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.GatewayName, ok = parsed.Parsed["gatewayName"]; !ok { - return nil, fmt.Errorf("the segment 'gatewayName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil @@ -67,15 +67,15 @@ func ParseVirtualWANP2SVPNGatewayIDInsensitively(input string) (*VirtualWANP2SVP id := VirtualWANP2SVPNGatewayId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.GatewayName, ok = parsed.Parsed["gatewayName"]; !ok { - return nil, fmt.Errorf("the segment 'gatewayName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "peeringName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway_test.go b/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway_test.go new file mode 100644 index 0000000..cb40538 --- /dev/null +++ b/resourcemanager/commonids/virtual_wan_p2s_vpn_gateway_test.go @@ -0,0 +1,280 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package commonids + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = VirtualWANP2SVPNGatewayId{} + +func TestNewVirtualWANP2SVPNGatewayID(t *testing.T) { + id := NewVirtualWANP2SVPNGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.GatewayName != "gatewayName" { + t.Fatalf("Expected %q but got %q for Segment 'VMwareSiteName'", id.GatewayName, "gatewayName") + } +} + +func TestFormatVirtualWANP2SVPNGatewayID(t *testing.T) { + actual := NewVirtualWANP2SVPNGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways/gatewayName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVirtualWANP2SVPNGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualWANP2SVPNGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways/gatewayName", + Expected: &VirtualWANP2SVPNGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways/gatewayName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualWANP2SVPNGatewayID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + } +} + +func TestParseVirtualWANP2SVPNGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualWANP2SVPNGatewayId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/p2SvPnGaTeWaYs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways/gatewayValue", + Expected: &VirtualWANP2SVPNGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Network/p2sVpnGateways/gatewayValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/p2SvPnGaTeWaYs/gAtEwAyVaLuE", + Expected: &VirtualWANP2SVPNGatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.nEtWoRk/p2SvPnGaTeWaYs/gAtEwAyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualWANP2SVPNGatewayIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + } +} + +func TestSegmentsForVirtualWANP2SVPNGatewayId(t *testing.T) { + segments := VirtualWANP2SVPNGatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VirtualWANP2SVPNGatewayId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resourcemanager/commonids/vmware_site_job.go b/resourcemanager/commonids/vmware_site_job.go index 4888c18..5a2fbc2 100644 --- a/resourcemanager/commonids/vmware_site_job.go +++ b/resourcemanager/commonids/vmware_site_job.go @@ -42,19 +42,19 @@ func ParseVMwareSiteJobID(input string) (*VMwareSiteJobId, error) { id := VMwareSiteJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.JobName, ok = parsed.Parsed["jobName"]; !ok { - return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "jobName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVMwareSiteJobIDInsensitively(input string) (*VMwareSiteJobId, error) { id := VMwareSiteJobId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.JobName, ok = parsed.Parsed["jobName"]; !ok { - return nil, fmt.Errorf("the segment 'jobName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "jobName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/vmware_site_machine.go b/resourcemanager/commonids/vmware_site_machine.go index 44051da..6f8a00e 100644 --- a/resourcemanager/commonids/vmware_site_machine.go +++ b/resourcemanager/commonids/vmware_site_machine.go @@ -42,19 +42,19 @@ func ParseVMwareSiteMachineID(input string) (*VMwareSiteMachineId, error) { id := VMwareSiteMachineId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.MachineName, ok = parsed.Parsed["machineName"]; !ok { - return nil, fmt.Errorf("the segment 'machineName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "machineName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVMwareSiteMachineIDInsensitively(input string) (*VMwareSiteMachineId, id := VMwareSiteMachineId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.MachineName, ok = parsed.Parsed["machineName"]; !ok { - return nil, fmt.Errorf("the segment 'machineName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "machineName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/vmware_site_runasaccount.go b/resourcemanager/commonids/vmware_site_runasaccount.go index 23cebe0..9e01b84 100644 --- a/resourcemanager/commonids/vmware_site_runasaccount.go +++ b/resourcemanager/commonids/vmware_site_runasaccount.go @@ -42,19 +42,19 @@ func ParseVMwareSiteRunAsAccountID(input string) (*VMwareSiteRunAsAccountId, err id := VMwareSiteRunAsAccountId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.RunAsAccountName, ok = parsed.Parsed["runAsAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'runAsAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "runAsAccountName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVMwareSiteRunAsAccountIDInsensitively(input string) (*VMwareSiteRunAsA id := VMwareSiteRunAsAccountId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.VMwareSiteName, ok = parsed.Parsed["vmwareSiteName"]; !ok { - return nil, fmt.Errorf("the segment 'vmwareSiteName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "vmwareSiteName", *parsed) } if id.RunAsAccountName, ok = parsed.Parsed["runAsAccountName"]; !ok { - return nil, fmt.Errorf("the segment 'runAsAccountName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "runAsAccountName", *parsed) } return &id, nil diff --git a/resourcemanager/commonids/vpn_connection.go b/resourcemanager/commonids/vpn_connection.go index d2a6d09..de32b02 100644 --- a/resourcemanager/commonids/vpn_connection.go +++ b/resourcemanager/commonids/vpn_connection.go @@ -42,19 +42,19 @@ func ParseVPNConnectionID(input string) (*VPNConnectionId, error) { id := VPNConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.GatewayName, ok = parsed.Parsed["gatewayName"]; !ok { - return nil, fmt.Errorf("the segment 'gatewayName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", *parsed) } if id.ConnectionName, ok = parsed.Parsed["connectionName"]; !ok { - return nil, fmt.Errorf("the segment 'connectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "connectionName", *parsed) } return &id, nil @@ -73,19 +73,19 @@ func ParseVPNConnectionIDInsensitively(input string) (*VPNConnectionId, error) { id := VPNConnectionId{} if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", *parsed) } if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", *parsed) } if id.GatewayName, ok = parsed.Parsed["gatewayName"]; !ok { - return nil, fmt.Errorf("the segment 'gatewayName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", *parsed) } if id.ConnectionName, ok = parsed.Parsed["connectionName"]; !ok { - return nil, fmt.Errorf("the segment 'connectionName' was not found in the resource id %q", input) + return nil, resourceids.NewSegmentNotSpecifiedError(id, "connectionName", *parsed) } return &id, nil diff --git a/resourcemanager/commonschema/resource_id_reference.go b/resourcemanager/commonschema/resource_id_reference.go index 208465b..e882ec4 100644 --- a/resourcemanager/commonschema/resource_id_reference.go +++ b/resourcemanager/commonschema/resource_id_reference.go @@ -5,7 +5,7 @@ package commonschema import ( "fmt" - + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/resourcemanager/edgezones/model.go b/resourcemanager/edgezones/model.go index 3ce7fde..cc851ce 100644 --- a/resourcemanager/edgezones/model.go +++ b/resourcemanager/edgezones/model.go @@ -23,7 +23,7 @@ func (m *Model) MarshalJSON() ([]byte, error) { out["name"] = m.Name out["type"] = "EdgeZone" } - + return json.Marshal(out) } diff --git a/resourcemanager/identity/system_assigned_test.go b/resourcemanager/identity/system_assigned_test.go index d64db44..001eca1 100644 --- a/resourcemanager/identity/system_assigned_test.go +++ b/resourcemanager/identity/system_assigned_test.go @@ -9,16 +9,16 @@ import ( ) func TestSystemAssignedMarshal(t *testing.T) { - testData := []struct{ + testData := []struct { input *SystemAssigned expectedValue string }{ { - input: nil, + input: nil, expectedValue: "None", }, { - input: &SystemAssigned{}, + input: &SystemAssigned{}, expectedValue: "None", }, { diff --git a/resourcemanager/resourceids/error_number_of_segments_didnt_match.go b/resourcemanager/resourceids/error_number_of_segments_didnt_match.go new file mode 100644 index 0000000..af4e145 --- /dev/null +++ b/resourcemanager/resourceids/error_number_of_segments_didnt_match.go @@ -0,0 +1,59 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids + +import ( + "fmt" + "reflect" + "strings" +) + +var _ error = NumberOfSegmentsDidntMatchError{} + +type NumberOfSegmentsDidntMatchError struct { + parseResult ParseResult + resourceId ResourceId + resourceIdName string +} + +func NewNumberOfSegmentsDidntMatchError(id ResourceId, parseResult ParseResult) NumberOfSegmentsDidntMatchError { + // Resource ID types must be in the format {Name}Id + resourceIdName := strings.TrimSuffix(reflect.ValueOf(id).Type().Name(), "Id") + return NumberOfSegmentsDidntMatchError{ + parseResult: parseResult, + resourceId: id, + resourceIdName: resourceIdName, + } +} + +// Error returns a detailed error message highlighting the issues found when parsing this Resource ID Segment. +func (e NumberOfSegmentsDidntMatchError) Error() string { + expectedId := buildExpectedResourceId(e.resourceId.Segments()) + + description, err := descriptionForSegments(e.resourceId.Segments()) + if err != nil { + return fmt.Sprintf("internal-error: building description for segments: %+v", err) + } + + parsedSegments := summaryOfParsedSegments(e.parseResult, e.resourceId.Segments()) + + return fmt.Sprintf(`parsing the %[1]s ID: the number of segments didn't match + +Expected a %[1]s ID that matched (containing %[2]d segments): + +> %[3]s + +However this value was provided (which was parsed into %[4]d segments): + +> %[5]s + +The following Segments are expected: + +%[6]s + +The following Segments were parsed: + +%[7]s +`, e.resourceIdName, len(e.resourceId.Segments()), expectedId, len(e.parseResult.Parsed), e.parseResult.RawInput, *description, parsedSegments) +} diff --git a/resourcemanager/resourceids/error_number_of_segments_didnt_match_test.go b/resourcemanager/resourceids/error_number_of_segments_didnt_match_test.go new file mode 100644 index 0000000..190dea0 --- /dev/null +++ b/resourcemanager/resourceids/error_number_of_segments_didnt_match_test.go @@ -0,0 +1,84 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids_test + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +func TestNumberOfSegmentsDidntMatchError_CommonIdAllMissing(t *testing.T) { + id := commonids.ResourceGroupId{} + parseResult := resourceids.ParseResult{ + Parsed: map[string]string{}, + RawInput: "/some-value", + } + expected := ` +parsing the ResourceGroup ID: the number of segments didn't match + +Expected a ResourceGroup ID that matched (containing 4 segments): + +> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group + +However this value was provided (which was parsed into 0 segments): + +> /some-value + +The following Segments are expected: + +* Segment 0 - this should be the literal value "subscriptions" +* Segment 1 - this should be the UUID of the Azure Subscription +* Segment 2 - this should be the literal value "resourceGroups" +* Segment 3 - this should be the name of the Resource Group + +The following Segments were parsed: + +* Segment 0 - not found +* Segment 1 - not found +* Segment 2 - not found +* Segment 3 - not found +` + actual := resourceids.NewNumberOfSegmentsDidntMatchError(id, parseResult).Error() + assertTemplatedCodeMatches(t, expected, actual) +} + +func TestNumberOfSegmentsDidntMatchError_CommonIdMissingSegment(t *testing.T) { + id := commonids.ResourceGroupId{} + parseResult := resourceids.ParseResult{ + Parsed: map[string]string{ + "subscriptions": "subscriptions", + "subscriptionId": "1234", + }, + RawInput: "/subscriptions/1234/resourcegroups", + } + expected := ` +parsing the ResourceGroup ID: the number of segments didn't match + +Expected a ResourceGroup ID that matched (containing 4 segments): + +> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group + +However this value was provided (which was parsed into 2 segments): + +> /subscriptions/1234/resourcegroups + +The following Segments are expected: + +* Segment 0 - this should be the literal value "subscriptions" +* Segment 1 - this should be the UUID of the Azure Subscription +* Segment 2 - this should be the literal value "resourceGroups" +* Segment 3 - this should be the name of the Resource Group + +The following Segments were parsed: + +* Segment 0 - parsed as "subscriptions" +* Segment 1 - parsed as "1234" +* Segment 2 - not found +* Segment 3 - not found +` + actual := resourceids.NewNumberOfSegmentsDidntMatchError(id, parseResult).Error() + assertTemplatedCodeMatches(t, expected, actual) +} diff --git a/resourcemanager/resourceids/error_segment_not_specified.go b/resourcemanager/resourceids/error_segment_not_specified.go new file mode 100644 index 0000000..bc3a1ba --- /dev/null +++ b/resourcemanager/resourceids/error_segment_not_specified.go @@ -0,0 +1,59 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids + +import ( + "fmt" + "reflect" + "strings" +) + +var _ error = SegmentNotSpecifiedError{} + +type SegmentNotSpecifiedError struct { + parseResult ParseResult + resourceId ResourceId + resourceIdName string + segmentName string +} + +// NewSegmentNotSpecifiedError returns a SegmentNotSpecifiedError for the provided Resource ID, segment and parseResult combination +func NewSegmentNotSpecifiedError(id ResourceId, segmentName string, parseResult ParseResult) SegmentNotSpecifiedError { + // Resource ID types must be in the format {Name}Id + resourceIdName := strings.TrimSuffix(reflect.ValueOf(id).Type().Name(), "Id") + return SegmentNotSpecifiedError{ + resourceIdName: resourceIdName, + resourceId: id, + segmentName: segmentName, + parseResult: parseResult, + } +} + +// Error returns a detailed error message highlighting the issues found when parsing this Resource ID Segment. +func (e SegmentNotSpecifiedError) Error() string { + expectedId := buildExpectedResourceId(e.resourceId.Segments()) + position := findPositionOfSegment(e.segmentName, e.resourceId.Segments()) + if position == nil { + return fmt.Sprintf("internal-error: couldn't determine the position for segment %q", e.segmentName) + } + description, err := descriptionForSegment(e.segmentName, e.resourceId.Segments()) + if err != nil { + return fmt.Sprintf("internal-error: building description for segment: %+v", err) + } + + return fmt.Sprintf(`parsing the %[1]s ID: the segment at position %[2]d didn't match + +Expected a %[1]s ID that matched: + +> %[3]s + +However this value was provided: + +> %[4]s + +The parsed Resource ID was missing a value for the segment at position %[2]d +(which %[5]s). + +`, e.resourceIdName, *position, expectedId, e.parseResult.RawInput, *description) +} diff --git a/resourcemanager/resourceids/error_segment_not_specified_test.go b/resourcemanager/resourceids/error_segment_not_specified_test.go new file mode 100644 index 0000000..ccf7d68 --- /dev/null +++ b/resourcemanager/resourceids/error_segment_not_specified_test.go @@ -0,0 +1,270 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids_test + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// NOTE: most of the below tests reference the Id `planetId`, this is intentionally private for testing +// purposes and isn't being TitleCased because this shouldn't happen outside of testing + +func TestSegmentNotSpecifiedError_CommonId(t *testing.T) { + subId := commonids.ResourceGroupId{} + result := resourceids.ParseResult{ + RawInput: "/example", + } + actual := resourceids.NewSegmentNotSpecifiedError(subId, "resourceGroupName", result) + expected := `parsing the ResourceGroup ID: the segment at position 3 didn't match + +Expected a ResourceGroup ID that matched: + +> /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group + +However this value was provided: + +> /example + +The parsed Resource ID was missing a value for the segment at position 3 +(which should be the name of the Resource Group). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_MissingSegment(t *testing.T) { + subId := commonids.ResourceGroupId{} + result := resourceids.ParseResult{ + RawInput: "/example", + } + actual := resourceids.NewSegmentNotSpecifiedError(subId, "somethingRandom", result) + expected := `internal-error: couldn't determine the position for segment "somethingRandom"` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_Constant(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.ConstantSegment("planetName", []string{"earth", "mars"}, "earth"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "planetName", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/earth + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which should be a Constant with one of the following values ["earth", "mars"]). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_ResourceGroup(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resources"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/example-resources + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which should be the name of the Resource Group). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_ResourceProvider(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.ResourceProviderSegment("resourceProvider", "Example.ResourceProvider", "Example.ResourceProvider"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "resourceProvider", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/Example.ResourceProvider + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which should be the name of the Resource Provider [for example 'Example.ResourceProvider']). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_Scope(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.ScopeSegment("scopeSegment", "/some/scope/value"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "scopeSegment", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/some/scope/value + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which specifies the Resource ID that should be used as a Scope [for example '/some/scope/value']). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_Static(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resources"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/resourcegroups/example", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "resourceGroups", result) + expected := `parsing the planet ID: the segment at position 0 didn't match + +Expected a planet ID that matched: + +> /resourceGroups/example-resources + +However this value was provided: + +> /resourcegroups/example + +The parsed Resource ID was missing a value for the segment at position 0 +(which should be the literal value "resourceGroups"). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_SubscriptionId(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-1234-1234-1234567890123"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/12345678-1234-1234-1234-1234567890123 + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which should be the UUID of the Azure Subscription). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_UserSpecified(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "planets"), + resourceids.UserSpecifiedSegment("planetName", "example-planet"), + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "planetName", result) + expected := `parsing the planet ID: the segment at position 1 didn't match + +Expected a planet ID that matched: + +> /planets/example-planet + +However this value was provided: + +> /planets + +The parsed Resource ID was missing a value for the segment at position 1 +(which should be the user specified value for this planet [for example "example-planet"]). +` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +func TestSegmentNotSpecifiedError_UnknownType(t *testing.T) { + id := planetId{ + segments: []resourceids.Segment{ + { + Name: "nah", + Type: "does-not-matter", + }, + }, + } + result := resourceids.ParseResult{ + RawInput: "/planets", + } + actual := resourceids.NewSegmentNotSpecifiedError(id, "nah", result) + expected := `internal-error: building description for segment: internal-error: the Segment Type "does-not-matter" was not implemented for Segment "nah"` + assertTemplatedCodeMatches(t, expected, actual.Error()) +} + +var _ resourceids.ResourceId = planetId{} + +type planetId struct { + segments []resourceids.Segment +} + +func (p planetId) ID() string { + panic("should not be called in test") +} + +func (p planetId) String() string { + panic("should not be called in test") +} + +func (p planetId) Segments() []resourceids.Segment { + return p.segments +} diff --git a/resourcemanager/resourceids/errors.go b/resourcemanager/resourceids/errors.go new file mode 100644 index 0000000..2b01ce7 --- /dev/null +++ b/resourcemanager/resourceids/errors.go @@ -0,0 +1,143 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids + +import ( + "fmt" + "strings" +) + +// descriptionForSegments returns a summary/description for the provided Resource ID Segments +func descriptionForSegments(input []Segment) (*string, error) { + lines := make([]string, 0) + + for i, segment := range input { + description, err := descriptionForSpecifiedSegment(segment) + if err != nil { + return nil, fmt.Errorf("building description for segment %q: %+v", segment.Name, err) + } + + lines = append(lines, fmt.Sprintf("* Segment %d - this %s", i, *description)) + } + + out := strings.Join(lines, "\n") + return &out, nil +} + +// descriptionForSegment returns a friendly description for the Segment specified in segmentName +func descriptionForSegment(segmentName string, segments []Segment) (*string, error) { + for _, segment := range segments { + if segment.Name != segmentName { + continue + } + + return descriptionForSpecifiedSegment(segment) + } + + return nil, fmt.Errorf("the segment %q was not defined for this Resource ID", segmentName) +} + +// descriptionForSpecifiedSegment returns a friendly description for the Segment +func descriptionForSpecifiedSegment(segment Segment) (*string, error) { + // NOTE: do not use round brackets within these error messages, since this description can be contained within one + // the description will also be prefixed with a `which ` + switch segment.Type { + case ConstantSegmentType: + { + if segment.PossibleValues == nil { + return nil, fmt.Errorf("the Segment %q defined a Constant with no PossibleValues", segment.Name) + } + + // intentionally format these as quoted string values + values := make([]string, 0) + for _, v := range *segment.PossibleValues { + values = append(values, fmt.Sprintf("%q", v)) + } + + msg := fmt.Sprintf("should be a Constant with one of the following values [%s]", strings.Join(values, ", ")) + return &msg, nil + } + + case ResourceGroupSegmentType: + { + msg := "should be the name of the Resource Group" + return &msg, nil + } + + case ResourceProviderSegmentType: + { + msg := fmt.Sprintf("should be the name of the Resource Provider [for example '%s']", segment.ExampleValue) + return &msg, nil + } + + case ScopeSegmentType: + { + msg := fmt.Sprintf("specifies the Resource ID that should be used as a Scope [for example '%s']", segment.ExampleValue) + return &msg, nil + } + + case StaticSegmentType: + { + if segment.FixedValue == nil { + return nil, fmt.Errorf("the Segment %q defined a Static Segment with no FixedValue", segment.Name) + } + msg := fmt.Sprintf("should be the literal value %q", *segment.FixedValue) + return &msg, nil + } + + case SubscriptionIdSegmentType: + { + msg := "should be the UUID of the Azure Subscription" + return &msg, nil + } + + case UserSpecifiedSegmentType: + { + name := strings.TrimSuffix(segment.Name, "Name") + msg := fmt.Sprintf("should be the user specified value for this %s [for example %q]", name, segment.ExampleValue) + return &msg, nil + } + } + + return nil, fmt.Errorf("internal-error: the Segment Type %q was not implemented for Segment %q", string(segment.Type), segment.Name) +} + +// buildExpectedResourceId iterates over the Resource ID to build up the "expected" value for the Resource ID +// this is done using the example segment values for each segment type. +func buildExpectedResourceId(segments []Segment) string { + components := make([]string, 0) + for _, v := range segments { + components = append(components, strings.TrimPrefix(v.ExampleValue, "/")) + } + + out := strings.Join(components, "/") + return fmt.Sprintf("/%s", out) +} + +// findPositionOfSegment returns the position of the segment specified by segmentName within segments +func findPositionOfSegment(segmentName string, segments []Segment) *int { + for i, segment := range segments { + if segment.Name == segmentName { + return &i + } + } + + return nil +} + +// summaryOfParsedSegments returns a summary of the parsed Resource ID Segments vs what we're expecting +func summaryOfParsedSegments(parsed ParseResult, segments []Segment) string { + out := make([]string, 0) + for i, v := range segments { + val, ok := parsed.Parsed[v.Name] + if !ok { + out = append(out, fmt.Sprintf("* Segment %d - not found", i)) + continue + } + + out = append(out, fmt.Sprintf("* Segment %d - parsed as %q", i, val)) + } + + return strings.Join(out, "\n") +} diff --git a/resourcemanager/resourceids/helpers_test.go b/resourcemanager/resourceids/helpers_test.go new file mode 100644 index 0000000..9d63d7d --- /dev/null +++ b/resourcemanager/resourceids/helpers_test.go @@ -0,0 +1,72 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package resourceids_test + +import ( + "strings" + "testing" +) + +func assertTemplatedCodeMatches(t *testing.T, expected string, actual string) { + // when generating "for real" we run gofmt after it - whilst we + // could do that here, as the test data won't contain the other files + // as such comparing these line by line is fine for now + actualLines := splitLines(actual) + expectedLines := splitLines(expected) + + normalizedActualValue := strings.Join(actualLines, "\n") + normalizedExpectedValue := strings.Join(expectedLines, "\n") + + if len(actualLines) != len(expectedLines) { + t.Fatalf(`Expected %d lines but got %d lines. + +Expected Value: +--- +%s +--- + +Actual Value: +--- +%s +--- +`, len(expectedLines), len(actualLines), normalizedExpectedValue, normalizedActualValue) + } + + for i := 0; i < len(actualLines); i++ { + actualLine := actualLines[i] + expectedLine := expectedLines[i] + if !strings.EqualFold(strings.TrimSpace(actualLine), strings.TrimSpace(expectedLine)) { + t.Fatalf(`Expected and Actual differ on line %d + +Expected %q but got %q + +Expected Value: +--- +%s +--- + +Actual Value: +--- +%s +--- +`, i, expectedLine, actualLine, normalizedExpectedValue, normalizedActualValue) + } + } +} + +func splitLines(input string) []string { + // normalize the spacing and remove any empty lines, since they don't matter for testing + lines := strings.Split(strings.TrimSpace(input), "\n") + out := make([]string, 0) + for _, line := range lines { + line = strings.TrimSpace(line) + line = strings.ReplaceAll(line, "\t", " ") + if line == "" || line == "\n" { + continue + } + + out = append(out, line) + } + return out +} diff --git a/resourcemanager/resourceids/ids.go b/resourcemanager/resourceids/legacy.go similarity index 92% rename from resourcemanager/resourceids/ids.go rename to resourcemanager/resourceids/legacy.go index f17907e..2e36156 100644 --- a/resourcemanager/resourceids/ids.go +++ b/resourcemanager/resourceids/legacy.go @@ -9,6 +9,16 @@ import ( "strings" ) +// Id defines a type for a ResourceId of some kind +type Id interface { + // ID returns the fully formatted ID for this Resource ID + ID() string + + // String returns a friendly description of the components of this Resource ID + // which is suitable for use in error messages (for example 'MyThing %q / Resource Group %q') + String() string +} + // ResourceID represents a parsed long-form Azure Resource Manager ID // with the Subscription ID, Resource Group and the Provider as top- // level fields, and other key-value pairs available via a map in the diff --git a/resourcemanager/resourceids/old.go b/resourcemanager/resourceids/old.go deleted file mode 100644 index b167029..0000000 --- a/resourcemanager/resourceids/old.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package resourceids - -// Id defines a type for a ResourceId of some kind -type Id interface { - // ID returns the fully formatted ID for this Resource ID - ID() string - - // String returns a friendly description of the components of this Resource ID - // which is suitable for use in error messages (for example 'MyThing %q / Resource Group %q') - String() string -} diff --git a/resourcemanager/resourceids/parse.go b/resourcemanager/resourceids/parse.go index a27dfa7..f3d9742 100644 --- a/resourcemanager/resourceids/parse.go +++ b/resourcemanager/resourceids/parse.go @@ -13,35 +13,59 @@ type Parser struct { // segments is a slice containing the expected (ordered) segments which // should be present within this Resource ID segments []Segment -} -// NewParser takes a slice of Segments expected for this Resource ID -func NewParser(segments []Segment) Parser { - return Parser{ - segments: segments, - } + // resourceId is a reference to the Resource ID type + resourceId ResourceId } // NewParserFromResourceIdType takes a ResourceId interface and uses its (ordered) Segments // to create a Parser which can be used to Parse Resource ID's. func NewParserFromResourceIdType(id ResourceId) Parser { segments := id.Segments() - return NewParser(segments) + return Parser{ + resourceId: id, + segments: segments, + } } type ParseResult struct { // Parsed is a map of segmentName : segmentValue Parsed map[string]string + + // RawInput is the raw value that's been parsed to obtain Parsed + RawInput string +} + +// SegmentNamed returns the specified Resource ID segment by its name, if it exists +func (p ParseResult) SegmentNamed(key string, insensitively bool) (*string, bool) { + if !insensitively { + v, ok := p.Parsed[key] + if !ok { + return nil, false + } + return &v, ok + } + + for k := range p.Parsed { + if strings.EqualFold(k, key) { + val := p.Parsed[k] + return &val, true + } + } + + return nil, false } // Parse processes a Resource ID and parses it into a ParseResult containing a map of the // Known Segments for this Resource ID which callers of this method can then process to // form a Resource ID struct of those values doing any type conversions as necessary (for +// // example, type-casting/converting Constants). // // `input`: the Resource ID to be parsed, which should match the segments for this Resource ID // `insensitively`: should this Resource ID be parsed case-insensitively and fix up any Constant, -// Resource Provider and Static Segments to the expected casing. +// +// Resource Provider and Static Segments to the expected casing. func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { if input == "" { return nil, fmt.Errorf("cannot parse an empty string") @@ -56,10 +80,14 @@ func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { Parsed: map[string]string{ p.segments[0].Name: input, }, + RawInput: input, }, nil } - parsed := make(map[string]string) + parseResult := ParseResult{ + Parsed: make(map[string]string, 0), + RawInput: input, + } hasScopeAtStart := p.segments[0].Type == ScopeSegmentType hasScopeAtEnd := p.segments[len(p.segments)-1].Type == ScopeSegmentType @@ -113,7 +141,7 @@ func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { } scopePrefix = *prefix - parsed[p.segments[0].Name] = *prefix + parseResult.Parsed[p.segments[0].Name] = *prefix } // trim off the scopePrefix and the leading `/` to give us the segments we expect plus the final scope string @@ -131,7 +159,7 @@ func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { split := strings.Split(uri, "/") segmentCount := len(split) if segmentCount < len(p.segments) { - return nil, fmt.Errorf("expected %d segments within the Resource ID but got %d for %q", len(p.segments), segmentCount, input) + return nil, NewNumberOfSegmentsDidntMatchError(p.resourceId, parseResult) } if hasScopeAtStart { @@ -146,11 +174,11 @@ func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { // as we go around each of the segments we're expecting, process the value we should surface rawSegment := split[i] - value, err := p.parseSegment(segment, rawSegment, insensitively) + value, err := p.parseSegment(segment, rawSegment, insensitively, parseResult) if err != nil { return nil, fmt.Errorf("parsing segment %q: %+v", segment.Name, err) } - parsed[segment.Name] = *value + parseResult.Parsed[segment.Name] = *value // and then remove rawSegment from `uri` so that any leftovers is the scope // since if there's a scope there'll be more segments than we expect @@ -163,22 +191,18 @@ func (p Parser) Parse(input string, insensitively bool) (*ParseResult, error) { return nil, fmt.Errorf("unexpected segment %q present at the end of the URI (input %q)", uri, input) } - parsed[p.segments[len(p.segments)-1].Name] = fmt.Sprintf("/%s", uri) + parseResult.Parsed[p.segments[len(p.segments)-1].Name] = fmt.Sprintf("/%s", uri) } - - if len(p.segments) != len(parsed) { - return nil, fmt.Errorf("expected %d segments but got %d for %q", len(p.segments), len(parsed), input) + if len(p.segments) != len(parseResult.Parsed) { + return nil, NewNumberOfSegmentsDidntMatchError(p.resourceId, parseResult) } - for k, v := range parsed { + for k, v := range parseResult.Parsed { if v == "" { - return nil, fmt.Errorf("segment %q is required but got an empty value", k) + return nil, NewSegmentNotSpecifiedError(p.resourceId, k, parseResult) } } - - return &ParseResult{ - Parsed: parsed, - }, nil + return &parseResult, nil } func (p Parser) parseScopePrefix(input, regexForNonScopeSegments string, insensitively bool) (*string, error) { @@ -202,7 +226,7 @@ func (p Parser) parseScopePrefix(input, regexForNonScopeSegments string, insensi return &v, nil } -func (p Parser) parseSegment(segment Segment, rawValue string, insensitively bool) (*string, error) { +func (p Parser) parseSegment(segment Segment, rawValue string, insensitively bool, currentlyParsed ParseResult) (*string, error) { switch segment.Type { case ConstantSegmentType: { @@ -235,10 +259,10 @@ func (p Parser) parseSegment(segment Segment, rawValue string, insensitively boo } if matches { - return &*segment.FixedValue, nil + return segment.FixedValue, nil } - return nil, fmt.Errorf("expected the segment %q to be %q", rawValue, *segment.FixedValue) + return nil, NewSegmentNotSpecifiedError(p.resourceId, segment.Name, currentlyParsed) } case ScopeSegmentType: diff --git a/resourcemanager/resourceids/parse_test.go b/resourcemanager/resourceids/parse_test.go index 4c614e7..f25224e 100644 --- a/resourcemanager/resourceids/parse_test.go +++ b/resourcemanager/resourceids/parse_test.go @@ -1,16 +1,22 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -package resourceids +package resourceids_test import ( "reflect" "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) func TestParseEmptyId(t *testing.T) { t.Logf("Sensitively") - actual, err := NewParser([]Segment{}).Parse("", false) + rid := fakeIdParser{ + []resourceids.Segment{}, + } + parser := resourceids.NewParserFromResourceIdType(rid) + actual, err := parser.Parse("", false) if err == nil { t.Fatalf("expected an error but didn't get one") } @@ -19,7 +25,7 @@ func TestParseEmptyId(t *testing.T) { } t.Logf("Insensitively") - actual, err = NewParser([]Segment{}).Parse("", true) + actual, err = parser.Parse("", true) if err == nil { t.Fatalf("expected an error but didn't get one") } @@ -31,63 +37,67 @@ func TestParseEmptyId(t *testing.T) { func TestParseStaticId(t *testing.T) { testData := []struct { name string - segments []Segment - expected *ParseResult + segments []resourceids.Segment + expected *resourceids.ParseResult input string insensitively bool }{ { name: "single segment sensitive", - segments: []Segment{ - StaticSegment("hello", "hello", "example"), + segments: []resourceids.Segment{ + resourceids.StaticSegment("hello", "hello", "example"), }, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "hello": "hello", }, + RawInput: "/hello", }, input: "/hello", insensitively: false, }, { name: "single segment insensitive", - segments: []Segment{ - StaticSegment("hello", "hello", "example"), + segments: []resourceids.Segment{ + resourceids.StaticSegment("hello", "hello", "example"), }, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "hello": "hello", }, + RawInput: "/Hello", }, input: "/Hello", insensitively: true, }, { name: "multiple segments sensitive", - segments: []Segment{ - StaticSegment("hello", "hello", "example"), - StaticSegment("there", "there", "example"), + segments: []resourceids.Segment{ + resourceids.StaticSegment("hello", "hello", "example"), + resourceids.StaticSegment("there", "there", "example"), }, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "hello": "hello", "there": "there", }, + RawInput: "/hello/there", }, input: "/hello/there", insensitively: false, }, { name: "multiple segments sensitive", - segments: []Segment{ - StaticSegment("hello", "hello", "example"), - StaticSegment("there", "there", "example"), + segments: []resourceids.Segment{ + resourceids.StaticSegment("hello", "hello", "example"), + resourceids.StaticSegment("there", "there", "example"), }, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "hello": "hello", "there": "there", }, + RawInput: "/Hello/tHere", }, input: "/Hello/tHere", insensitively: true, @@ -95,23 +105,26 @@ func TestParseStaticId(t *testing.T) { } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(test.segments) + rid := fakeIdParser{ + test.segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitively) validateResult(t, actual, test.expected, err) } } func TestParseResourceGroupId(t *testing.T) { - segments := []Segment{ - StaticSegment("subscriptions", "subscriptions", "example"), - SubscriptionIdSegment("subscriptionId", "example"), - StaticSegment("resourceGroups", "resourceGroups", "example"), - ResourceGroupSegment("resourceGroupName", "example"), + segments := []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "example"), + resourceids.SubscriptionIdSegment("subscriptionId", "example"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "example"), + resourceids.ResourceGroupSegment("resourceGroupName", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -168,52 +181,57 @@ func TestParseResourceGroupId(t *testing.T) { name: "resource group id - sensitive", input: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", "resourceGroupName": "BoB", }, + RawInput: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB", }, }, { name: "resource groups id - insensitive", input: "/subscRiptions/11112222-3333-4444-555566667777/resourcegroups/BoB", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", "resourceGroupName": "BoB", }, + RawInput: "/subscRiptions/11112222-3333-4444-555566667777/resourcegroups/BoB", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseVirtualMachineId(t *testing.T) { - segments := []Segment{ - StaticSegment("subscriptions", "subscriptions", "example"), - SubscriptionIdSegment("subscriptionId", "example"), - StaticSegment("resourceGroups", "resourceGroups", "example"), - ResourceGroupSegment("resourceGroupName", "example"), - StaticSegment("providers", "providers", "example"), - ResourceProviderSegment("provider", "Microsoft.Compute", "example"), - StaticSegment("virtualMachines", "virtualMachines", "example"), - UserSpecifiedSegment("virtualMachineName", "example"), + segments := []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "example"), + resourceids.SubscriptionIdSegment("subscriptionId", "example"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "example"), + resourceids.ResourceGroupSegment("resourceGroupName", "example"), + resourceids.StaticSegment("providers", "providers", "example"), + resourceids.ResourceProviderSegment("provider", "Microsoft.Compute", "example"), + resourceids.StaticSegment("virtualMachines", "virtualMachines", "example"), + resourceids.UserSpecifiedSegment("virtualMachineName", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -270,8 +288,8 @@ func TestParseVirtualMachineId(t *testing.T) { name: "virtual machine id - sensitive", input: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Compute/virtualMachines/machine1", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", @@ -281,14 +299,15 @@ func TestParseVirtualMachineId(t *testing.T) { "virtualMachines": "virtualMachines", "virtualMachineName": "machine1", }, + RawInput: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Compute/virtualMachines/machine1", }, }, { name: "virtual machine id - insensitive", input: "/subScriptions/11112222-3333-4444-555566667777/resourcegroups/BoB/pRoviders/microsoft.Compute/virtualmachines/machine1", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", @@ -298,6 +317,7 @@ func TestParseVirtualMachineId(t *testing.T) { "virtualMachines": "virtualMachines", "virtualMachineName": "machine1", }, + RawInput: "/subScriptions/11112222-3333-4444-555566667777/resourcegroups/BoB/pRoviders/microsoft.Compute/virtualmachines/machine1", }, }, { @@ -313,29 +333,32 @@ func TestParseVirtualMachineId(t *testing.T) { } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseVirtualMachineExtensionId(t *testing.T) { - segments := []Segment{ - StaticSegment("subscriptions", "subscriptions", "example"), - SubscriptionIdSegment("subscriptionId", "example"), - StaticSegment("resourceGroups", "resourceGroups", "example"), - ResourceGroupSegment("resourceGroupName", "example"), - StaticSegment("providers", "providers", "example"), - ResourceProviderSegment("provider", "Microsoft.Compute", "example"), - StaticSegment("virtualMachines", "virtualMachines", "example"), - UserSpecifiedSegment("virtualMachineName", "example"), - StaticSegment("extensions", "extensions", "example"), - UserSpecifiedSegment("extensionName", "example"), + segments := []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "example"), + resourceids.SubscriptionIdSegment("subscriptionId", "example"), + resourceids.StaticSegment("resourceGroups", "resourceGroups", "example"), + resourceids.ResourceGroupSegment("resourceGroupName", "example"), + resourceids.StaticSegment("providers", "providers", "example"), + resourceids.ResourceProviderSegment("provider", "Microsoft.Compute", "example"), + resourceids.StaticSegment("virtualMachines", "virtualMachines", "example"), + resourceids.UserSpecifiedSegment("virtualMachineName", "example"), + resourceids.StaticSegment("extensions", "extensions", "example"), + resourceids.UserSpecifiedSegment("extensionName", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -372,8 +395,8 @@ func TestParseVirtualMachineExtensionId(t *testing.T) { name: "virtual machine extension id - sensitive", input: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Compute/virtualMachines/machine1/extensions/extension1", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", @@ -385,14 +408,15 @@ func TestParseVirtualMachineExtensionId(t *testing.T) { "extensions": "extensions", "extensionName": "extension1", }, + RawInput: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Compute/virtualMachines/machine1/extensions/extension1", }, }, { name: "resource groups id - insensitive", input: "/subScriptions/11112222-3333-4444-555566667777/resourcegroups/BoB/pRoviders/microsoft.Compute/virtualmachines/machine1/exTensions/extension1", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "subscriptions": "subscriptions", "subscriptionId": "11112222-3333-4444-555566667777", "resourceGroups": "resourceGroups", @@ -404,43 +428,48 @@ func TestParseVirtualMachineExtensionId(t *testing.T) { "extensions": "extensions", "extensionName": "extension1", }, + RawInput: "/subScriptions/11112222-3333-4444-555566667777/resourcegroups/BoB/pRoviders/microsoft.Compute/virtualmachines/machine1/exTensions/extension1", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseAdvancedThreatProtectionId(t *testing.T) { - segments := []Segment{ - ScopeSegment("scope", "example"), - StaticSegment("providers", "providers", "example"), - ResourceProviderSegment("provider", "Microsoft.Security", "example"), - StaticSegment("advancedThreatProtectionSettings", "advancedThreatProtectionSettings", "example"), - UserSpecifiedSegment("name", "example"), + segments := []resourceids.Segment{ + resourceids.ScopeSegment("scope", "example"), + resourceids.StaticSegment("providers", "providers", "example"), + resourceids.ResourceProviderSegment("provider", "Microsoft.Security", "example"), + resourceids.StaticSegment("advancedThreatProtectionSettings", "advancedThreatProtectionSettings", "example"), + resourceids.UserSpecifiedSegment("name", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { name: "resource group id - sensitive", input: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Security/advancedThreatProtectionSettings/someName", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB", "providers": "providers", "provider": "Microsoft.Security", "advancedThreatProtectionSettings": "advancedThreatProtectionSettings", "name": "someName", }, + RawInput: "/subscriptions/11112222-3333-4444-555566667777/resourceGroups/BoB/providers/Microsoft.Security/advancedThreatProtectionSettings/someName", }, }, { @@ -452,14 +481,15 @@ func TestParseAdvancedThreatProtectionId(t *testing.T) { name: "resource group id - insensitive", input: "/subscripTions/11112222-3333-4444-555566667777/resourcEgroups/BoB/proviDers/Microsoft.security/advancedthreatProtectionSettings/someName", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/subscripTions/11112222-3333-4444-555566667777/resourcEgroups/BoB", "providers": "providers", "provider": "Microsoft.Security", "advancedThreatProtectionSettings": "advancedThreatProtectionSettings", "name": "someName", }, + RawInput: "/subscripTions/11112222-3333-4444-555566667777/resourcEgroups/BoB/proviDers/Microsoft.security/advancedthreatProtectionSettings/someName", }, }, { @@ -476,14 +506,15 @@ func TestParseAdvancedThreatProtectionId(t *testing.T) { name: "virtual machine id - sensitive", input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1/providers/Microsoft.Security/advancedThreatProtectionSettings/someName", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1", "providers": "providers", "provider": "Microsoft.Security", "advancedThreatProtectionSettings": "advancedThreatProtectionSettings", "name": "someName", }, + RawInput: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1/providers/Microsoft.Security/advancedThreatProtectionSettings/someName", }, }, { @@ -495,34 +526,38 @@ func TestParseAdvancedThreatProtectionId(t *testing.T) { name: "virtual machine id - insensitive", input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1/Providers/Microsoft.SecuRity/advancedThreatprotectionSettings/someName", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1", "providers": "providers", "provider": "Microsoft.Security", "advancedThreatProtectionSettings": "advancedThreatProtectionSettings", "name": "someName", }, + RawInput: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1/Providers/Microsoft.SecuRity/advancedThreatprotectionSettings/someName", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseIdContainingAConstant(t *testing.T) { - segments := []Segment{ - StaticSegment("planets", "planets", "example"), - ConstantSegment("planetName", []string{"Mars", "Earth"}, "example"), + segments := []resourceids.Segment{ + resourceids.StaticSegment("planets", "planets", "example"), + resourceids.ConstantSegment("planetName", []string{"Mars", "Earth"}, "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -539,44 +574,48 @@ func TestParseIdContainingAConstant(t *testing.T) { name: "planets - earth - sensitive", input: "/planets/Earth", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "planets": "planets", "planetName": "Earth", }, + RawInput: "/planets/Earth", }, }, { name: "planets - earth - insensitive", input: "/planets/earth", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "planets": "planets", "planetName": "Earth", }, + RawInput: "/planets/earth", }, }, { name: "planets - mars - sensitive", input: "/planets/Mars", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "planets": "planets", "planetName": "Mars", }, + RawInput: "/planets/Mars", }, }, { name: "planets - mars - insensitive", input: "/planets/mars", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "planets": "planets", "planetName": "Mars", }, + RawInput: "/planets/mars", }, }, { @@ -592,22 +631,25 @@ func TestParseIdContainingAConstant(t *testing.T) { } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseIdContainingAScopePrefix(t *testing.T) { - segments := []Segment{ - ScopeSegment("scope", "example"), - StaticSegment("extensions", "extensions", "example"), - UserSpecifiedSegment("extensionName", "example"), + segments := []resourceids.Segment{ + resourceids.ScopeSegment("scope", "example"), + resourceids.StaticSegment("extensions", "extensions", "example"), + resourceids.UserSpecifiedSegment("extensionName", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -624,69 +666,76 @@ func TestParseIdContainingAScopePrefix(t *testing.T) { name: "scope - single level - sensitive", input: "/planets/extensions/terraform", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/planets", "extensions": "extensions", "extensionName": "terraform", }, + RawInput: "/planets/extensions/terraform", }, }, { name: "scope - single level - insensitive", input: "/planets/extenSions/terraform", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/planets", "extensions": "extensions", "extensionName": "terraform", }, + RawInput: "/planets/extenSions/terraform", }, }, { name: "scope - multiple level - sensitive", input: "/solarSystems/milkyWay/planets/mars/extensions/terraform", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/solarSystems/milkyWay/planets/mars", "extensions": "extensions", "extensionName": "terraform", }, + RawInput: "/solarSystems/milkyWay/planets/mars/extensions/terraform", }, }, { name: "scope - multiple level - insensitive", input: "/solarSystems/milkyWay/planets/mars/extenSions/terraform", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/solarSystems/milkyWay/planets/mars", "extensions": "extensions", "extensionName": "terraform", }, + RawInput: "/solarSystems/milkyWay/planets/mars/extenSions/terraform", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseIdContainingAScopeSuffix(t *testing.T) { - segments := []Segment{ - StaticSegment("subscriptions", "subscriptions", "example"), - SubscriptionIdSegment("subscriptionId", "example"), - ScopeSegment("scope", "example"), + segments := []resourceids.Segment{ + resourceids.StaticSegment("subscriptions", "subscriptions", "example"), + resourceids.SubscriptionIdSegment("subscriptionId", "example"), + resourceids.ScopeSegment("scope", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -703,70 +752,77 @@ func TestParseIdContainingAScopeSuffix(t *testing.T) { name: "scope - single level - sensitive", input: "/subscriptions/1111/someThing", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/someThing", "subscriptions": "subscriptions", "subscriptionId": "1111", }, + RawInput: "/subscriptions/1111/someThing", }, }, { name: "scope - single level - insensitive", input: "/subscrIptions/1111/someThing", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/someThing", "subscriptions": "subscriptions", "subscriptionId": "1111", }, + RawInput: "/subscrIptions/1111/someThing", }, }, { name: "scope - multiple level - sensitive", input: "/subscriptions/1111/solarSystems/milkyWay/planets/mars", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/solarSystems/milkyWay/planets/mars", "subscriptions": "subscriptions", "subscriptionId": "1111", }, + RawInput: "/subscriptions/1111/solarSystems/milkyWay/planets/mars", }, }, { name: "scope - multiple level - insensitive", input: "/subscriPtions/1111/solarSystems/milkyWay/planets/mars", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/solarSystems/milkyWay/planets/mars", "subscriptions": "subscriptions", "subscriptionId": "1111", }, + RawInput: "/subscriPtions/1111/solarSystems/milkyWay/planets/mars", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseIdContainingAScopeEitherEnd(t *testing.T) { - segments := []Segment{ - ScopeSegment("start", "example"), - StaticSegment("connections", "connections", "example"), - SubscriptionIdSegment("connectionName", "example"), - ScopeSegment("end", "example"), + segments := []resourceids.Segment{ + resourceids.ScopeSegment("start", "example"), + resourceids.StaticSegment("connections", "connections", "example"), + resourceids.SubscriptionIdSegment("connectionName", "example"), + resourceids.ScopeSegment("end", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -803,71 +859,78 @@ func TestParseIdContainingAScopeEitherEnd(t *testing.T) { name: "scope - single level - sensitive", input: "/someThing/connections/BER-FCO/someOtherThing", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "connectionName": "BER-FCO", "connections": "connections", "end": "/someOtherThing", "start": "/someThing", }, + RawInput: "/someThing/connections/BER-FCO/someOtherThing", }, }, { name: "scope - single level - insensitive", input: "/someThing/Connections/BER-FCO/someOtherThing", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "connectionName": "BER-FCO", "connections": "connections", "end": "/someOtherThing", "start": "/someThing", }, + RawInput: "/someThing/Connections/BER-FCO/someOtherThing", }, }, { name: "scope - multiple level - sensitive", input: "/someThing/thats/really/awesome/connections/BER-FCO/someOtherThing/woah", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "connectionName": "BER-FCO", "connections": "connections", "end": "/someOtherThing/woah", "start": "/someThing/thats/really/awesome", }, + RawInput: "/someThing/thats/really/awesome/connections/BER-FCO/someOtherThing/woah", }, }, { name: "scope - multiple level - insensitive", input: "/someThing/thats/really/awesome/conNections/BER-FCO/someOtherThing/woah", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "connectionName": "BER-FCO", "connections": "connections", "end": "/someOtherThing/woah", "start": "/someThing/thats/really/awesome", }, + RawInput: "/someThing/thats/really/awesome/conNections/BER-FCO/someOtherThing/woah", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } func TestParseIdContainingJustAScope(t *testing.T) { - segments := []Segment{ - ScopeSegment("scope", "example"), + segments := []resourceids.Segment{ + resourceids.ScopeSegment("scope", "example"), } testData := []struct { name string input string - expected *ParseResult + expected *resourceids.ParseResult insensitive bool }{ { @@ -879,72 +942,99 @@ func TestParseIdContainingJustAScope(t *testing.T) { name: "slash - sensitive", input: "/", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/", }, + RawInput: "/", }, }, { name: "slash - insensitive", input: "/", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/", }, + RawInput: "/", }, }, { name: "single level - sensitive", input: "/hello", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/hello", }, + RawInput: "/hello", }, }, { name: "single level - insensitive", input: "/hello", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/hello", }, + RawInput: "/hello", }, }, { name: "multiple levels - sensitive", input: "/hello/there/world", insensitive: false, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/hello/there/world", }, + RawInput: "/hello/there/world", }, }, { name: "multiple levels - insensitive", input: "/hello/there/world", insensitive: true, - expected: &ParseResult{ - map[string]string{ + expected: &resourceids.ParseResult{ + Parsed: map[string]string{ "scope": "/hello/there/world", }, + RawInput: "/hello/there/world", }, }, } for _, test := range testData { t.Logf("Test %q..", test.name) - parser := NewParser(segments) + rid := fakeIdParser{ + segments, + } + parser := resourceids.NewParserFromResourceIdType(rid) actual, err := parser.Parse(test.input, test.insensitive) validateResult(t, actual, test.expected, err) } } -func validateResult(t *testing.T, actual *ParseResult, expected *ParseResult, err error) { +var _ resourceids.ResourceId = fakeIdParser{} + +type fakeIdParser struct { + segments []resourceids.Segment +} + +func (f fakeIdParser) ID() string { + panic("shouldn't be called in test") +} + +func (f fakeIdParser) String() string { + panic("shouldn't be called in test") +} + +func (f fakeIdParser) Segments() []resourceids.Segment { + return f.segments +} + +func validateResult(t *testing.T, actual *resourceids.ParseResult, expected *resourceids.ParseResult, err error) { if err != nil { if expected == nil { return @@ -970,4 +1060,7 @@ func validateResult(t *testing.T, actual *ParseResult, expected *ParseResult, er if !reflect.DeepEqual(expected.Parsed, actual.Parsed) { t.Fatalf("Diff between Expected and Actual.\n\nExpected: %+v\n\nActual: %+v", expected.Parsed, actual.Parsed) } + if expected.RawInput != actual.RawInput { + t.Fatalf("Diff between Expected and Actual RawInput.\n\nExpected: %q\nActual:%q", expected.RawInput, actual.RawInput) + } } diff --git a/resourcemanager/tags/flatten.go b/resourcemanager/tags/flatten.go index 5e95585..63f9670 100644 --- a/resourcemanager/tags/flatten.go +++ b/resourcemanager/tags/flatten.go @@ -5,6 +5,7 @@ package tags import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" )