-
Notifications
You must be signed in to change notification settings - Fork 0
/
linode.go
139 lines (123 loc) · 3.47 KB
/
linode.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
package main
import (
"fmt"
"os"
"strings"
"github.com/pulumi/pulumi-linode/sdk/v3/go/linode"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
var _ Provider = &Linode{}
type Linode struct {
sshIDs []string
globalTimeout pulumi.CustomTimeouts
}
// NewLinodeProvider creates a new Linode provider with the given SSH key IDs
// and timeout. The timeout should take the form of a string that can be parsed
// by pulumi, so "30m" would be 30 minutes, "1h" would be 1 hour, etc.
func NewLinodeProvider(timeout string) (*Linode, error) {
rawLinodeSshIDs := os.Getenv("LINODE_SSH_KEY_IDS")
if rawLinodeSshIDs == "" {
fmt.Println("no raw ssh key")
return nil, fmt.Errorf("No SSH IDs provided, please provide a list of SSH IDs in the LINODE_SSH_IDS environment variable")
}
fmt.Println("linode ssh key", rawLinodeSshIDs)
sshIDs := strings.Split(rawLinodeSshIDs, ",")
if len(sshIDs) == 0 {
fmt.Println("no ssh keys from parsing")
return nil, fmt.Errorf("No SSH IDs provided, please provide a list of SSH IDs in the LINODE_SSH_IDS environment variable")
}
fmt.Println("linode ssh key", sshIDs)
return &Linode{
sshIDs: sshIDs,
globalTimeout: pulumi.CustomTimeouts{
Delete: timeout,
},
}, nil
}
// CreateValidatorInstance creates a new validator instance in the given region.
// It fulfills the Provider interface. The returned string is the IP address of
// the new instance.
func (l *Linode) CreateValidatorInstance(ctx *pulumi.Context, name, region string) (pulumi.StringOutput, error) {
instance, err := linode.NewInstance(ctx, name, &linode.InstanceArgs{
Region: pulumi.String(region),
Type: pulumi.String("g6-standard-8"),
Image: pulumi.String("linode/ubuntu22.04"),
Label: pulumi.String(name),
AuthorizedKeys: pulumi.ToStringArray(l.sshIDs),
Tags: pulumi.StringArray{pulumi.String("temp")},
StackscriptId: pulumi.IntPtr(1439088),
StackscriptData: pulumi.Map{
"hostname": pulumi.String(name),
},
}, pulumi.Timeouts(&l.globalTimeout))
if err != nil {
ctx.Export("name", pulumi.String(fmt.Sprintf("Error creating instance %s %s: %s", name, region, err.Error())))
} else {
ctx.Export(name, instance.IpAddress)
}
return instance.IpAddress, nil
}
var (
LinodeRegions = map[string]int{
"ap-west": 1,
"ca-central": 1,
"ap-southeast": 1,
"us-ord": 1,
"fr-par": 1,
"us-sea": 1,
"br-gru": 1,
"nl-ams": 1,
"se-sto": 1,
"es-mad": 1,
"in-maa": 1,
"jp-osa": 1,
"it-mil": 1,
"us-mia": 1,
"id-cgk": 1,
"us-lax": 1,
"us-central": 1,
"us-west": 1,
"us-southeast": 1,
"us-east": 1,
"eu-west": 1,
"ap-south": 1,
"eu-central": 1,
"ap-northeast": 1,
}
LinodeFullRegions = map[string]int{
"us-ord": 2,
"us-sea": 2,
"br-gru": 2,
"se-sto": 2,
"es-mad": 1,
"it-mil": 2,
"us-mia": 2,
"us-lax": 2,
"us-central": 2,
"us-southeast": 2,
"eu-central": 2,
"fr-par": 2,
"us-east": 2,
"us-west": 2,
"eu-west": 2,
}
LinodeMinimalRegions = map[string]int{
// "ap-west": 1,
"ca-central": 2,
// "ap-southeast": 1,
"us-sea": 2,
// "br-gru": 1,
// "se-sto": 1,
"es-mad": 2,
"jp-osa": 1,
"it-mil": 1,
// "id-cgk": 1,
"us-central": 2,
// "ap-south": 1,
// "ap-northeast": 1,
}
LinodeTestRegions = map[string]int{
"us-central": 1,
"eu-west": 1,
}
)