// parseAzureResourceID converts a long-form Azure Resource Manager ID
// into a ResourceID. We make assumptions about the structure of URLs,
// which is obviously not good, but the best thing available given the
// SDK.
167200
func ParseAzureResourceID(id string) (*ResourceID, error) {
	idURL, err := url.ParseRequestURI(id)
	if err != nil {
		return nil, fmt.Errorf("Cannot parse Azure ID: %s", err)
	}

	path := idURL.Path

	path = strings.TrimPrefix(path, "/")
	path = strings.TrimSuffix(path, "/")

	components := strings.Split(path, "/")

	// We should have an even number of key-value pairs.
	if len(components)%2 != 0 {
		return nil, fmt.Errorf("The number of path segments is not divisible by 2 in %q", path)
	}

	var subscriptionID string

	// Put the constituent key-value pairs into a map
	componentMap := make(map[string]string, len(components)/2)
	for current := 0; current < len(components); current += 2 {
		key := components[current]
		value := components[current+1]

		// Check key/value for empty strings.
		if key == "" || value == "" {
			return nil, fmt.Errorf("Key/Value cannot be empty strings. Key: '%s', Value: '%s'", key, value)
		}

		// Catch the subscriptionID before it can be overwritten by another "subscriptions"
		// value in the ID which is the case for the Service Bus subscription resource
		if key == "subscriptions" && subscriptionID == "" {
			subscriptionID = value
		} else {
			componentMap[key] = value
		}
	}

	// Build up a ResourceID from the map
	idObj := &ResourceID{}
	idObj.Path = componentMap

	if subscriptionID != "" {
		idObj.SubscriptionID = subscriptionID
	} else {
		return nil, fmt.Errorf("No subscription ID found in: %q", path)
	}

	if resourceGroup, ok := componentMap["resourceGroups"]; ok {
		idObj.ResourceGroup = resourceGroup
		delete(componentMap, "resourceGroups")
	} else {
		// Some Azure APIs are weird and provide things in lower case...
		// However it's not clear whether the casing of other elements in the URI
		// matter, so we explicitly look for that case here.
		if resourceGroup, ok := componentMap["resourcegroups"]; ok {
			idObj.ResourceGroup = resourceGroup
			delete(componentMap, "resourcegroups")
		} else {
			return nil, fmt.Errorf("No resource group name found in: %q", path)
		}
	}

	// It is OK not to have a provider in the case of a resource group
	if provider, ok := componentMap["providers"]; ok {
		idObj.Provider = provider
		delete(componentMap, "providers")
	}

	return idObj, nil
}
786446
func (s *PutMethodResponseInput) SetResourceId(v string) *PutMethodResponseInput {
	s.ResourceId = &v
	return s
}
389679
func (s *PutComplianceItemsInput) SetResourceId(v string) *PutComplianceItemsInput {
	s.ResourceId = &v
	return s
}
949182
func (s *DescribeScheduledActionsInput) SetResourceId(v string) *DescribeScheduledActionsInput {
	s.ResourceId = &v
	return s
}
410812
func (s *DeregisterScalableTargetInput) SetResourceId(v string) *DeregisterScalableTargetInput {
	s.ResourceId = &v
	return s
}
92650
func ParseResourceIDOptionalNamespace(namespace, s string) (ResourceID, error) {
	if m := ResourceIDRegexp.FindStringSubmatch(s); m != nil {
		return ResourceID{resourceID{m[1], strings.ToLower(m[2]), m[3]}}, nil
	}
	if m := UnqualifiedResourceIDRegexp.FindStringSubmatch(s); m != nil {
		return ResourceID{resourceID{namespace, strings.ToLower(m[1]), m[2]}}, nil
	}
	return ResourceID{}, errors.Wrap(ErrInvalidServiceID, "parsing "+s)
}
683472
func (s *DescribeScalingActivitiesInput) SetResourceId(v string) *DescribeScalingActivitiesInput {
	s.ResourceId = &v
	return s
}
1300886
func (s *ResourceComplianceSummaryItem) SetResourceId(v string) *ResourceComplianceSummaryItem {
	s.ResourceId = &v
	return s
}
42707
func (s *BaseConfigurationItem) SetResourceId(v string) *BaseConfigurationItem {
	s.ResourceId = &v
	return s
}
1314963
func (s *UpdateIntegrationResponseInput) SetResourceId(v string) *UpdateIntegrationResponseInput {
	s.ResourceId = &v
	return s
}
1070575
func MustParseResourceID(s string) ResourceID {
	id, err := ParseResourceID(s)
	if err != nil {
		panic(err)
	}
	return id
}
157448
func (s *ListTagsForResourceInput) SetResourceId(v string) *ListTagsForResourceInput {
	s.ResourceId = &v
	return s
}
1249700
func (s *ClientPropertiesResult) SetResourceId(v string) *ClientPropertiesResult {
	s.ResourceId = &v
	return s
}
259516
func (s *ListResourceDelegatesInput) SetResourceId(v string) *ListResourceDelegatesInput {
	s.ResourceId = &v
	return s
}
408841
func (s *ResourceTag) SetResourceId(v string) *ResourceTag {
	s.ResourceId = &v
	return s
}
224441
func (s *DisassociateTagOptionFromResourceInput) SetResourceId(v string) *DisassociateTagOptionFromResourceInput {
	s.ResourceId = &v
	return s
}
369573
func (s *TrustedAdvisorResourceDetail) SetResourceId(v string) *TrustedAdvisorResourceDetail {
	s.ResourceId = &v
	return s
}