func GetSubnetId()

in src/go/cmd/createvmss/main.go [174:208]


func GetSubnetId(ctx context.Context, azureClients *AzureClients) (string, error) {
	vm, err := azureClients.VMClient.Get(ctx, azureClients.LocalMetadata.ResourceGroup, azureClients.LocalMetadata.Name, compute.InstanceView)
	if err != nil {
		return "", fmt.Errorf("error getting the vmdata: %v", err)
	}

	if vm.VirtualMachineProperties == nil ||
		vm.VirtualMachineProperties.NetworkProfile == nil ||
		vm.VirtualMachineProperties.NetworkProfile.NetworkInterfaces == nil ||
		len((*vm.VirtualMachineProperties.NetworkProfile.NetworkInterfaces)) == 0 ||
		(*vm.VirtualMachineProperties.NetworkProfile.NetworkInterfaces)[0].ID == nil {
		return "", fmt.Errorf("unable to retreive nic for the local compute vm")
	}

	nicId := *(*vm.VirtualMachineProperties.NetworkProfile.NetworkInterfaces)[0].ID
	nicName := GetResourceName(nicId)
	nic, err := azureClients.NICClient.Get(ctx, azureClients.LocalMetadata.ResourceGroup, nicName, "")
	if err != nil {
		return "", fmt.Errorf("error getting the nic data for group '%s', nic '%s': %v", azureClients.LocalMetadata.ResourceGroup, nicName, err)
	}
	if nic.InterfacePropertiesFormat == nil ||
		nic.InterfacePropertiesFormat.IPConfigurations == nil ||
		len((*nic.InterfacePropertiesFormat.IPConfigurations)) == 0 {
		return "", fmt.Errorf("nic '%s' has no ip configurations", nicId)
	}

	ipConfig := (*nic.InterfacePropertiesFormat.IPConfigurations)[0]
	if ipConfig.InterfaceIPConfigurationPropertiesFormat == nil ||
		ipConfig.InterfaceIPConfigurationPropertiesFormat.Subnet == nil ||
		ipConfig.InterfaceIPConfigurationPropertiesFormat.Subnet.ID == nil {
		return "", fmt.Errorf("nic '%s' ip configuration has no subnet", nicId)
	}

	return *(*nic.InterfacePropertiesFormat.IPConfigurations)[0].Subnet.ID, nil
}