Skip to content

Commit a89d953

Browse files
authored
Memorystore Valkey Multi vpc support (#13355)
1 parent 0b9825a commit a89d953

8 files changed

+906
-3
lines changed

mmv1/products/memorystore/Instance.yaml

+33-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
name: 'Instance'
1616
description: A Google Cloud Memorystore instance.
1717
docs:
18+
references:
19+
guides:
20+
'Official Documentation': https://cloud.google.com/memorystore/docs/valkey/create-instances
21+
api: 'https://cloud.google.com/memorystore/docs/valkey/reference/rest/v1/projects.locations.instances'
1822
id_format: 'projects/{{project}}/locations/{{location}}/instances/{{instance_id}}'
1923
base_url: 'projects/{{project}}/locations/{{location}}/instances'
2024
self_link: 'projects/{{project}}/locations/{{location}}/instances/{{instance_id}}'
@@ -72,11 +76,10 @@ examples:
7276
'prevent_destroy': 'false'
7377
virtual_fields:
7478
- name: 'desired_psc_auto_connections'
75-
description: "Required. Immutable. User inputs for the auto-created
79+
description: "Immutable. User inputs for the auto-created
7680
PSC connections. "
7781
type: Array
7882
immutable: true
79-
required: true
8083
item_type:
8184
type: NestedObject
8285
properties:
@@ -155,6 +158,16 @@ properties:
155158
"Output only. Target number of replica nodes per shard for the
156159
instance. "
157160
output: true
161+
- name: 'targetEngineVersion'
162+
type: String
163+
description:
164+
"Output only. Target engine version for the instance."
165+
output: true
166+
- name: 'targetNodeType'
167+
type: String
168+
description:
169+
"Output only. Target node type for the instance."
170+
output: true
158171
- name: 'uid'
159172
type: String
160173
description: "Output only. System assigned, unique identifier for the instance. "
@@ -490,6 +503,24 @@ properties:
490503
enum_values:
491504
- 'CLUSTER'
492505
- 'CLUSTER_DISABLED'
506+
- name: 'pscAttachmentDetails'
507+
type: Array
508+
description:
509+
"Configuration of a service attachment of the cluster, for creating PSC connections."
510+
output: true
511+
item_type:
512+
type: NestedObject
513+
properties:
514+
- name: 'serviceAttachment'
515+
type: String
516+
description:
517+
"Service attachment URI which your self-created PscConnection should use as target."
518+
output: true
519+
- name: 'connectionType'
520+
type: String
521+
description:
522+
"Service attachment URI which your self-created PscConnection should use as target."
523+
output: true
493524
- name: 'pscAutoConnections'
494525
type: Array
495526
description:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
---
15+
name: 'InstanceDesiredUserCreatedEndpoints'
16+
api_resource_type_kind: Instance
17+
description: |
18+
Manages user created connections for Memorystore instance
19+
docs:
20+
note: |
21+
Please ensure your connections meet the requirements outlined at
22+
https://cloud.devsite.corp.google.com/memorystore/docs/valkey/about-multiple-vpc-networking#application_connection_requirements.
23+
If you remove a connections item from the resource, the corresponding forwarding rule will no longer be functioning.
24+
If the corresponding forwarding rule is represented in your terraform configuration it is recommended to delete that
25+
`google_compute_forwarding_rule` resource at the same time.
26+
references:
27+
guides:
28+
api: 'https://cloud.google.com/memorystore/docs/valkey/reference/rest/v1/projects.locations.instances'
29+
id_format: 'projects/{{project}}/locations/{{region}}/instances/{{name}}'
30+
base_url: 'projects/{{project}}/locations/{{region}}/instances'
31+
self_link: 'projects/{{project}}/locations/{{region}}/instances/{{name}}'
32+
create_url: 'projects/{{project}}/locations/{{region}}/instances/{{name}}?updateMask=endpoints'
33+
create_verb: PATCH
34+
update_verb: 'PATCH'
35+
update_url: 'projects/{{project}}/locations/{{region}}/instances/{{name}}?updateMask=endpoints'
36+
update_mask: true
37+
custom_code:
38+
custom_delete: 'templates/terraform/custom_delete/memorystore_instance_desired_user_created_endpoints.go.tmpl'
39+
timeouts:
40+
insert_minutes: 60
41+
update_minutes: 120
42+
delete_minutes: 30
43+
autogen_async: true
44+
async:
45+
actions: ['create', 'delete', 'update']
46+
type: 'OpAsync'
47+
operation:
48+
base_url: '{{op_id}}'
49+
result:
50+
resource_inside_response: false
51+
examples:
52+
- name: 'memorystore_instance_desired_user_created_endpoints'
53+
primary_resource_id: 'instance-user-conn'
54+
vars:
55+
instance_name: 'instance-user-conn'
56+
network1_name: 'net1'
57+
subnet_network1_name: 'subnet-net1'
58+
ip1_network1_name: 'ip1-net1'
59+
ip2_network1_name: 'ip2-net1'
60+
forwarding_rule1_network1_name: 'fwd1-net1'
61+
forwarding_rule2_network1_name: 'fwd2-net1'
62+
network2_name: 'network2'
63+
subnet_network2_name: 'subnet-net2'
64+
ip1_network2_name: 'ip1-net2'
65+
ip2_network2_name: 'ip2-net2'
66+
forwarding_rule1_network2_name: 'fwd1-net2'
67+
forwarding_rule2_network2_name: 'fwd2-net2'
68+
- name: 'memorystore_instance_desired_user_and_auto_created_endpoints'
69+
primary_resource_id: 'instance-user-auto-conn'
70+
vars:
71+
instance_name: 'instance-user-auto-conn'
72+
network1_name: 'net1'
73+
subnet_network1_name: 'subnet-net1'
74+
policy_name: 'scpolicy'
75+
network2_name: 'network2'
76+
subnet_network2_name: 'subnet-net2'
77+
ip1_network2_name: 'ip1-net2'
78+
ip2_network2_name: 'ip2-net2'
79+
forwarding_rule1_network2_name: 'fwd1-net2'
80+
forwarding_rule2_network2_name: 'fwd2-net2'
81+
parameters:
82+
- name: 'name'
83+
type: String
84+
description: |
85+
The name of the Memorystore instance these endpoints should be added to.
86+
required: true
87+
url_param_only: true
88+
- name: 'region'
89+
type: String
90+
description: |
91+
The name of the region of the Memorystore instance these endpoints should be added to.
92+
url_param_only: true
93+
required: true
94+
properties:
95+
- name: 'desiredUserCreatedEndpoints'
96+
api_name: 'endpoints'
97+
type: Array
98+
description: "A list of desired user endpoints"
99+
custom_flatten: 'templates/terraform/custom_flatten/memorystore_instance_desired_user_created_connections_desired_endpoints.go.tmpl'
100+
item_type:
101+
type: NestedObject
102+
description: |
103+
Instance Endpoint consists of PSC connections that are created
104+
as a group in each VPC network for accessing the Instance. In each group,
105+
there shall be one connection for each service attachment in the Instance.
106+
properties:
107+
- name: connections
108+
type: Array
109+
item_type:
110+
type: NestedObject
111+
name: 'connections'
112+
properties:
113+
- name: 'pscConnection'
114+
type: NestedObject
115+
description: |
116+
Detailed information of a PSC connection that is created by the customer
117+
who owns the cluster.
118+
properties:
119+
- name: 'pscConnectionId'
120+
type: String
121+
description:
122+
"The PSC connection id of the forwarding rule connected
123+
to the\nservice attachment."
124+
required: true
125+
- name: 'ipAddress'
126+
type: String
127+
description:
128+
"The IP allocated on the consumer network for the
129+
PSC forwarding rule. "
130+
required: true
131+
- name: 'forwardingRule'
132+
type: String
133+
description: "The URI of the consumer side forwarding rule.\nFormat:\nprojects/{project}/regions/{region}/forwardingRules/{forwarding_rule} "
134+
required: true
135+
- name: 'projectId'
136+
type: String
137+
description:
138+
"The consumer project_id where the forwarding rule is
139+
created from. "
140+
default_from_api: true
141+
- name: 'network'
142+
type: String
143+
description:
144+
"The consumer network where the IP address resides, in
145+
the form of\nprojects/{project_id}/global/networks/{network_id}. "
146+
required: true
147+
- name: 'serviceAttachment'
148+
type: String
149+
description:
150+
"The service attachment which is the target of the PSC connection, in the form of
151+
projects/{project-id}/regions/{region}/serviceAttachments/{service-attachment-id}."
152+
required: true
153+
- name: 'pscConnectionStatus'
154+
type: Enum
155+
description:
156+
"Output Only. The status of the PSC connection: whether a connection exists and ACTIVE or it no longer exists.
157+
\n Possible values:\n ACTIVE \n NOT_FOUND"
158+
output: true
159+
- name: 'connectionType'
160+
type: Enum
161+
description:
162+
"Output Only. Type of a PSC Connection.
163+
\n Possible values:\n CONNECTION_TYPE_DISCOVERY \n CONNECTION_TYPE_PRIMARY \n CONNECTION_TYPE_READER"
164+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
billingProject := ""
2+
3+
project, err := tpgresource.GetProject(d, config)
4+
if err != nil {
5+
return fmt.Errorf("Error fetching project for InstanceDesiredUserCreatedConnections: %s", err)
6+
}
7+
billingProject = project
8+
9+
obj := make(map[string]interface{})
10+
// not setting desiredUserCreatedEndpoints in obj
11+
12+
13+
url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}MemorystoreBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/locations/{{"{{"}}region{{"}}"}}/instances/{{"{{"}}name{{"}}"}}")
14+
if err != nil {
15+
return err
16+
}
17+
18+
log.Printf("[DEBUG] Updating InstanceDesiredUserCreatedConnections %q: %#v", d.Id(), obj)
19+
headers := make(http.Header)
20+
21+
updateMask := []string{}
22+
updateMask = append(updateMask, "endpoints")
23+
// endpoints maps to desiredUserCreatedEndpoints on the resource
24+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
25+
// won't set it
26+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
27+
if err != nil {
28+
return err
29+
}
30+
31+
// err == nil indicates that the billing_project value was found
32+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
33+
billingProject = bp
34+
}
35+
36+
obj["async_instance_endpoints_deletion_enabled"] = true
37+
38+
// if updateMask is empty we are not updating anything so skip the post
39+
if len(updateMask) > 0 {
40+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
41+
Config: config,
42+
Method: "PATCH",
43+
Project: billingProject,
44+
RawURL: url,
45+
UserAgent: userAgent,
46+
Body: obj,
47+
Timeout: d.Timeout(schema.TimeoutUpdate),
48+
Headers: headers,
49+
})
50+
51+
if err != nil {
52+
return fmt.Errorf("Error updating InstanceDesiredUserCreatedConnections %q: %s", d.Id(), err)
53+
} else {
54+
log.Printf("[DEBUG] Finished updating InstanceDesiredUserCreatedConnections %q: %#v", d.Id(), res)
55+
}
56+
57+
err = MemorystoreOperationWaitTime(
58+
config, res, project, "Updating InstanceDesiredUserCreatedConnections", userAgent,
59+
d.Timeout(schema.TimeoutUpdate))
60+
61+
if err != nil {
62+
return err
63+
}
64+
}
65+
return resourceMemorystoreInstanceDesiredUserCreatedEndpointsRead(d, meta)

0 commit comments

Comments
 (0)