Hey :wave: I am reading about project organizatio...
# golang
h
Hey 👋 I am reading about project organization and am using Go for the infrastructure code as well as the application code. In the documentation here: https://www.pulumi.com/docs/using-pulumi/organizing-projects-stacks/ I don't see the go.mod file mentioned. Is the the go.mod file meant to be at the root of the project if keeping application code with infrastructure code? I created a folder for
infrastructure
and created a new pulumi project in that but that also creates a go.mod file and then I run into the issue of having a nested module. In my case, the go.mod file for my application code lives in the root of the project
i
Hello! The go.mod file can be inside the same directory as the Pulumi.yaml, or in a parent directory. These are both valid: Everything in one directory. This is typically the case when the Pulumi project is in a separate repository from the rest of your code.
Copy code
/
├─go.mod
├─main.go
└─Pulumi.yaml
Pulumi project as a subdirectory in an existing project.
Copy code
/
├─go.mod
├─other.go
└─infrastructure/
  ├─main.go
  └─Pulumi.yaml
If you have an existing Go project with its own go.mod, you can delete infrastructure/go.mod and run
go mod tidy
. Go will inspect your code and update go.mod with any missing dependencies like the Pulumi SDK. It's also allowed to keep the infrastructure/go.mod and treat it as a submodule. That requires some more knowledge of Go submodules. Typically, there shouldn't be any issues, but you have to make sure to run
pulumi
inside the infrastructure directory, not outside. One advantage of doing this is that dependencies for your infrastructure (Pulumi and friends) do not become dependencies of your application.
Please be sure to use at least v3.68.0 if you decide to place go.mod in a parent directory of infrastructure/.
h
Hey @incalculable-parrot-23117 - thank you for the response! Yeah I don't know much about submodules so would prefer to keep it dead simple for now. I did end up creating a multi-module workspace to get around my IDE complaining about the nested module Will remove that go.mod in
infrastructure/go.mod
for now as you suggested
@incalculable-parrot-23117 your blog is super helpful! 👌