forked from siderolabs/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
146 lines (116 loc) · 2.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute"
"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
"github.com/siderolabs/pulumi-provider-talos/sdk/go/talos"
)
const (
ClusterName = "talos"
TalosVersion = "v1.0.6"
ControlPlaneNodesCount = 3
WorkerNodesCount = 2
)
// ResourceInfo holds pointers to the various resources that
// need to be passed around to each other.
type ResourceInfo struct {
PulumiConfig *config.Config
BucketLocation string
Region string
Zone string
Bucket *storage.Bucket
Image *compute.Image
Network *compute.Network
CPInstances []*compute.Instance
CPAddresses map[string]*compute.Address
WorkerAddresses map[string]*compute.Address
LBAddress *compute.GlobalAddress
TalosClusterConfig *talos.ClusterConfig
TalosClusterSecrets *talos.ClusterSecrets
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ri := ResourceInfo{
CPInstances: []*compute.Instance{},
CPAddresses: map[string]*compute.Address{},
WorkerAddresses: map[string]*compute.Address{},
}
// TODO: understand how to either set these programatically or let
// GCP choose for zone during instance creation.
ri.PulumiConfig = config.New(ctx, "")
region := ri.PulumiConfig.Get("region")
if region == "" {
region = "us-central1"
}
ri.Region = region
zone := ri.PulumiConfig.Get("zone")
if zone == "" {
zone = "us-central1-a"
}
ri.Zone = zone
// Create an Storage Bucket
err := ri.createStorage(ctx)
if err != nil {
return err
}
// Upload blob and create image
err = ri.createImage(ctx)
if err != nil {
return err
}
// Create a virtual networkf or us to use
err = ri.createNetworks(ctx)
if err != nil {
return err
}
// Carve out IP Addresses
err = ri.createCPAddresses(ctx)
if err != nil {
return err
}
err = ri.createWorkerAddresses(ctx)
if err != nil {
return err
}
err = ri.createLBAddress(ctx)
if err != nil {
return err
}
// Setup all firewall rules
err = ri.createFirewalls(ctx)
if err != nil {
return err
}
// Create Talos configs
err = ri.createConfigs(ctx)
if err != nil {
return err
}
// Create VMs
err = ri.createCPVMs(ctx)
if err != nil {
return err
}
err = ri.createWorkerVMs(ctx)
if err != nil {
return err
}
// Create K8s loadbalancer
err = ri.createLB(ctx)
if err != nil {
return err
}
// Bootstrap it
err = ri.bootstrapTalos(ctx)
if err != nil {
return err
}
for _, ip := range ri.CPAddresses {
ctx.Export("controlPlaneIP", ip.Address)
}
ctx.Export("loadBalancerIP", ri.LBAddress.Address)
ctx.Export("talosConfig", ri.TalosClusterSecrets.TalosConfig)
return nil
})
}