After `pulumi up` I see my nested resources in my ...
# general
b
After
pulumi up
I see my nested resources in my pulumi cloud resources tab, can I fetch those outputs from the command line?
b
Do you want the stack outputs or the list of stack resources?
s
@big-island-38073 if you want to reference the resources your pulumi app just created, then 1) the best way to do it is via stack references if you create another stack that depends on the first stack. Or 2) as a stack output if you want to export specific attributes of the said resource (like an ARN) that you want to use in a shell script (Like retrieving the kubeconfig after creating a k8s cluster). Stack Refs: https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences Stack Output: https://www.pulumi.com/docs/reference/cli/pulumi_stack_output/
b
Thanks @steep-sunset-89396, looks like I'm gonna have to do a bunch of reading. I thought that my Javascript code having something like:
export const talos0vmid = talos0.vmid
was enough to declare an output, Also Outputs and resources are clearly not the same. But this is confusing:
Copy code
$ pulumi up
Previewing update (dev)

View Live: <https://app.pulumi.com/daneroo/pulumi-pxmx/dev/previews/e0d01581-a834-4b2c-8546-7b7fbe758a72>

     Type                 Name             Plan     
     pulumi:pulumi:Stack  pulumi-pxmx-dev           
 
Outputs:
  + talos0vmid: output<string>
  + talos1vmid: output<string>

Resources:
    3 unchanged
But also
Copy code
$ pulumi stack output
Current stack outputs (0):
    No output values currently in this stack
s
Interesting. Here's a trick maybe for you. I usually use the management console to explore the properties of my resources and pick what I need. And then in typescript I usually do a bag (
{prop1: val1, prop2: val2}
) of the properties I want as outputs. In your example above, did you run
pulumi up
or
pulumi preview
? Running
pulumi preview
won't alter the state of your stack. You need to let
pulumi up
finish in order to get the outputs be exported by the CLI.
b
It was
pulumi up
.
s
When you explore your stack resources in the console, do you see any value for
.vmid
? What provider are you using by the way ?
b
I'm pretty comfortable destructuring to get at the data I wand in JS/TS, But these variables aprear to be nested Outputs, I am unable to do the simplest things, Access a nested Array, JSON.stringify,... For example this is one my resource's properties. (It's a Proxmox VM, and I'm trying to get it's mac address)
Copy code
networks
[
  {
    "bridge": "vmbr0",
    "firewall": false,
    "linkDown": false,
    "macaddr": "9E:28:27:8A:97:0E",
    "model": "virtio",
    "queues": 0,
    "rate": 0,
    "tag": -1
  }
]
The provisioning of this VM is working fine, but I need to finish the job with some external scripts, which I hope to automate with better pulumi integration. But for now all I want is to provision the VM's (which is working)) And get the macaddress so I can decide if pulumi is a realistic way to go..
s
I'm not familiar with proxmox, but the export of the MAC address should be like
export const macaddr = talos0.networks[0].macaddr;
.
Also, looks like the proxmox is not an officially supported provider.
I'm wondering... have you tried to export your stack and explore into the json ?
pulumi stack export > stack.json
I found it's also a good way to look into what's usually available.
b
Yes I agree it should be
export const macaddr = talos0.networks[0].macaddr
but that yields this error in VSCode:
Copy code
Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Output<QemuVMNetwork[] | undefined>'.
  Property '0' does not exist on type 'Output<QemuVMNetwork[] | undefined>'.
Looks like you found the answer though!!!!
Copy code
$ pulumi stack export | jq -r .deployment.resources[2].outputs.networks[0].macaddr
F2:97:D7:F8:24:C5
$ pulumi stack export | jq -r .deployment.resources[3].outputs.networks[0].macaddr
9E:28:27:8A:97:0E
Bingo!
👍 1
Perhaps it is because the resources I am creating are actually done with a the `
Copy code
@matchlighter/pulumi-proxmoxve
Which is a wrapper around a terraform provider. .. I know I am really asking for trouble..
Thanks @steep-sunset-89396, that totally unblocked me. Once I kludge something together, I can redo it properly. Perhaps I should be writing my own provider...
👍 1
s
Yes, if proxmox is your bread and butter and you heavily rely on it, then you may want to create your own provider. Maybe a dynamic provider at first ? https://www.pulumi.com/blog/dynamic-providers/
b
Yessssss!!!!
I am really trying to get something pretty specific to work in an automated way. • Proxmox is just great to provision VM's in my homelab (but I want it automated) • Talos is a new Kubernetes distribution based on an immutable filesystem • Start up two empty VM's with the Talos
.iso
• Run Talos' bootstrapping code to inject configuration into the two newly created VM's ◦ This is where I need to turn the above mentioned mac address into an IP address • Export the kubeconfig from the new cluster • Get on with my life, with a brand new Kubernetes cluster! • I am assuming from then, I can follow the "normal" kubernetes instructions Hopefully the DynamicProvider you mentioned above will do the trick!
🎉 1
s
That looks really cool what you're doing for sure !