From 9b8175a2dd45169f662d41b65575d4ff6791c932 Mon Sep 17 00:00:00 2001 From: Herko Lategan Date: Mon, 23 Sep 2024 17:43:18 +0100 Subject: [PATCH] roachprod: validate cloud providers Previously, when calling the `create` command, it was possible to pass the same cloud twice by specifying `-c` or `--clouds` for the same provider more than once. There was no early validation that caught this and the resulting error after attempting to create the cluster was confusing. This change adds validation that warns the user, early on, a duplicate provider has been passed. Epic: None Release note: None --- pkg/cmd/roachprod/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/cmd/roachprod/main.go b/pkg/cmd/roachprod/main.go index 7c6fe1ca0a56..840f76d26259 100644 --- a/pkg/cmd/roachprod/main.go +++ b/pkg/cmd/roachprod/main.go @@ -1395,6 +1395,18 @@ func validateAndConfigure(cmd *cobra.Command, args []string) { _ = cmd.Flags().Set("arch", string(arch)) } } + + // Validate cloud providers, if set. + providersSet := make(map[string]struct{}) + for _, p := range createVMOpts.VMProviders { + if _, ok := vm.Providers[p]; !ok { + printErrAndExit(fmt.Errorf("unknown cloud provider %q", p)) + } + if _, ok := providersSet[p]; ok { + printErrAndExit(fmt.Errorf("duplicate cloud provider specified %q", p)) + } + providersSet[p] = struct{}{} + } } var updateCmd = &cobra.Command{