Skip to content

Commit d542369

Browse files
Merge pull request #57 from danmanor/user-data
equinix: Enable providing cloud-init user-data scripts
2 parents 7e36376 + 636eaf3 commit d542369

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/providers/equinix.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package providers
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"fmt"
67
"strings"
@@ -17,11 +18,12 @@ const (
1718
var eqClients = make(map[string]*packngo.Client)
1819

1920
type equinixProviderConfig struct {
20-
ProjectID string `json:"projectid"` //project id in equinix
21-
Token string `json:"token"` //token for authentication
22-
Metros []string `json:"metros"` //server location
23-
Plan string `json:"plan"` //server size
24-
OS string `json:"os"` //OS to install
21+
ProjectID string `json:"projectid"` //project id in equinix
22+
Token string `json:"token"` //token for authentication
23+
Metros []string `json:"metros"` //server location
24+
Plan string `json:"plan"` //server size
25+
OS string `json:"os"` //OS to install
26+
UserData string `json:"userdata,omitempty"` //Cloud-init user-data script for initial server setup
2527
}
2628

2729
type equinixProvider struct {
@@ -37,6 +39,7 @@ func EquinixProviderFactory(providerInfo string, secretData map[string][]byte, l
3739
Metros: []string{"da", "ny", "sv"},
3840
Plan: "c3.small.x86",
3941
OS: "rocky_8",
42+
UserData: "",
4043
}
4144

4245
if configJson, ok := secretData["config"]; ok {
@@ -45,6 +48,16 @@ func EquinixProviderFactory(providerInfo string, secretData map[string][]byte, l
4548
}
4649
}
4750

51+
if config.UserData != "" {
52+
// Provided userdata from secret should be base64 encoded
53+
decodedBytes, err := base64.StdEncoding.DecodeString(config.UserData)
54+
if err != nil {
55+
return nil, fmt.Errorf("error decoding userdata: %w", err)
56+
}
57+
58+
config.UserData = string(decodedBytes)
59+
}
60+
4861
key := config.ProjectID + config.Token
4962

5063
if _, ok := eqClients[key]; !ok {
@@ -90,6 +103,7 @@ func (p *equinixProvider) Acquire(poolSize int, poolName string, poolType string
90103
OS: p.config.OS,
91104
ProjectID: p.config.ProjectID,
92105
Tags: []string{poolName},
106+
UserData: p.config.UserData,
93107
}
94108

95109
device, _, err := p.client.Devices.Create(&cr)

0 commit comments

Comments
 (0)