https://pulumi.com logo
#general
Title
# general
a

agreeable-hair-34658

07/29/2021, 12:58 PM
Hi guys, I am currently stuck with the following error, that arises when doing var virtualNetwork = Network.VirtualNetwork.Get(config.Network.Vnet.Key, config.Network.Vnet.Value); the error message is error: Code="ResourceNotFound" Message="The Resource 'Microsoft.Network/virtualNetworks/testvnet' under resource group 'ghd-dwhnet-prod-rg' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix" the virtual network I need to reference is in another resource group than the resources, that I want to create
g

great-sunset-355

07/29/2021, 1:01 PM
Are you trying to refer to existing vnet resource? Then you'd want this method instead: https://www.pulumi.com/docs/reference/pkg/azure/network/getvirtualnetwork/
1
b

bored-oyster-3147

07/29/2021, 1:01 PM
You should be able to provider a different provider to the
.Get
method.
@great-sunset-355 pretty sure that's what he is using this is just what it looks like in .NET
a

agreeable-hair-34658

07/29/2021, 1:03 PM
yeah, I am refering to an existing vnet resource
b

bored-oyster-3147

07/29/2021, 1:03 PM
nevermind... disregard me.. apparently I'm full of shit this week lol. Jan is right you need to use the method above which allows you to specify ResourceGroup in the method signature.
I thought they were the same.
a

agreeable-hair-34658

07/29/2021, 1:03 PM
the provider is basically the same, both resources (ecisting and new) are in azure
great, this is exactly what I require 😄
🙌 1
g

great-sunset-355

07/29/2021, 1:06 PM
@bored-oyster-3147 Yeah some resources has
.Get
method while package provides
get_resource
which is confusing because the behaviour is different
👀 1
a

agreeable-hair-34658

07/29/2021, 1:15 PM
@great-sunset-355 one more quick question: I refactored my code to this. Apparently, I always need to use
APPLY
to extract any attributes?
Copy code
// retrieve network
        var virtualNetwork = Network.GetVirtualNetwork.InvokeAsync(new Network.GetVirtualNetworkArgs
        {
            VirtualNetworkName = config.Network.Vnet.Key,
            ResourceGroupName = config.Network.Vnet.Value,
        });

        var subnetMgmt = new Network.Subnet(config.Security.SubnetMgmtName, new Network.SubnetArgs()
        {
            VirtualNetworkName = virtualNetwork.Name,  
            ResourceGroupName = resourceGroupVnet.Name,      
            AddressPrefix = config.Security.SubnetMgmtAddressPrefix,
            Name = config.Security.SubnetMgmtName,
            PrivateEndpointNetworkPolicies = "Disabled"
        });
problem is
virtualNetwork.Name
is not available
b

bored-oyster-3147

07/29/2021, 1:18 PM
so in .NET you use the
.InvokeAsync
methods like this:
var virtualNetwork = Output.Create(Network.GetVirtualNetwork.InvokeAsync(...));
because
.InvokeAsync(...)
returns a
Task<T>
and you want an
Output<T>
. Then you can use
.apply(...)
like you normally would. See the example here: https://www.pulumi.com/docs/reference/pkg/azure/network/getvirtualnetwork/#example-usage