https://pulumi.com logo
#golang
Title
# golang
d

delightful-daybreak-41063

09/26/2022, 10:32 PM
I’m working on a Go CLI tool that I was hoping would spin up an AWS instance and install a server, and then stream data to the server for processing. I found pulumi in that search, and was excited it was written in go as well, hoping to integrate the two in go, instead of gluing things together with bash scripts. Currently, I can create the instance via
pulumi up
and install stuff via UserData, but now I’m hoping to sidestep the
pulumi up
command and just start the instance in the CLI app? I see that I can import github.com/pulumi/pulumi/pkg/v3/cmd/pulumi is made public in
go mod
, and I have access to the
NewPulumiCmd() cobra.Cmd
, which seems to be the only valuable thing that is exported. I assumed I could just call the
NewPulumiCmd.Run()
and pass in any cli parameters I would have normally passed in, but that package is “package main”, so go doesn’t want me to import it, giving the error:
import "<http://github.com/pulumi/pulumi/pkg/v3/cmd/pulumi|github.com/pulumi/pulumi/pkg/v3/cmd/pulumi>" is a program, not an importable package
. Is this a problem that has been asked about before? Is this the first time it has been asked? Is this just the wrong thing to be doing with the tool? Are we opposed to moving all the sub-commands to a nested package (i.e. /pkg/cmd/pulumi/cmds/up.go) and making them Public?
b

billowy-army-68599

09/26/2022, 10:38 PM
@delightful-daybreak-41063 you’re looking for Automation API I think https://www.pulumi.com/automation/ here’s a CLI example: https://github.com/jaxxstorm/pulumi-productionapp/tree/main/cli
d

delightful-daybreak-41063

09/27/2022, 1:41 AM
Awesome! Thanks for the guidance. I figured it would have been a solved problem by now, I just didn’t know where to look.
b

billowy-army-68599

09/27/2022, 1:18 PM
@delightful-daybreak-41063 is there anything you search for? I’d love t make this more discoverable
d

delightful-daybreak-41063

09/27/2022, 7:27 PM
That’s a good question. I think I just got started in the regular pulumi use case/docs, and then tunnel visioned myself into assuming that I had to use the /cmd/pulumi stuff. As far as my search queries: “run pulumi code inside application” “pulumi run from go program instead of cli” “import pulumi into go project” Those ones seem to be the most relevant until I went in search of the source code and tried to
go mod
import it I also tried adding in different use cases like “start ec2 instance programatically with pulumi”. But those got too far into the ec2 docs for pulumi and all that’s there. I also tried sprinkling in “reddit”/“stack overflow” to get away from the docs, but that didn’t help quite as much, and eventually I went searching for some official slack/discourse place for pulumi and ended up here.
Again, half of the problem was probably me just getting tunnel vision and not just reading the full manual.
12 Views