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
15 changes: 12 additions & 3 deletions mmv1/products/networkconnectivity/Transport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ properties:
- name: network
type: ResourceRef
description: |
Resource URL of the Network that will be peered with this Transport. This field must be provided during resource creation and cannot be changed.
Resource URL of the Network that will be peered with this Transport.
Exactly one of `network` or `hub` must be specified. This field is
immutable and cannot be changed after creation.
immutable: true
resource: Network
imports: selfLink
required: true
exactly_one_of:
- hub
- network
- name: advertisedRoutes
type: Array
description: |
Expand All @@ -144,11 +148,16 @@ properties:
- name: hub
type: ResourceRef
description: |
The NCC Hub that the Transport should attach to. The hub must be in the same project as the Transport.
The NCC Hub that the Transport should attach to. The hub must be in the
same project as the Transport. Exactly one of `network` or `hub` must be
specified. This field is immutable and cannot be changed after creation.
min_version: beta
resource: Hub
imports: selfLink
immutable: true
exactly_one_of:
- hub
- network
- name: pscRoutingEnabled
type: Boolean
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package networkconnectivity

import (
"slices"
"testing"
)

// TestUnitNetworkConnectivityTransport_networkHubExactlyOneOf guards against
// regressions of https://github.com/hashicorp/terraform-provider-google/issues/28425
// where `network` was incorrectly Required, blocking NCC hub-only Transports.
func TestUnitNetworkConnectivityTransport_networkHubExactlyOneOf(t *testing.T) {
t.Parallel()

r := ResourceNetworkConnectivityTransport()

network, ok := r.Schema["network"]
if !ok {
t.Fatal("expected network in schema")
}
if network.Required {
t.Error("network must not be Required; exactly one of network or hub must be set")
}
if !network.Optional {
t.Error("network should be Optional")
}
if !slices.Contains(network.ExactlyOneOf, "network") {
t.Errorf("network ExactlyOneOf = %v, want to include network", network.ExactlyOneOf)
}

hub, ok := r.Schema["hub"]
if !ok {
// hub is beta-only; on GA it is omitted and ExactlyOneOf is filtered to network alone.
if len(network.ExactlyOneOf) != 1 || network.ExactlyOneOf[0] != "network" {
t.Errorf("GA network ExactlyOneOf = %v, want [network]", network.ExactlyOneOf)
}
return
}

if hub.Required {
t.Error("hub must not be Required")
}
if !hub.Optional {
t.Error("hub should be Optional")
}
if !slices.Contains(network.ExactlyOneOf, "hub") {
t.Errorf("network ExactlyOneOf = %v, want to include hub", network.ExactlyOneOf)
}
if !slices.Contains(hub.ExactlyOneOf, "hub") || !slices.Contains(hub.ExactlyOneOf, "network") {
t.Errorf("hub ExactlyOneOf = %v, want hub and network", hub.ExactlyOneOf)
}
}
Loading