Skip to content

Commit 3a00758

Browse files
iac: pulumi infra
1 parent 40c31b3 commit 3a00758

File tree

8 files changed

+1067
-0
lines changed

8 files changed

+1067
-0
lines changed

iac/deploy.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//revive:disable:package-comments,exported
2+
package main
3+
4+
import (
5+
"context"
6+
"fmt"
7+
"log"
8+
"os"
9+
10+
"github.com/pulumi/pulumi/sdk/v3/go/auto"
11+
)
12+
13+
func main() {
14+
ctx := context.Background()
15+
16+
// Configuration
17+
stackProjectName := "github-repos"
18+
stackEnvironmentName := "prod-strategy-optimizer"
19+
workDir := "pulumi-github-main"
20+
pulumiOrganizationName := os.Getenv("PULUMI_ORG_NAME")
21+
pulumiAccessToken := os.Getenv("PULUMI_ACCESS_TOKEN")
22+
23+
// Validate required environment variables
24+
if pulumiOrganizationName == "" || pulumiAccessToken == "" {
25+
log.Fatal("PULUMI_ORG_NAME and PULUMI_ACCESS_TOKEN must be set")
26+
}
27+
28+
configMap := auto.ConfigMap{
29+
"github:token": auto.ConfigValue{
30+
Value: os.Getenv("GITHUB_TOKEN"),
31+
Secret: true,
32+
},
33+
"github:owner": auto.ConfigValue{
34+
Value: os.Getenv("GITHUB_OWNER"),
35+
Secret: true,
36+
},
37+
}
38+
39+
// Create or select the stack
40+
pulumiStackName := auto.FullyQualifiedStackName(pulumiOrganizationName, stackProjectName, stackEnvironmentName)
41+
stack, err := NewPulumiStack(ctx, pulumiStackName, workDir)
42+
if err != nil {
43+
log.Fatalf("Failed to create or select stack: %v", err)
44+
}
45+
log.Println("Stack", pulumiStackName, "ready")
46+
47+
// Deploy the stack
48+
outputs, err := deployStack(ctx, stack, pulumiAccessToken, configMap)
49+
if err != nil {
50+
log.Fatalf("Stack deployment failed: %v", err)
51+
}
52+
53+
log.Println("Stack deployment completed successfully")
54+
if len(outputs) > 0 {
55+
log.Println("Stack outputs:")
56+
for k, v := range outputs {
57+
// Note: Secret outputs will be encrypted in the log.
58+
log.Printf("- %s: %s\n", k, v.Value)
59+
}
60+
}
61+
}
62+
63+
// deployStack orchestrates the deployment of a Pulumi stack.
64+
// It is designed to be testable by accepting a Stack interface.
65+
func deployStack(ctx context.Context, stack Stack, pulumiAccessToken string, configMap auto.ConfigMap) (map[string]auto.OutputValue, error) {
66+
err := stack.SetEnvVars(map[string]string{
67+
"PULUMI_SKIP_UPDATE_CHECK": "true",
68+
"PULUMI_CONFIG_PASSPHRASE": "",
69+
"PULUMI_ACCESS_TOKEN": pulumiAccessToken,
70+
})
71+
if err != nil {
72+
return nil, fmt.Errorf("failed to set environment variables: %w", err)
73+
}
74+
75+
err = stack.SetAllConfig(ctx, configMap)
76+
if err != nil {
77+
return nil, fmt.Errorf("failed to set config: %w", err)
78+
}
79+
80+
log.Println("Refreshing stack...")
81+
refrOut, err := stack.Refresh(ctx)
82+
if err != nil {
83+
return nil, fmt.Errorf("failed to refresh stack: %w", err)
84+
}
85+
log.Println(refrOut)
86+
87+
log.Println("Previewing stack...")
88+
prevOut, err := stack.Preview(ctx)
89+
if err != nil {
90+
return nil, fmt.Errorf("failed to preview stack: %w", err)
91+
}
92+
log.Println(prevOut)
93+
94+
log.Println("Updating stack...")
95+
upResult, err := stack.Up(ctx)
96+
if err != nil {
97+
return nil, fmt.Errorf("failed to update stack: %w", err)
98+
}
99+
log.Println(upResult.StdOut)
100+
101+
return upResult.Outputs, nil
102+
}

iac/go.mod

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module pulumi-infra
2+
3+
go 1.24.2
4+
5+
require (
6+
github.com/pulumi/pulumi/sdk/v3 v3.177.0
7+
github.com/stretchr/testify v1.10.0
8+
)
9+
10+
require (
11+
dario.cat/mergo v1.0.0 // indirect
12+
github.com/BurntSushi/toml v1.2.1 // indirect
13+
github.com/Microsoft/go-winio v0.6.1 // indirect
14+
github.com/ProtonMail/go-crypto v1.1.3 // indirect
15+
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
16+
github.com/agext/levenshtein v1.2.3 // indirect
17+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
18+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
19+
github.com/atotto/clipboard v0.1.4 // indirect
20+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
21+
github.com/blang/semver v3.5.1+incompatible // indirect
22+
github.com/charmbracelet/bubbles v0.16.1 // indirect
23+
github.com/charmbracelet/bubbletea v0.25.0 // indirect
24+
github.com/charmbracelet/lipgloss v0.7.1 // indirect
25+
github.com/cheggaaa/pb v1.0.29 // indirect
26+
github.com/cloudflare/circl v1.6.1 // indirect
27+
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
28+
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
29+
github.com/davecgh/go-spew v1.1.1 // indirect
30+
github.com/djherbis/times v1.5.0 // indirect
31+
github.com/emirpasic/gods v1.18.1 // indirect
32+
github.com/fsnotify/fsnotify v1.6.0 // indirect
33+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
34+
github.com/go-git/go-billy/v5 v5.6.1 // indirect
35+
github.com/go-git/go-git/v5 v5.13.1 // indirect
36+
github.com/gogo/protobuf v1.3.2 // indirect
37+
github.com/golang/glog v1.2.4 // indirect
38+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
39+
github.com/google/uuid v1.6.0 // indirect
40+
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
41+
github.com/hashicorp/errwrap v1.1.0 // indirect
42+
github.com/hashicorp/go-multierror v1.1.1 // indirect
43+
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
44+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
45+
github.com/iwdgo/sigintwindows v0.2.2 // indirect
46+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
47+
github.com/kevinburke/ssh_config v1.2.0 // indirect
48+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
49+
github.com/mattn/go-isatty v0.0.20 // indirect
50+
github.com/mattn/go-localereader v0.0.1 // indirect
51+
github.com/mattn/go-runewidth v0.0.15 // indirect
52+
github.com/mitchellh/go-ps v1.0.0 // indirect
53+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
54+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
55+
github.com/muesli/cancelreader v0.2.2 // indirect
56+
github.com/muesli/reflow v0.3.0 // indirect
57+
github.com/muesli/termenv v0.15.2 // indirect
58+
github.com/nxadm/tail v1.4.11 // indirect
59+
github.com/opentracing/basictracer-go v1.1.0 // indirect
60+
github.com/opentracing/opentracing-go v1.2.0 // indirect
61+
github.com/pgavlin/fx v0.1.6 // indirect
62+
github.com/pjbgf/sha1cd v0.3.0 // indirect
63+
github.com/pkg/errors v0.9.1 // indirect
64+
github.com/pkg/term v1.1.0 // indirect
65+
github.com/pmezard/go-difflib v1.0.0 // indirect
66+
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
67+
github.com/pulumi/esc v0.14.2 // indirect
68+
github.com/rivo/uniseg v0.4.4 // indirect
69+
github.com/rogpeppe/go-internal v1.12.0 // indirect
70+
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
71+
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
72+
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
73+
github.com/skeema/knownhosts v1.3.0 // indirect
74+
github.com/spf13/cobra v1.8.0 // indirect
75+
github.com/spf13/pflag v1.0.5 // indirect
76+
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
77+
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
78+
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
79+
github.com/xanzy/ssh-agent v0.3.3 // indirect
80+
github.com/zclconf/go-cty v1.13.2 // indirect
81+
go.uber.org/atomic v1.9.0 // indirect
82+
golang.org/x/crypto v0.37.0 // indirect
83+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
84+
golang.org/x/mod v0.19.0 // indirect
85+
golang.org/x/net v0.39.0 // indirect
86+
golang.org/x/sync v0.13.0 // indirect
87+
golang.org/x/sys v0.32.0 // indirect
88+
golang.org/x/term v0.31.0 // indirect
89+
golang.org/x/text v0.24.0 // indirect
90+
golang.org/x/tools v0.23.0 // indirect
91+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
92+
google.golang.org/grpc v1.67.1 // indirect
93+
google.golang.org/protobuf v1.36.6 // indirect
94+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
95+
gopkg.in/warnings.v0 v0.1.2 // indirect
96+
gopkg.in/yaml.v3 v3.0.1 // indirect
97+
lukechampine.com/frand v1.4.2 // indirect
98+
)

0 commit comments

Comments
 (0)