Maybe someone can stop me if there's an easier way.
I need to get the private ip of a running VM. As far as I can tell, I have to retrieve the VM and inspect the VirtualMachineProperties which only includes a reference to the nic NetworkInterfaceReference whose ID is going to be in the form /subscriptions/27b750cd-ed43-42fd-9044-8d75e124ae55/resourceGroups/cm-kube-ubuntu/providers/Microsoft.Network/networkInterfaces/master199.
Thus, to get the actual network interface, I need to call InterfacesClient.Get which requires the resourceGroup and networkInterfaceName as parameters.
This requires some string decomposition on the user's part. Similarly, when placing a nic into a load balancer backend, the user must _compose_ the full identifier of the LoadBalancer resource.
Thus, it seems like we might want to write, test, and ship some utilities for doing these string manipulations. I'm more or less going to have to write some of them for the work I'm doing, unless there's another way about this that I'm missing.
+1 on the pain point, however I don't think this should be requiring extra tooling. I feel like there is a gap in the design (apparently nobody gave a serious thought about doing these operations).
Clearly, as discussed above and in the other thread, this is just a Band-Aid for a larger issue. However, this is not a "Won't Fix" as it would make a meaningful improvement in the short-term if we could fix it. I'll put this on the Backlog.
Closing as stale. If this is still a real issue please reopen.
I think it would be good to keep this on the backlog. Look at any projects that non-trivially uses the Go SDK and they have to include these annoying-to-author/maintain helper utility functions for ripping apart and concatenating Azure identifiers. The Azure cloudprovider implementation in Kubernetes is a good example. I believe the azurerm module in Terraform has it's own set of them.
They're something that could be entirely code-gen'd and would be a significant QoL improvement for the SDK.
I'd like to add a +1 to re-opening this - we're currently doing this by hand and it's painful, so some method for this would be really useful (both splitting of values out from the URI and for forming a URI for a resource without necessarily calling the Get method / making an HTTP call).
@colemickens @tombuildsstuff can either of you provide a link or two to your hand-written code that does this?
Deconstruct IDs:
Construct resource IDs:
You can look at where these are used. It's not like the code is doing anything particularly weird with regards to the SDK.
It's probably a separate issue, but we also wrapped calls so that we could distinguish between 404s and "errors": https://github.com/kubernetes/kubernetes/blob/master/pkg/cloudprovider/providers/azure/azure_wrap.go This is also something the SDK could probably auto-generate and allow users to opt-into if they like.
We've added azure.ParseResourceID in go-autorest version v10.4.0 to deconstruct an Azure resource ID.
This might not be the right issue related to the problem I am seeing but its the closest one. I am trying to get the name of the Network Interface from the NetworkInterfaceReference but unable to parse the *i.NetworkProfile.NetworkInterfaces which gets printed as [{
Most helpful comment
We've added
azure.ParseResourceIDin go-autorest version v10.4.0 to deconstruct an Azure resource ID.