diff --git a/internal/cmd/firewall/create.go b/internal/cmd/firewall/create.go index e45824fc..22ba9c3d 100644 --- a/internal/cmd/firewall/create.go +++ b/internal/cmd/firewall/create.go @@ -83,6 +83,10 @@ var CreateCmd = base.Cmd{ return err } + if err := waiter.WaitForActions(ctx, result.Actions); err != nil { + return err + } + fmt.Printf("Firewall %d created\n", result.Firewall.ID) return nil diff --git a/internal/cmd/floatingip/create.go b/internal/cmd/floatingip/create.go index e9979fc2..1eef1fc3 100644 --- a/internal/cmd/floatingip/create.go +++ b/internal/cmd/floatingip/create.go @@ -94,6 +94,12 @@ var CreateCmd = base.Cmd{ return err } + if result.Action != nil { + if err := waiter.ActionProgress(ctx, result.Action); err != nil { + return err + } + } + fmt.Printf("Floating IP %d created\n", result.FloatingIP.ID) return changeProtection(ctx, client, waiter, result.FloatingIP, true, protectionOps) diff --git a/internal/cmd/placementgroup/create.go b/internal/cmd/placementgroup/create.go index 52352809..066907e5 100644 --- a/internal/cmd/placementgroup/create.go +++ b/internal/cmd/placementgroup/create.go @@ -27,7 +27,7 @@ var CreateCmd = base.Cmd{ cmd.MarkFlagRequired("type") return cmd }, - Run: func(ctx context.Context, client hcapi2.Client, actionWaiter state.ActionWaiter, cmd *cobra.Command, args []string) error { + Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, cmd *cobra.Command, args []string) error { name, _ := cmd.Flags().GetString("name") labels, _ := cmd.Flags().GetStringToString("label") placementGroupType, _ := cmd.Flags().GetString("type") @@ -43,6 +43,12 @@ var CreateCmd = base.Cmd{ return err } + if result.Action != nil { + if err := waiter.ActionProgress(ctx, result.Action); err != nil { + return err + } + } + fmt.Printf("Placement group %d created\n", result.PlacementGroup.ID) return nil diff --git a/internal/cmd/placementgroup/create_test.go b/internal/cmd/placementgroup/create_test.go index 761ac3d4..4b28d800 100644 --- a/internal/cmd/placementgroup/create_test.go +++ b/internal/cmd/placementgroup/create_test.go @@ -40,7 +40,10 @@ func TestCreate(t *testing.T) { fx.Client.PlacementGroupClient.EXPECT(). Create(gomock.Any(), opts). - Return(hcloud.PlacementGroupCreateResult{PlacementGroup: &placementGroup, Action: nil}, nil, nil) + Return(hcloud.PlacementGroupCreateResult{PlacementGroup: &placementGroup, Action: &hcloud.Action{ID: 321}}, nil, nil) + + fx.ActionWaiter.EXPECT(). + ActionProgress(gomock.Any(), &hcloud.Action{ID: 321}) out, err := fx.Run(cmd, []string{"--name", placementGroup.Name, "--type", string(placementGroup.Type)}) diff --git a/internal/cmd/primaryip/create.go b/internal/cmd/primaryip/create.go index fd0519a9..7f8423db 100644 --- a/internal/cmd/primaryip/create.go +++ b/internal/cmd/primaryip/create.go @@ -41,7 +41,7 @@ var CreateCmd = base.Cmd{ return cmd }, - Run: func(ctx context.Context, client hcapi2.Client, actionWaiter state.ActionWaiter, cmd *cobra.Command, args []string) error { + Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, cmd *cobra.Command, args []string) error { typ, _ := cmd.Flags().GetString("type") name, _ := cmd.Flags().GetString("name") assigneeID, _ := cmd.Flags().GetInt64("assignee-id") @@ -68,10 +68,16 @@ var CreateCmd = base.Cmd{ return err } + if result.Action != nil { + if err := waiter.ActionProgress(ctx, result.Action); err != nil { + return err + } + } + fmt.Printf("Primary IP %d created\n", result.PrimaryIP.ID) if len(protection) > 0 { - if err := changeProtection(ctx, client, actionWaiter, result.PrimaryIP, true, protectionOpts); err != nil { + if err := changeProtection(ctx, client, waiter, result.PrimaryIP, true, protectionOpts); err != nil { return err } } diff --git a/internal/cmd/primaryip/create_test.go b/internal/cmd/primaryip/create_test.go index 6e8e3576..1d157d9c 100644 --- a/internal/cmd/primaryip/create_test.go +++ b/internal/cmd/primaryip/create_test.go @@ -30,11 +30,15 @@ func TestCreate(t *testing.T) { Return( &hcloud.PrimaryIPCreateResult{ PrimaryIP: &hcloud.PrimaryIP{ID: 1}, + Action: &hcloud.Action{ID: 321}, }, &hcloud.Response{}, nil, ) + fx.ActionWaiter.EXPECT(). + ActionProgress(gomock.Any(), &hcloud.Action{ID: 321}) + out, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14"}) expOut := "Primary IP 1 created\n"