Skip to content
Open
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
7 changes: 3 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.

3 changes: 1 addition & 2 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.

12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/fatih/structs v1.1.0
github.com/goccy/go-yaml v1.19.2
github.com/guptarohit/asciigraph v0.10.0
github.com/hetznercloud/hcloud-go/v2 v2.44.0
github.com/hetznercloud/hcloud-go/v2 v2.45.0
github.com/jedib0t/go-pretty/v6 v6.8.2
github.com/spf13/cast v1.10.0
github.com/spf13/cobra v1.10.2
Expand All @@ -21,11 +21,11 @@ require (
github.com/stretchr/testify v1.11.1
github.com/swaggest/assertjson v1.10.0
go.uber.org/mock v0.6.0
golang.org/x/crypto v0.53.0
golang.org/x/crypto v0.54.0
golang.org/x/exp v0.0.0-20260611194520-c48552f49976
golang.org/x/net v0.56.0
golang.org/x/term v0.44.0
golang.org/x/text v0.39.0
golang.org/x/net v0.57.0
golang.org/x/term v0.45.0
golang.org/x/text v0.40.0
)

require (
Expand Down Expand Up @@ -59,7 +59,7 @@ require (
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/sys v0.47.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/guptarohit/asciigraph v0.10.0 h1:LmbFXSHZOhaQxjJYexdRk7TzoC5sJ7vDTEjP1YUbKgY=
github.com/guptarohit/asciigraph v0.10.0/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag=
github.com/hetznercloud/hcloud-go/v2 v2.44.0 h1:1p9qwaZ/H55nLP9c7WfuwUA0LfsexS2YHOhD8+iBga8=
github.com/hetznercloud/hcloud-go/v2 v2.44.0/go.mod h1:d0s2WLe7jSoStamv3eHoWgBSOxc/K17tYSXsqUkbse0=
github.com/hetznercloud/hcloud-go/v2 v2.45.0 h1:0TnAwVUK/DJzEacOcY6IcbISJOIqldUjvaFpuVz8Mbk=
github.com/hetznercloud/hcloud-go/v2 v2.45.0/go.mod h1:pdG7fFGlYsCAaJ9r0QOIF0O6wQcpbJxT2VT8aP6XlIc=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -119,19 +119,19 @@ go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
golang.org/x/exp v0.0.0-20260611194520-c48552f49976 h1:X8Hz2ImujgbmetVuW+w2YkyZChE3cBpZi2P158rTG9M=
golang.org/x/exp v0.0.0-20260611194520-c48552f49976/go.mod h1:vnf4pv9iKZXY58sQE1L86zmNWJ4159e1RkcWiLCkeEY=
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus=
golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=
golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w=
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
16 changes: 7 additions & 9 deletions internal/cmd/all/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ func TestListAll(t *testing.T) {
IP: net.ParseIP("192.0.2.1"),
},
},
Created: time.Now().Add(-72 * time.Hour),
Location: &hcloud.Location{Name: "hel1"},
Datacenter: &hcloud.Datacenter{Name: "hel1-dc2"},
Created: time.Now().Add(-72 * time.Hour),
Location: &hcloud.Location{Name: "hel1"},
},
}, nil)
fx.Client.NetworkClient.EXPECT().
Expand Down Expand Up @@ -102,12 +101,11 @@ func TestListAll(t *testing.T) {
AllWithOpts(gomock.Any(), hcloud.PrimaryIPListOpts{}).
Return([]*hcloud.PrimaryIP{
{
ID: 123,
Name: "test",
Created: time.Now().Add(-2 * time.Hour),
Datacenter: &hcloud.Datacenter{Name: "fsn1-dc14"},
Type: hcloud.PrimaryIPTypeIPv4,
IP: net.ParseIP("127.0.0.1"),
ID: 123,
Name: "test",
Created: time.Now().Add(-2 * time.Hour),
Type: hcloud.PrimaryIPTypeIPv4,
IP: net.ParseIP("127.0.0.1"),
},
}, nil)
fx.Client.FloatingIPClient.EXPECT().
Expand Down
29 changes: 5 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,11 +20,11 @@ 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.
The --datacenter flag has been removed. 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
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.

See https://docs.hetzner.cloud/changelog#2026-04-27-primary-ips-will-return-unassigned
Expand All @@ -48,26 +47,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 +104,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
22 changes: 10 additions & 12 deletions internal/cmd/primaryip/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ func TestCreate(t *testing.T) {
nil,
)

fx.Client.LocationClient.EXPECT().
Get(gomock.Any(), "fsn1").
Return(&hcloud.Location{Name: "fsn1"}, &hcloud.Response{}, nil)
fx.ActionWaiter.EXPECT().
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 321})
fx.Client.PrimaryIPClient.EXPECT().
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 +90,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 @@ -119,16 +115,18 @@ func TestCreateJSON(t *testing.T) {
Action: &hcloud.Action{ID: 321},
}, nil, nil)

fx.Client.LocationClient.EXPECT().
Get(gomock.Any(), "fsn1").
Return(&hcloud.Location{Name: "fsn1"}, nil, nil)
fx.ActionWaiter.EXPECT().
WaitForActions(gomock.Any(), gomock.Any(), &hcloud.Action{ID: 321})
fx.Client.PrimaryIPClient.EXPECT().
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 @@ -72,12 +71,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
Loading
Loading