From 8acc76268af1f11a8af99ce3f5455a981bb15e79 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Sun, 22 May 2022 20:35:32 +0200 Subject: [PATCH] Switch from datacenter to location parameter --- README.md | 2 +- config.go | 6 +++--- main.go | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3461c65..d33eeee 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ For authentication it uses the SSH agent, so ensure the private counterpart to t [hcloud] token = "" server_type = "cx11" -datacenter = "nbg1" +location = "nbg1" ssh_key = "" private_network = "" diff --git a/config.go b/config.go index 9a8c01b..df2fb5a 100644 --- a/config.go +++ b/config.go @@ -12,7 +12,7 @@ type hcloudConfig struct { SSHKeyPrivatePath string `toml:"ssh_key_private_path"` PrivateNetwork string `toml:"private_network"` ServerType string `toml:"server_type"` - Datacenter string + Location string Image string } @@ -41,8 +41,8 @@ func verifyConfig(conf *config) error { if conf.HCloud.ServerType == "" { return errors.New("server type missing") } - if conf.HCloud.Datacenter == "" { - return errors.New("datacenter missing") + if conf.HCloud.Location == "" { + return errors.New("location missing") } if conf.HCloud.Image == "" { conf.HCloud.Image = "debian-11" diff --git a/main.go b/main.go index 1165513..10196b1 100644 --- a/main.go +++ b/main.go @@ -118,8 +118,6 @@ func main() { serverExists = false } - serverTypeName := cfg.HCloud.ServerType - datacenterName := cfg.HCloud.Datacenter if serverExists { log.Printf("server '%s' (id %d) already exists, checking for necessary changes\n", serverName, server.ID) // check if redeploy is necessary -- fetching user data afterwards not possible, maybe cache locally/connect to server? @@ -150,7 +148,7 @@ func main() { log.Printf("creating server '%s'", serverName) // create server startAfterCreate := false - serverType, _, err := client.ServerType.GetByName(context.Background(), serverTypeName) + serverType, _, err := client.ServerType.GetByName(context.Background(), cfg.HCloud.ServerType) if err != nil { log.Fatalf("error finding server type: %v\n", err) } @@ -158,13 +156,16 @@ func main() { if err != nil { log.Fatalf("error finding image: %v\n", err) } - datacenter, _, err := client.Datacenter.GetByName(context.Background(), datacenterName) + location, _, err := client.Location.GetByName(context.Background(), cfg.HCloud.Location) + if err != nil { + log.Fatalf("error finding location: %v\n", err) + } createOpts := hcloud.ServerCreateOpts{ Name: serverName, StartAfterCreate: &startAfterCreate, ServerType: serverType, Image: image, - Datacenter: datacenter, + Location: location, SSHKeys: []*hcloud.SSHKey{sshKey}, Networks: []*hcloud.Network{privateNetwork}, }