magnificent-vase-49161
02/06/2024, 2:00 PMIAC-PULUMI
├── dev
│ ├── eks
│ ├── iam
│ ├── rds
│ ├── vpc
│ └── dev.go
├── prod
│ ├── eks
│ ├── iam
│ ├── rds
│ ├── vpc
│ └── prod.go
├── shared
│ ├── eks
│ ├── iam
│ ├── rds
│ ├── vpc
│ └── shared.go
├── modules
│ ├── eks
│ ├── iam
│ ├── rds
│ ├── vpc
├── .gitignore
├── go.mod
├── go.sum
├── main.go
├── Pulumi.iac-pulumi-dev.yaml
├── Pulumi.iac-pulumi-prod.yaml
├── Pulumi.iac-pulumi-shared.yaml
├── Pulumi.yaml
└── vendor
My main.go is as follows:
package main
import (
"fmt"
"log"
"os"
"os/exec"
"iac-pulumi/shared"
)
func runPulumiCommand(env string) {
// Construct the stack name based on the environment variable
stackName := fmt.Sprintf("<<MY-COMPANY>>/iac-pulumi/%s", env)
// Select the stack
cmd := exec.Command("pulumi", "stack", "select", stackName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatalf("Failed to select Pulumi stack: %v", err)
}
}
func main() {
env := os.Getenv("DEPLOY_ENV")
if env == "" {
fmt.Println("Please run: export DEPLOY_ENV=<your-environment>")
return
}
switch env {
case "shared":
shared.Deploy()
runPulumiCommand(env)
default:
panic("Unknown environment")
}
}
However, when running the command pulumi up or pulumi preview
I receive the following error:
Diagnostics:
pulumi:pulumi:Stack (iac-pulumi-shared):
error: Duplicate resource URN 'urn:pulumi:shared::iac-pulumi::pulumi:pulumi:Stack::iac-pulumi-shared'; try giving it a unique name
As if it is trying to recreate the stack but the stack already exists so in theory it should just select the existing one.
I searched slack and the internet for the same problem and only found this: https://github.com/pulumi/pulumi/issues/13779
Does anyone have any insight into how to resolve this?
Thanks!salmon-account-74572
02/06/2024, 10:14 PMexec.Command
to perform operations on Pulumi stacks.
Also, you’ll want to review the documentation around Pulumi projects and stacks, so that you understand how to manipulate them with Automation API. The docs have some great materials here; let me know if you need links and I’ll look them up (although they should be pretty easy to find).
If you have further specific questions, let me know. I’m happy to help if I’m able.magnificent-vase-49161
02/07/2024, 1:48 PMmagnificent-vase-49161
02/07/2024, 8:13 PMsalmon-account-74572
02/07/2024, 8:16 PM