Hi Team, Good Day!!! Is there any pulumi APIs to...
# general
c
Hi Team, Good Day!!! Is there any pulumi APIs to fetch list of vNets from Azure based on subscription/ResourceGroup? I found below but here we need to mention VirtualNetworkName and ResourceGroupName both and then it return details of mentioned Vnet. vnet, err := network.LookupVirtualNetwork(ctx, &network.LookupVirtualNetworkArgs{ VirtualNetworkName: "vNetAlpha", ResourceGroupName: "ResourceGroupAlpha", }, nil) Similarly looking for pulumi APIs for other vRouter resources like subnet, routeTable, securityGroup, VPNGateways etc. Please suggest if any Thanks!!
b
@cool-room-80906 what do you mean by "Pulumi API"? Because with Pulumi you are in the world of real programming languages, so why not using the Azure SDK for the language with which you implemented your Pulumi program and grab the required informations directly?
Another option would be to use the Azure Classic provider and call https://www.pulumi.com/registry/packages/azure/api-docs/core/getresources/
Or querying the Azure Resource Graph via https://www.pulumi.com/registry/packages/azure-native/api-docs/resourcegraph/ using the Pulumi Azure Native provider
But keep in mind that
getResources
and
resourcegraph
are not the same.
getResources
queries the Azure API directly where the
resourceGraph
operates on a cache, which has implications when and if resources show up there.
c
Hi @big-architect-71258....through pulumi API I want to refer below methods from "github.com/pulumi/pulumi-azure-native/sdk/go/azure/network" ...my bad vnet, err := network.LookupVirtualNetwork(ctx, &network.LookupVirtualNetworkArgs{ VirtualNetworkName: "some name, ResourceGroupName: "some name", }, nil) I am able to fetch details of azure virtual network....but I want list of virtual networks. I referred getResources method as suggested but didn't worked for me as well ...used "github.com/pulumi/pulumi-azure/sdk/v6/go/azure/core" to fetch list of virtual networks using below methods resourceGroupName := "some name" resourceName := "some name" resourceType := "Microsoft.Network/virtualNetworks" vnetResources, err := core.GetResources(ctx, &core.GetResourcesArgs{ ResourceGroupName: &resourceGroupName, Type: &resourceType, // Name: &resourceName, }) if err != nil { return fmt.Errorf("failed to list virtual networks: %w", err) } resourceDetails = make(map[string]pulumi.Input) // Iterate over each virtual network resource found for _, vnet := range vnetResources.Resources { resourceDetails[vnet.Name] = pulumi.StringMap{ "id": pulumi.String(vnet.Id), "name": pulumi.String(vnet.Name), "type": pulumi.String(vnet.Type), } } Thanks!!