i’m using azure native, is there a way to referenc...
# azure
g
i’m using azure native, is there a way to reference a resource in another subscription in pulumi. I tried the below but get an error saying `request failed /subscriptions/MY_SUB_ID/resourceGroups/%2Fsubscriptions%2FMY_OTHER_SUB_ID%2FresourceGroups%2Fcontainer-apps-production/providers/Microsoft.ContainerRegistry/registries/elaway:`:
Copy code
var registry = Output.Tuple<string, string>("/subscriptions/MY_OTHER_SUB_ID/resourceGroups/container-apps-production", registryName)
                 .Apply(
                     items =>
                         Pulumi.AzureNative.ContainerRegistry.GetRegistry.InvokeAsync(
                             new() {
                                 ResourceGroupName = items.Item1,
                                 RegistryName      = items.Item2
                             }
                         )
                 );
thought this might work which it kinda does but then says
Duplicate resource URN 'urn:pulumi:staging::jctest::pulumi:providers:azure-native::production'; try giving it a unique name
Copy code
var registry = Output.Tuple<string, string>("container-apps-production", registryName)
                .Apply(
                    items =>
                        Pulumi.AzureNative.ContainerRegistry.GetRegistry.InvokeAsync(
                            new()
                            {
                                ResourceGroupName = items.Item1,
                                RegistryName = items.Item2
                            },
                            new InvokeOptions()
                            {
                                Provider = new Provider("production",
                                    new ProviderArgs() { SubscriptionId = "MY_OTHER_SUB" })
                            }
                        )
                );
that did work but each provider needed to have a unique name
but now i have 3
pulumi:providers:azure-native
resources
Copy code
var registry = Output.Tuple<string, string>("container-apps-production", registryName)
                .Apply(
                    items =>
                        Pulumi.AzureNative.ContainerRegistry.GetRegistry.InvokeAsync(
                            new()
                            {
                                ResourceGroupName = items.Item1,
                                RegistryName = items.Item2
                            },
                            new InvokeOptions()
                            {
                                Provider = new Provider("production-container-registry",
                                    new ProviderArgs() { SubscriptionId = "my_other_sub" })
                            }
                        )
                );

            var credentials = Output
                .Tuple<string, string>(
                    "container-apps-production",
                    registryName)
                .Apply(
                    items =>
                        ListRegistryCredentials.InvokeAsync(
                            new()
                            {
                                ResourceGroupName = items.Item1,
                                RegistryName = items.Item2,
                            },
                            new InvokeOptions()
                            {
                                Provider = new Provider("production-registry-credentials",
                                    new ProviderArgs() { SubscriptionId = "my_other_sub" })
                            }
                        )
                );
maybe i can create one instance and pass it each objects above and then i only have 2 azure native provider resources?
t
You need to define a Provider once and then reuse it for all resource options. Provide is a type of resource, so it should be named uniquely.
Copy code
var myProvider = new Provider("production",
                                    new ProviderArgs() { SubscriptionId = "MY_OTHER_SUB" });
...
new InvokeOptions() { Provider = myProvider }
g
cool, that’s what i did in the end 🙂 thanks!
t
Also, you can pass outputs directly to args if you use a different form of a function, e.g.
GetRegistry.Invoke
instead of
GetRegistry.InvokeAsync
. You won’t need an Apply then.
g
yeah i’m not sure why I have that
Output.Tuple
as the values passed in are normal strings
t
🙂 ah okay, definitely remove them then
g
Copy code
var registry2 =
                Pulumi.AzureNative.ContainerRegistry.GetRegistry.Invoke(
                    new()
                    {
                        ResourceGroupName = "container-apps-production",
                        RegistryName = registryName
                    },
                    new InvokeOptions
                    {
                        Provider = provider
                    }
                );
            
var loginServer2 = registry2.Apply(x => x.LoginServer);
how’s that? 🙂
t
👍
g
nice! thanks for the tips