You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Composite Resource IDs are two Resource IDs combined together with a pipe character (e.g. {first}|{second}) and are used in the AzureRM Provider primarily for Virtual Resources which map 1:1 - for example the association resources.
Whilst every time we need one of these today we end up reimplementing the same logic, we should be able to use Generics to have a single Composite Resource ID which both implements the ResourceId interface, but also takes two generic arguments for the ResourceId type, for example:
// to ensure this implements `.ID()` and `.String()` so this can be used as a regular Resource IDvar_ resourceids.ResourceID=CompositeResourceID[resourceids.ResourceId, resourceids.ResourceID]{}
typeCompositeResourceID[T1 resourceids.ResourceId, T2 resourceids.ResourceID] struct {
FirstT1SecondT2
}
However where this currently falls down is the way that ResourceID Parsing is done, where the resourceids.Parser.Parse method returns a ParseResult, which is a mapping of the Resource ID Segment Name : Values - which must be then assigned to the Fields within each struct, which isn't currently possible without calling the specific Parse functions for T1 and T2 above.
As such, this work is dependent on #190, which adds a new FromParseResult method to the resourceids.ResourceId interface, but once that's available it should be possible to make a generic Parse function similar to below:
funcParse[resourceids.ResourceId, T2 resourceids.ResourceID](inputstring) (*CompositeResourceID[T1, T2], error) {
components:=strings.Split(input, "|")
iflen(components) !=2 {
// TODO
}
output:=CompositeResourceID[T1, T2]{}
// Parse the first of the two Resource IDs from the componentsfirstParser:=resourceids.NewParserFromResourceIdType(T1{})
firstParseResult, err:=firstParser.Parse(components[0], false)
iferr!=nil {
// TODO
}
first, err:=T1{}.FromParseResult(firstParseResult.ParseResult)
iferr!=nil {
// TODO
}
output.First=first// ...
}
Which would mean that the code used in the Provider can be reduced from:
components:=strings.Split(d.GetID(), "|")
iflen(components) !=2 {
// TODO
}
first, err:=ParseFirstID(components[0])
iferr!=nil {
// TODO
}
second, err:=ParseSecondID(components[1])
iferr!=nil {
// TODO
}
To the same as used elsewhere in the Provider:
id, err:=ParseCompositeResourceID[FirstId, SecondId](d.GetID())
iferr!=nil {
// TODO
}
The text was updated successfully, but these errors were encountered:
Composite Resource IDs are two Resource IDs combined together with a pipe character (e.g.
{first}|{second}
) and are used in the AzureRM Provider primarily for Virtual Resources which map 1:1 - for example theassociation
resources.Whilst every time we need one of these today we end up reimplementing the same logic, we should be able to use Generics to have a single Composite Resource ID which both implements the
ResourceId
interface, but also takes two generic arguments for the ResourceId type, for example:However where this currently falls down is the way that ResourceID Parsing is done, where the
resourceids.Parser.Parse
method returns aParseResult
, which is a mapping of the Resource ID Segment Name : Values - which must be then assigned to the Fields within each struct, which isn't currently possible without calling the specific Parse functions forT1
andT2
above.As such, this work is dependent on #190, which adds a new
FromParseResult
method to theresourceids.ResourceId
interface, but once that's available it should be possible to make a generic Parse function similar to below:Which would mean that the code used in the Provider can be reduced from:
To the same as used elsewhere in the Provider:
The text was updated successfully, but these errors were encountered: