Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/reference/manual/hcloud_primary-ip_create.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions docs/reference/manual/hcloud_server_create.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/reference/manual/hcloud_server_list.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions internal/cmd/primaryip/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package primaryip

import (
"fmt"
"strings"

"github.com/spf13/cobra"

Expand All @@ -21,9 +20,6 @@ var CreateCmd = base.CreateCmd[*hcloud.PrimaryIP]{
Short: "Create a Primary IP",
Long: `Create a Primary IP.

The --datacenter flag is deprecated. Use --location or --assignee-id instead.
See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.

The --assignee-type flag will be required together with the --assignee-id flag. Using
the default value (server) for the --assignee-type flag is deprecated. Consider
explicitly setting the --assignee-type flag.
Expand All @@ -48,26 +44,22 @@ and https://docs.hetzner.cloud/changelog#2026-04-27-primary-ips-make-assignee_ty
cmd.Flags().String("location", "", "Location (ID or name) of Primary IP")
_ = cmd.RegisterFlagCompletionFunc("location", cmpl.SuggestCandidatesF(client.Location().Names))

cmd.Flags().String("datacenter", "", "Datacenter (name) (deprecated)")
_ = cmd.RegisterFlagCompletionFunc("datacenter", cmpl.SuggestCandidatesF(client.Datacenter().Names))

cmd.Flags().StringToString("label", nil, "User-defined labels ('key=value') (can be specified multiple times)")

cmd.Flags().StringSlice("enable-protection", []string{}, "Enable protection (delete) (default: none)")
_ = cmd.RegisterFlagCompletionFunc("enable-protection", cmpl.SuggestCandidates("delete"))

cmd.Flags().Bool("auto-delete", false, "Delete Primary IP if assigned resource is deleted (true, false)")

cmd.MarkFlagsOneRequired("assignee-id", "datacenter", "location")
cmd.MarkFlagsMutuallyExclusive("assignee-id", "datacenter", "location")
cmd.MarkFlagsOneRequired("assignee-id", "location")
cmd.MarkFlagsMutuallyExclusive("assignee-id", "location")
return cmd
},
Run: func(s state.State, cmd *cobra.Command, _ []string) (*hcloud.PrimaryIP, any, error) {
typ, _ := cmd.Flags().GetString("type")
name, _ := cmd.Flags().GetString("name")
assigneeID, _ := cmd.Flags().GetInt64("assignee-id")
assigneeType, _ := cmd.Flags().GetString("assignee-type")
datacenter, _ := cmd.Flags().GetString("datacenter")
locationIDOrName, _ := cmd.Flags().GetString("location")
labels, _ := cmd.Flags().GetStringToString("label")
protection, _ := cmd.Flags().GetStringSlice("enable-protection")
Expand Down Expand Up @@ -109,20 +101,6 @@ and https://docs.hetzner.cloud/changelog#2026-04-27-primary-ips-make-assignee_ty
}
createOpts.Location = location.Name
}
if cmd.Flags().Changed("datacenter") {
cmd.PrintErrln("Warning: The --datacenter flag is deprecated. Use --location or --assignee-id instead.")

// Backward compatible datacenter argument.
// datacenter hel1-dc2 => location hel1
parts := strings.Split(datacenter, "-")

if len(parts) != 2 {
return nil, nil, fmt.Errorf("Datacenter name is not valid, expected format $LOCATION-$DATACENTER, but got: %s", datacenter)
}

locationName := parts[0]
createOpts.Location = locationName
}

result, _, err := s.Client().PrimaryIP().Create(s, createOpts)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions internal/cmd/primaryip/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func TestCreate(t *testing.T) {
Labels: map[string]string{"foo": "bar"},
}

fx.Client.LocationClient.EXPECT().
Get(gomock.Any(), "fsn1").
Return(&hcloud.Location{Name: "fsn1"}, &hcloud.Response{}, nil)

fx.Client.PrimaryIPClient.EXPECT().
Create(
gomock.Any(),
Expand All @@ -59,16 +63,14 @@ func TestCreate(t *testing.T) {
GetByID(gomock.Any(), primaryIP.ID).
Return(primaryIP, &hcloud.Response{}, nil)

out, errOut, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14", "--auto-delete", "--label", "foo=bar"})

expErr := "Warning: The --datacenter flag is deprecated. Use --location or --assignee-id instead.\n"
out, errOut, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--location=fsn1", "--auto-delete", "--label", "foo=bar"})

expOut := `Primary IP 1 created
IPv4: 192.168.2.1
`

require.NoError(t, err)
assert.Equal(t, expErr, errOut)
assert.Empty(t, errOut)
assert.Equal(t, expOut, out)
}

Expand All @@ -89,11 +91,6 @@ func TestCreateJSON(t *testing.T) {
Location: &hcloud.Location{
Name: "fsn1",
},
Datacenter: &hcloud.Datacenter{
ID: 1,
Name: "fsn1-dc14",
Location: &hcloud.Location{ID: 1, Name: "fsn1"},
},
Created: time.Date(2016, 1, 30, 23, 50, 0, 0, time.UTC),
Labels: map[string]string{"foo": "bar"},
AutoDelete: true,
Expand All @@ -102,6 +99,10 @@ func TestCreateJSON(t *testing.T) {
DNSPtr: map[string]string{},
}

fx.Client.LocationClient.EXPECT().
Get(gomock.Any(), "fsn1").
Return(&hcloud.Location{Name: "fsn1"}, nil, nil)

fx.Client.PrimaryIPClient.EXPECT().
Create(
gomock.Any(),
Expand All @@ -125,10 +126,9 @@ func TestCreateJSON(t *testing.T) {
GetByID(gomock.Any(), primaryIP.ID).
Return(primaryIP, nil, nil)

jsonOut, out, err := fx.Run(cmd, []string{"-o=json", "--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14", "--auto-delete", "--label", "foo=bar"})
jsonOut, out, err := fx.Run(cmd, []string{"-o=json", "--name=my-ip", "--type=ipv4", "--location=fsn1", "--auto-delete", "--label", "foo=bar"})

expOut := `Warning: The --datacenter flag is deprecated. Use --location or --assignee-id instead.
Primary IP 1 created
expOut := `Primary IP 1 created
`

require.NoError(t, err)
Expand Down
9 changes: 1 addition & 8 deletions internal/cmd/primaryip/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/spf13/cobra"

"github.com/hetznercloud/cli/internal/cmd/base"
"github.com/hetznercloud/cli/internal/cmd/datacenter"
"github.com/hetznercloud/cli/internal/cmd/location"
"github.com/hetznercloud/cli/internal/cmd/util"
"github.com/hetznercloud/cli/internal/hcapi2"
Expand All @@ -27,7 +26,7 @@ var DescribeCmd = base.DescribeCmd[*hcloud.PrimaryIP]{
}
return ip, hcloud.SchemaFromPrimaryIP(ip), nil
},
PrintText: func(s state.State, _ *cobra.Command, out io.Writer, primaryIP *hcloud.PrimaryIP) error {
PrintText: func(_ state.State, _ *cobra.Command, out io.Writer, primaryIP *hcloud.PrimaryIP) error {
fmt.Fprintf(out, "ID:\t%d\n", primaryIP.ID)
fmt.Fprintf(out, "Name:\t%s\n", primaryIP.Name)
fmt.Fprintf(out, "Created:\t%s (%s)\n", util.Datetime(primaryIP.Created), humanize.Time(primaryIP.Created))
Expand Down Expand Up @@ -66,12 +65,6 @@ var DescribeCmd = base.DescribeCmd[*hcloud.PrimaryIP]{
fmt.Fprintf(out, "Location:\n")
fmt.Fprintf(out, "%s", util.PrefixLines(location.DescribeLocation(primaryIP.Location), " "))

if primaryIP.Datacenter != nil {
fmt.Fprintln(out)
fmt.Fprintf(out, "Datacenter:\n")
fmt.Fprintf(out, "%s", util.PrefixLines(datacenter.DescribeDatacenter(s.Client(), primaryIP.Datacenter, true), " "))
}

return nil
},
}
15 changes: 0 additions & 15 deletions internal/cmd/primaryip/testdata/create_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
"name": "fsn1",
"network_zone": ""
},
"datacenter": {
"description": "",
"id": 1,
"location": {
"city": "",
"country": "",
"description": "",
"id": 1,
"latitude": 0,
"longitude": 0,
"name": "fsn1",
"network_zone": ""
},
"name": "fsn1-dc14"
},
"dns_ptr": [],
"id": 1,
"ip": "192.168.2.1",
Expand Down
47 changes: 1 addition & 46 deletions internal/cmd/server/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"mime/multipart"
"net/textproto"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -42,10 +41,7 @@ var CreateCmd = base.CreateCmd[*createResult]{
cmd := &cobra.Command{
Use: "create [options] --name <name> --type <server-type> --image <image>",
Short: "Create a Server",
Long: `Create a Server.

The --datacenter flag is deprecated. Use --location instead.
See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.`,
Long: `Create a Server.`,
}

cmd.Flags().String("name", "", "Server name (required)")
Expand All @@ -62,9 +58,6 @@ See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.`,
cmd.Flags().String("location", "", "Location (ID or name)")
_ = cmd.RegisterFlagCompletionFunc("location", cmpl.SuggestCandidatesF(client.Location().Names))

cmd.Flags().String("datacenter", "", "Datacenter (ID or name) (deprecated)")
_ = cmd.RegisterFlagCompletionFunc("datacenter", cmpl.SuggestCandidatesF(client.Datacenter().Names))

cmd.Flags().StringSlice("ssh-key", nil, "ID or name of SSH Key to inject (can be specified multiple times)")
_ = cmd.RegisterFlagCompletionFunc("ssh-key", cmpl.SuggestCandidatesF(client.SSHKey().Names))

Expand Down Expand Up @@ -114,8 +107,6 @@ See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.`,
var locName string
if createOpts.Location != nil {
locName = createOpts.Location.Name
} else if createOpts.Datacenter != nil {
locName = createOpts.Datacenter.Location.Name
}

cmd.Print(deprecatedServerTypeWarning(createOpts.ServerType, locName))
Expand Down Expand Up @@ -275,7 +266,6 @@ func createOptsFromFlags(
serverTypeName, _ := flags.GetString("type")
imageIDorName, _ := flags.GetString("image")
locationIDOrName, _ := flags.GetString("location")
datacenterIDOrName, _ := flags.GetString("datacenter")
userDataFiles, _ := flags.GetStringArray("user-data-from-file")
startAfterCreate, _ := flags.GetBool("start-after-create")
sshKeys, _ := flags.GetStringSlice("ssh-key")
Expand Down Expand Up @@ -438,41 +428,6 @@ func createOptsFromFlags(
createOpts.Firewalls = append(createOpts.Firewalls, &hcloud.ServerCreateFirewall{Firewall: *firewall})
}

if datacenterIDOrName != "" {
cmd.PrintErrln("Warning: The --datacenter flag is deprecated. Use --location instead.")

// If parseable as ID -> GetByID and use Location Name
// Else -> Backwards-compatible split
var datacenterID int64
datacenterID, err = strconv.ParseInt(datacenterIDOrName, 10, 64)
if err == nil {
// Input was a valid number/ID
var datacenter *hcloud.Datacenter
datacenter, _, err = s.Client().Datacenter().GetByID(s, datacenterID)
if err != nil {
return
}
if datacenter == nil {
err = fmt.Errorf("Datacenter not found: %s", datacenterIDOrName)
return
}
createOpts.Location = datacenter.Location
} else {
// Input was not a valid number/ID, probably DC name

// Backward compatible datacenter argument.
// datacenter hel1-dc2 => location hel1
parts := strings.Split(datacenterIDOrName, "-")

if len(parts) != 2 {
err = fmt.Errorf("Datacenter name is not valid, expected format $LOCATION-$DATACENTER, but got: %s", datacenterIDOrName)
return
}

createOpts.Location = &hcloud.Location{Name: parts[0]}
}
}

if locationIDOrName != "" {
var location *hcloud.Location
location, _, err = s.Client().Location().Get(s, locationIDOrName)
Expand Down
8 changes: 0 additions & 8 deletions internal/cmd/server/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ func TestCreateJSON(t *testing.T) {
},
Created: time.Date(2016, 1, 30, 23, 50, 0, 0, time.UTC),
Labels: make(map[string]string),
Datacenter: &hcloud.Datacenter{
ID: 1,
Name: "fsn1-dc14",
Location: &hcloud.Location{
ID: 1,
Name: "fsn1",
},
},
ServerType: &hcloud.ServerType{
ID: 1,
Name: "cpx22",
Expand Down
7 changes: 0 additions & 7 deletions internal/cmd/server/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"

"github.com/hetznercloud/cli/internal/cmd/base"
"github.com/hetznercloud/cli/internal/cmd/datacenter"
"github.com/hetznercloud/cli/internal/cmd/image"
"github.com/hetznercloud/cli/internal/cmd/iso"
"github.com/hetznercloud/cli/internal/cmd/location"
Expand Down Expand Up @@ -149,12 +148,6 @@ var DescribeCmd = base.DescribeCmd[*hcloud.Server]{
fmt.Fprintf(out, "Location:\n")
fmt.Fprint(out, util.PrefixLines(location.DescribeLocation(server.Location), " "))

if server.Datacenter != nil {
fmt.Fprintln(out)
fmt.Fprintf(out, "Datacenter:\n")
fmt.Fprintf(out, "%s", util.PrefixLines(datacenter.DescribeDatacenter(s.Client(), server.Datacenter, true), " "))
}

fmt.Fprintln(out)
if server.BackupWindow != "" {
fmt.Fprintf(out, "Backup Window:\t%s\n", server.BackupWindow)
Expand Down
9 changes: 1 addition & 8 deletions internal/cmd/server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ var ListCmd = &base.ListCmd[*hcloud.Server, schema.Server]{
AddFieldFn("outgoing_traffic", func(server *hcloud.Server) string {
return humanize.IBytes(server.OutgoingTraffic)
}).
AddFieldFn("datacenter", func(server *hcloud.Server) string {
if server.Datacenter != nil {
return server.Datacenter.Name
}
return "-"
}).
AddFieldFn("location", func(server *hcloud.Server) string {
return server.Location.Name
}).
Expand Down Expand Up @@ -139,8 +133,7 @@ var ListCmd = &base.ListCmd[*hcloud.Server, schema.Server]{
return "-"
}
return server.PlacementGroup.Name
}).
MarkFieldAsDeprecated("datacenter", "The datacenter column is deprecated. Use location column instead.")
})
},

Schema: hcloud.SchemaFromServer,
Expand Down
Loading
Loading