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
20 changes: 20 additions & 0 deletions internal/cmd/affinity-groups/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions internal/cmd/project/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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=<value>)",
}
}
}
Comment on lines +137 to +146

}

model := inputModel{
Expand Down