https://pulumi.com logo
Title
w

wooden-caravan-96340

01/18/2023, 11:51 AM
How to use
compute.GetVirtualMachine()
in automation api with golang? Did anybody encounter this kind of error? I'm getting
panic: runtime error: invalid memory address or nil pointer dereference
error :(. The code looks like this:
con := context.Background()
	ctx, err := pulumi.NewContext(con, pulumi.RunInfo{Project: "rest-api", Stack: "pulumi-test"})
	if err != nil {
		fmt.Println(err)
	}
	vm, err := compute.GetVirtualMachine(ctx, "vm480cd303", pulumi.ID("50dd5f24-507b-4b76-a911-4708782d2940"), &compute.VirtualMachineState{})
	
	if err != nil { fmt.Println(err)}
	fmt.Println(vm.Name)
e

echoing-dinner-19531

01/18/2023, 11:56 AM
That doesn't look right, you should pretty much never need to call NewContext yourself. Take a look at the golang automation example at https://github.com/pulumi/automation-api-examples/blob/main/go/inline_program/main.go to see how you should be calling into pulumi.
w

wooden-caravan-96340

01/20/2023, 7:10 AM
The only i was able to call that
compute.GetVirtualMachine
was through
stack.Up()
. But that ends up deleteing all the resources in a stack , i just want to get
the power state of a vm
.
e

echoing-dinner-19531

01/21/2023, 1:36 PM
Pretty much all pulumi resource calls (including getters) need to run within a deployment, this might get changed at some point but for now we need the deployment infrastructure setup to invoke these calls correctly.
w

wooden-caravan-96340

01/22/2023, 8:24 AM
ok, thanks!