Skip to content

Commit 10f7e8b

Browse files
prauczli82016
authored andcommitted
add auto_accept_projects in ncc group (GoogleCloudPlatform#11828)
Co-authored-by: Zhenhua Li <[email protected]>
1 parent 31c6b85 commit 10f7e8b

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the License);
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
name: Group
15+
legacy_long_form_project: true
16+
base_url: projects/{{project}}/locations/global/hubs/{{hub}}/groups
17+
create_url: projects/{{project}}/locations/global/hubs/{{hub}}/groups/{{name}}?updateMask=autoAccept.autoAcceptProjects,labels,description
18+
update_url: projects/{{project}}/locations/global/hubs/{{hub}}/groups/{{name}}?updateMask=autoAccept.autoAcceptProjects,labels,description
19+
self_link: projects/{{project}}/locations/global/hubs/{{hub}}/groups/{{name}}
20+
create_verb: 'PATCH'
21+
update_verb: 'PATCH'
22+
references:
23+
guides:
24+
'Official Documentation': 'https://cloud.google.com/network-connectivity/docs/network-connectivity-center/concepts/overview'
25+
api: 'https://cloud.google.com/network-connectivity/docs/reference/networkconnectivity/rest/v1beta/projects.locations.global.hubs.groups'
26+
async:
27+
type: 'OpAsync'
28+
operation:
29+
path: 'name'
30+
base_url: '{{op_id}}'
31+
wait_ms: 1000
32+
result:
33+
path: 'targetLink'
34+
error:
35+
path: 'error/errors'
36+
message: 'message'
37+
# A handwritten sweeper is needed as the resource name can only be `default`, `center`, and `edge`.
38+
exclude_sweeper: true
39+
examples:
40+
- name: 'network_connectivity_group_basic'
41+
primary_resource_id: 'primary'
42+
vars:
43+
hub_name: "network-connectivity-hub1"
44+
auto_accept_project_1_name: "foo"
45+
auto_accept_project_2_name: "bar"
46+
description: The NetworkConnectivity Group resource
47+
parameters:
48+
- name: 'hub'
49+
type: ResourceRef
50+
resource: 'Hub'
51+
imports: 'id'
52+
description: |
53+
The name of the hub. Hub names must be unique. They use the following form: projects/{projectNumber}/locations/global/hubs/{hubId}
54+
immutable: true
55+
required: true
56+
url_param_only: true
57+
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
58+
properties:
59+
- name: name
60+
type: Enum
61+
description: 'The name of the group. Group names must be unique.'
62+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
63+
required: true
64+
immutable: true
65+
custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
66+
enum_values:
67+
- 'default'
68+
- 'center'
69+
- 'edge'
70+
- name: createTime
71+
type: String
72+
description: Output only. The time the hub was created.
73+
output: true
74+
- name: updateTime
75+
type: String
76+
description: Output only. The time the hub was last updated.
77+
output: true
78+
- name: labels
79+
type: KeyValueLabels
80+
description: Optional labels in key:value format. For more information about labels, see [Requirements for labels](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements).
81+
- name: description
82+
type: String
83+
description: An optional description of the group.
84+
- name: uid
85+
type: String
86+
description: Output only. The Google-generated UUID for the group. This value is unique across all group resources. If a group is deleted and another with the same name is created, the new route table is assigned a different uniqueId.
87+
output: true
88+
- name: state
89+
type: String
90+
description: Output only. The current lifecycle state of this hub.
91+
output: true
92+
exactly_one_of:
93+
- CREATING
94+
- ACTIVE
95+
- DELETING
96+
- name: autoAccept
97+
type: NestedObject
98+
description: Optional. The auto-accept setting for this group.
99+
properties:
100+
- name: autoAcceptProjects
101+
type: Array
102+
description: 'A list of project ids or project numbers for which you want to enable auto-accept. The auto-accept setting is applied to spokes being created or updated in these projects.'
103+
required: true
104+
item_type:
105+
type: String
106+
- name: routeTable
107+
type: String
108+
description: 'Output only. The name of the route table that corresponds to this group. They use the following form: `projects/{projectNumber}/locations/global/hubs/{hubId}/routeTables/{route_table_id}`'
109+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "google_network_connectivity_hub" "basic_hub" {
2+
name = "{{index $.Vars "hub_name"}}"
3+
description = "A sample hub"
4+
labels = {
5+
label-one = "value-one"
6+
}
7+
}
8+
9+
resource "google_network_connectivity_group" "{{$.PrimaryResourceId}}" {
10+
hub = google_network_connectivity_hub.basic_hub.id
11+
name = "default"
12+
labels = {
13+
label-one = "value-one"
14+
}
15+
description = "A sample hub group"
16+
auto_accept {
17+
auto_accept_projects = [
18+
"{{index $.Vars "auto_accept_project_1_name"}}",
19+
"{{index $.Vars "auto_accept_project_2_name"}}",
20+
]
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package networkconnectivity_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
func TestAccNetworkConnectivityGroup_BasicGroup(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"project_name": envvar.GetTestProjectFromEnv(),
17+
"hub_random_suffix": acctest.RandString(t, 10),
18+
"project_random_suffix_1": acctest.RandString(t, 10),
19+
"project_random_suffix_2": acctest.RandString(t, 10),
20+
}
21+
22+
acctest.VcrTest(t, resource.TestCase{
23+
PreCheck: func() { acctest.AccTestPreCheck(t) },
24+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
25+
CheckDestroy: testAccCheckNetworkConnectivityGroupDestroyProducer(t),
26+
Steps: []resource.TestStep{
27+
{
28+
Config: testAccNetworkConnectivityGroup_BasicGroup(context),
29+
},
30+
{
31+
ResourceName: "google_network_connectivity_group.primary",
32+
ImportState: true,
33+
ImportStateVerify: true,
34+
ImportStateVerifyIgnore: []string{"hub", "labels", "terraform_labels"},
35+
},
36+
{
37+
Config: testAccNetworkConnectivityGroup_BasicGroupUpdate0(context),
38+
},
39+
{
40+
ResourceName: "google_network_connectivity_group.primary",
41+
ImportState: true,
42+
ImportStateVerify: true,
43+
ImportStateVerifyIgnore: []string{"hub", "labels", "terraform_labels"},
44+
},
45+
},
46+
})
47+
}
48+
49+
func testAccNetworkConnectivityGroup_BasicGroup(context map[string]interface{}) string {
50+
return acctest.Nprintf(`
51+
resource "google_network_connectivity_hub" "basic_hub" {
52+
name = "tf-test-hub%{hub_random_suffix}"
53+
description = "A sample hub"
54+
project = "%{project_name}"
55+
labels = {
56+
label-one = "value-one"
57+
}
58+
}
59+
resource "google_network_connectivity_group" "primary" {
60+
hub = google_network_connectivity_hub.basic_hub.id
61+
name = "default"
62+
labels = {
63+
label-one = "value-one"
64+
}
65+
description = "A sample group"
66+
auto_accept {
67+
auto_accept_projects = ["tf-test-name%{project_random_suffix_1}"]
68+
}
69+
}
70+
`, context)
71+
}
72+
73+
func testAccNetworkConnectivityGroup_BasicGroupUpdate0(context map[string]interface{}) string {
74+
return acctest.Nprintf(`
75+
resource "google_network_connectivity_hub" "basic_hub" {
76+
name = "tf-test-hub%{hub_random_suffix}"
77+
description = "A sample hub"
78+
project = "%{project_name}"
79+
labels = {
80+
label-one = "value-one"
81+
}
82+
}
83+
resource "google_network_connectivity_group" "primary" {
84+
hub = google_network_connectivity_hub.basic_hub.id
85+
name = "default"
86+
labels = {
87+
label-two = "value-one"
88+
}
89+
description = "An updated sample group"
90+
auto_accept {
91+
auto_accept_projects = ["tf-test-name%{project_random_suffix_1}", "tf-test-name%{project_random_suffix_2}"]
92+
}
93+
}
94+
`, context)
95+
}

0 commit comments

Comments
 (0)