diff --git a/internal/cmd/affinity-groups/create/create_test.go b/internal/cmd/affinity-groups/create/create_test.go index e547a4990..f58fe7dc9 100644 --- a/internal/cmd/affinity-groups/create/create_test.go +++ b/internal/cmd/affinity-groups/create/create_test.go @@ -121,6 +121,26 @@ func TestParseInput(t *testing.T) { }, ), }, + { + description: "fails public project without network area and without billing reference", + flagValues: fixtureFlagValues( + func(flagValues map[string]string) { + flagValues["label"] = "scope=PUBLIC" + delete(flagValues, "network-area-id") + }, + ), + isValid: false, + }, + { + description: "fails public project with empty billing reference", + flagValues: fixtureFlagValues( + func(flagValues map[string]string) { + flagValues["label"] = "scope=PUBLIC,billingReference=" + delete(flagValues, "network-area-id") + }, + ), + isValid: false, + }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { diff --git a/internal/cmd/project/create/create.go b/internal/cmd/project/create/create.go index ef95167e9..5343934f2 100644 --- a/internal/cmd/project/create/create.go +++ b/internal/cmd/project/create/create.go @@ -112,6 +112,8 @@ func configureFlags(cmd *cobra.Command) { func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) { globalFlags := globalflags.Parse(p, cmd) + networkAreaId := flags.FlagToStringPointer(p, cmd, networkAreaIdFlag) + labels := flags.FlagToStringToStringPointer(p, cmd, labelFlag) if labels != nil { labelKeyRegex := regexp.MustCompile(labelKeyRegex) @@ -131,6 +133,18 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, } } } + + if scope, hasScope := (*labels)["scope"]; hasScope && scope == "PUBLIC" { + billingReference, hasBilling := (*labels)["billingReference"] + + if networkAreaId == nil && (!hasBilling || billingReference == "") { + return nil, &errors.FlagValidationError{ + Flag: labelFlag, + Details: "creating a standalone public project (without a network area) requires a 'billingReference' label (e.g., --label billingReference=)", + } + } + } + } model := inputModel{