Hi, is there some sort of document/pattern etc abo...
# general
d
Hi, is there some sort of document/pattern etc about how Dependency Tracking works? @tall-librarian-49374
e
There's some docs on dependency tracking at https://www.pulumi.com/docs/intro/concepts/inputs-outputs/ Was there a specific question you had regarding how it works?
d
its good! whats the option to convert from Output<T> to T or Input<T> to T? read https://mikhail.io/lab/pulumi/7-outputs/ but something is missing! Thanks
e
In general you can't. Pulumi programs need to be able to run at preview time as well as for the actual update and at preview most Outputs don't actually have a value so a method to go from Output<T> to T would result in crashes during preview. There is a
get
method but it's documented as not for use in normal program flow but only for cloud functions that are embeded in your pulumi program:
Copy code
/**
     * Retrieves the underlying value of this dependency.
     *
     * This function is only callable in code that runs in the cloud post-deployment.  At this
     * point all Output values will be known and can be safely retrieved. During pulumi deployment
     * or preview execution this must not be called (and will throw).  This is because doing so
     * would allow Output values to flow into Resources while losing the data that would allow
     * the dependency graph to be changed.
     */
    get(): T;
Chances are what ever you were hoping to do with the value inside the Output can be done another way. For example most resources will take
Input<T>
as their input values and those can be made from plain values or Outputs.
d
Currently doing get* calls to get resource and only create if not available eg: getVirtualMachine. these methods don't work with Input/Output<T>! whats the way to do idempotent creation in pulumi! Thanks
e
All resource creation is idempotent in Pulumi? It's like other IaC tools in that regard,
new Resource()
doesn't actually go off and make a new resource it just declares to the pulumi engine that the resource should exist. Pulumi then checks current state to decided if a create/update/replace/same is needed.
d
i started with like this, eg: new resources.*ResourceGroup*(name) throws error: cannot check existence of resource does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/read'
i can create stuff within rg just fine
and resources.getResourceGroup work just fine
e
Have you tried running some pre-built examples like https://github.com/pulumi/examples/tree/master/azure-ts-webserver to check your setup is correct
Because that error looks a lot like azure permission setup issues
d
i have created infra from eg and created multiple resources!
e
Can you share the code your trying to run that is giving issues then? If the examples work then you've probably got a problem with the program your writing
d
import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources"; export type
*ResourceGroupResult* =
    |
*resources*.*GetResourceGroupResult*
   
| *resources*.*ResourceGroup*;
export var Current:
*ResourceGroupResult*;
export function
*set*(current: *ResourceGroupResult*) {
    Current = current; } export const Config = new pulumi.
*Config*("rg");
export const Name = Config.
*require*("name");
export async function
*ResourceGroup*(): *Promise*<*ResourceGroupResult*> {
    const name = Name;     let rg:
*ResourceGroupResult* | null = null;
    try {         rg = await resources.
*getResourceGroup*({
            resourceGroupName: name,         });     } catch {}     if (!rg) {         rg = new resources.
*ResourceGroup*(name);
    }     return rg; }
if rg = new resources.
*ResourceGroup*(name);
is directly used, it throws
throws error: cannot check existence of resource does not have authorization to perform action 'Microsoft.Resources/subscriptions/resourcegroups/read'
you are right, its right issue
but, then
resources.*getResourceGroup*
shouldn't work also!
e
It might be that you have perms to look up from any location but don't have perms to create in the default location
d
but, that rg is already created and i am working on this rg! thats why i had used get* pattern to check and then create. now after you told, i only use new Resource pattern and it work! Only
rg = new resources.*ResourceGroup*(name);
don't work
e
It sounds like you should have a read of https://www.pulumi.com/docs/guides/adopting/import/ If that resourceGroup already exists you should either read it or import it.
new ResourceGroup(name)
won't do what you want.
d
thanks, read about that as well but i thought its just to adapt resources like cloning stuff etc!