From ef014264ec80fbee5dea58f3ffc7f1a87880ccbf 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 737bb5ea3ad3..41a5ef1d9117 100644 --- a/pkg/cmd/roachprod/main.go +++ b/pkg/cmd/roachprod/main.go @@ -1709,6 +1709,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{