-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoundation.go
59 lines (46 loc) · 1.24 KB
/
foundation.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
package main
import (
"fmt"
"os"
"github.com/go-playground/validator/v10"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"gopkg.in/yaml.v3"
"github.com/nicklasfrahm/infrastructure/pkg/pulumi/dns"
)
const (
// StackFoundation is the name of the stack that deploys DNS,
// Kubernetes at the network edge and underlay networking.
StackFoundation = "foundation"
// dnsSpecPath is the path to the DNS specification.
dnsSpecPath = "deploy/dns.yaml"
)
// NewFoundationStack deploys DNS, Kubernetes at the network edge
// and underlay networking.
func NewFoundationStack(ctx *pulumi.Context) error {
if err := configureDNS(ctx); err != nil {
return err
}
return nil
}
// configureDNS loads the DNS specification and configures DNS.
func configureDNS(ctx *pulumi.Context) error {
dnsSpecBytes, err := os.ReadFile(dnsSpecPath)
if err != nil {
return err
}
var dnsSpec dns.Spec
if err := yaml.Unmarshal(dnsSpecBytes, &dnsSpec); err != nil {
return err
}
if err := validator.New().Struct(dnsSpec); err != nil {
return err
}
for i := 0; i < len(dnsSpec.Zones); i++ {
zone := &dnsSpec.Zones[i]
_, err := dns.NewZone(ctx, fmt.Sprintf("%s-c.zone-%s", StackFoundation, zone.Name), zone)
if err != nil {
return err
}
}
return nil
}