Skip to content

Commit 0c82f2b

Browse files
committed
integrated cloud-init support (fix #10)
1 parent 8c24ac3 commit 0c82f2b

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ $ cp docker-machine-driver-hetzner /usr/local/bin/
4141

4242
## Options
4343

44-
- `--hetzner-api-token`: **required**. Your project-specific access token for the Hetzner Cloud API.
45-
- `--hetzner-image`: The name of the Hetzner Cloud image to use, see [Images API](https://docs.hetzner.cloud/#resources-images-get) for how to get a list (defaults to `ubuntu-16.04`).
46-
- `--hetzner-server-type`: The type of the Hetzner Cloud server, see [Server Types API](https://docs.hetzner.cloud/#resources-server-types-get) for how to get a list (defaults to `cx11`).
47-
- `--hetzner-server-location`: The location to create the server in, see [Locations API](https://docs.hetzner.cloud/#resources-locations-get) for how to get a list.
44+
- `--hetzner-api-token`: **required**. Your project-specific access token for the Hetzner Cloud API.
45+
- `--hetzner-image`: The name of the Hetzner Cloud image to use, see [Images API](https://docs.hetzner.cloud/#resources-images-get) for how to get a list (defaults to `ubuntu-16.04`).
46+
- `--hetzner-server-type`: The type of the Hetzner Cloud server, see [Server Types API](https://docs.hetzner.cloud/#resources-server-types-get) for how to get a list (defaults to `cx11`).
47+
- `--hetzner-server-location`: The location to create the server in, see [Locations API](https://docs.hetzner.cloud/#resources-locations-get) for how to get a list.
4848
**NOTICE: Beware that Hetzner does not reject invalid location names at the time of writing this; instead, a seemingly random location is chosen. Double check both the option value's
4949
spelling and the newly created server to make sure the desired location was chosen indeed.**
50-
- `--hetzner-existing-key-path`: Use an existing (local) SSH key instead of generating a new keypair.
51-
- `--hetzner-existing-key-id`: **requires `--hetzner-existing-key-path`**. Use an existing (remote) SSH key instead of uploading the imported key pair,
52-
see [SSH Keys API](https://docs.hetzner.cloud/#resources-ssh-keys-get) for how to get a list
50+
- `--hetzner-existing-key-path`: Use an existing (local) SSH key instead of generating a new keypair.
51+
- `--hetzner-existing-key-id`: **requires `--hetzner-existing-key-path`**. Use an existing (remote) SSH key instead of uploading the imported key pair,
52+
see [SSH Keys API](https://docs.hetzner.cloud/#resources-ssh-keys-get) for how to get a list
53+
- `--hetzner-user-data`: Cloud-init based User data
5354

5455
#### Existing SSH keys
5556

@@ -76,6 +77,7 @@ was used during creation.
7677
| `--hetzner-server-location` | `HETZNER_LOCATION` | - *(let Hetzner choose)* |
7778
| `--hetzner-existing-key-path` | `HETZNER_EXISTING_KEY_PATH` | - *(generate new keypair)* |
7879
| `--hetzner-existing-key-id` | `HETZNER_EXISTING_KEY_ID` | 0 *(upload new key)* |
80+
| `--hetzner-user-data` | `HETZNER_USER_DATA` | - |
7981

8082

8183
## Building from source

driver.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Driver struct {
3535
originalKey string
3636
danglingKey bool
3737
ServerID int
38+
userData string
3839
cachedServer *hcloud.Server
3940
}
4041

@@ -48,6 +49,7 @@ const (
4849
flagLocation = "hetzner-server-location"
4950
flagExKeyID = "hetzner-existing-key-id"
5051
flagExKeyPath = "hetzner-existing-key-path"
52+
flagUserData = "hetzner-user-data"
5153
)
5254

5355
func NewDriver() *Driver {
@@ -105,6 +107,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
105107
Usage: "Path to existing key (new public key will be created unless --hetzner-existing-key-id is specified)",
106108
Value: "",
107109
},
110+
mcnflag.StringFlag{
111+
EnvVar: "HETZNER_USER_DATA",
112+
Name: flagUserData,
113+
Usage: "Cloud-init based User data",
114+
Value: "",
115+
},
108116
}
109117
}
110118

@@ -116,13 +124,13 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
116124
d.KeyID = opts.Int(flagExKeyID)
117125
d.IsExistingKey = d.KeyID != 0
118126
d.originalKey = opts.String(flagExKeyPath)
127+
d.userData = opts.String(flagUserData)
119128

120129
d.SetSwarmConfigFromFlags(opts)
121130

122131
if d.AccessToken == "" {
123132
return errors.Errorf("hetzner requires --%v to be set", flagAPIToken)
124133
}
125-
126134
return nil
127135
}
128136

@@ -208,7 +216,10 @@ func (d *Driver) Create() error {
208216

209217
log.Infof("Creating Hetzner server...")
210218

211-
srvopts := hcloud.ServerCreateOpts{Name: d.GetMachineName()}
219+
srvopts := hcloud.ServerCreateOpts{
220+
Name: d.GetMachineName(),
221+
UserData: d.userData,
222+
}
212223

213224
var err error
214225
if srvopts.Location, err = d.getLocation(); err != nil {

0 commit comments

Comments
 (0)