Skip to content

Commit 003d947

Browse files
matheusaleixo-citSirGitsalotmaxi-cit
authored
Added new resource "WasmPlugin" (#12275)
Co-authored-by: Chris Hawk <[email protected]> Co-authored-by: Max W. Portocarrero <[email protected]>
1 parent 6f6457d commit 003d947

File tree

11 files changed

+1663
-2
lines changed

11 files changed

+1663
-2
lines changed

mmv1/products/networkservices/LbRouteExtension.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ properties:
153153
- name: 'service'
154154
type: String
155155
description: |
156-
The reference to the service that runs the extension. Must be a reference to a backend service
156+
The reference to the service that runs the extension.
157+
158+
* To configure a callout extension, service must be a fully-qualified reference to a backend service.
159+
* To configure a plugin extension, service must be a reference to a WasmPlugin resource.
157160
required: true
158161
diff_suppress_func: 'tpgresource.ProjectNumberDiffSuppress'
159162
- name: 'timeout'

mmv1/products/networkservices/LbTrafficExtension.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ properties:
152152
- name: 'service'
153153
type: String
154154
description: |
155-
The reference to the service that runs the extension. Must be a reference to a backend service
155+
The reference to the service that runs the extension.
156+
157+
* To configure a callout extension, service must be a fully-qualified reference to a backend service.
158+
* To configure a plugin extension, service must be a reference to a WasmPlugin resource.
156159
required: true
157160
diff_suppress_func: 'tpgresource.ProjectNumberDiffSuppress'
158161
- name: 'timeout'
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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: 'WasmPlugin'
16+
description: |
17+
WasmPlugin is a resource representing a service executing a customer-provided Wasm module.
18+
references:
19+
guides:
20+
'Configure a route extension': 'https://cloud.google.com/service-extensions/docs/create-plugin'
21+
api: 'https://cloud.google.com/service-extensions/docs/reference/rest/v1/projects.locations.wasmPlugins'
22+
docs:
23+
base_url: 'projects/{{project}}/locations/{{location}}/wasmPlugins'
24+
self_link: 'projects/{{project}}/locations/{{location}}/wasmPlugins/{{name}}'
25+
create_url: 'projects/{{project}}/locations/{{location}}/wasmPlugins?wasmPluginId={{name}}'
26+
create_verb: 'POST'
27+
update_verb: 'PATCH'
28+
update_mask: true
29+
read_query_params: '?view=WASM_PLUGIN_VIEW_FULL'
30+
timeouts:
31+
insert_minutes: 20
32+
update_minutes: 20
33+
delete_minutes: 20
34+
autogen_async: true
35+
async:
36+
actions: ['create', 'delete', 'update']
37+
type: 'OpAsync'
38+
operation:
39+
base_url: '{{op_id}}'
40+
result:
41+
resource_inside_response: false
42+
custom_code:
43+
examples:
44+
- name: 'wasm_plugin_basic_docker_repository'
45+
primary_resource_id: 'wasm_plugin'
46+
vars:
47+
wasm_plugin_name: 'my-wasm-plugin'
48+
plugin_package_name: 'my-wasm-plugin-data'
49+
repository_name: 'my-artifact-registry-docker-repository'
50+
skip_vcr: true
51+
- name: 'wasm_plugin_basic_generic_repository'
52+
primary_resource_id: 'wasm_plugin'
53+
vars:
54+
wasm_plugin_name: 'my-wasm-plugin'
55+
plugin_package_name: 'my-wasm-plugin-data'
56+
repository_name: 'my-artifact-registry-generic-repository'
57+
skip_vcr: true
58+
parameters:
59+
- name: 'location'
60+
type: String
61+
description: |
62+
The location of the traffic extension
63+
url_param_only: true
64+
immutable: true
65+
default_value: "global"
66+
- name: 'name'
67+
type: String
68+
description: |
69+
Identifier. Name of the WasmPlugin resource.
70+
url_param_only: true
71+
required: true
72+
immutable: true
73+
properties:
74+
- name: 'createTime'
75+
type: Time
76+
description: 'Output only. The timestamp when the resource was created.'
77+
output: true
78+
- name: 'updateTime'
79+
type: Time
80+
description: 'Output only. The timestamp when the resource was updated.'
81+
output: true
82+
- name: 'description'
83+
type: String
84+
description: |
85+
Optional. A human-readable description of the resource.
86+
- name: 'labels'
87+
type: KeyValueLabels
88+
description: 'Optional. Set of labels associated with the WasmPlugin resource.'
89+
- name: 'mainVersionId'
90+
type: String
91+
description: |
92+
The ID of the WasmPluginVersion resource that is the currently serving one. The version referred to must be a child of this WasmPlugin resource and should be listed in the "versions" field.
93+
required: true
94+
- name: 'logConfig'
95+
type: NestedObject
96+
description: |
97+
Optional. Specifies the logging options for the activity performed by this plugin. If logging is enabled, plugin logs are exported to Cloud Logging.
98+
Note that the settings relate to the logs generated by using logging statements in your Wasm code.
99+
properties:
100+
- name: 'enable'
101+
type: Boolean
102+
description: |
103+
Optional. Specifies whether to enable logging for activity by this plugin.
104+
- name: 'sampleRate'
105+
type: Double
106+
validation:
107+
function: 'validation.FloatBetween(0, 1)'
108+
description: |
109+
Non-empty default. Configures the sampling rate of activity logs, where 1.0 means all logged activity is reported and 0.0 means no activity is reported.
110+
A floating point value between 0.0 and 1.0 indicates that a percentage of log messages is stored.
111+
The default value when logging is enabled is 1.0. The value of the field must be between 0 and 1 (inclusive).
112+
This field can be specified only if logging is enabled for this plugin.
113+
default_from_api: true
114+
- name: 'minLogLevel'
115+
type: Enum
116+
description: |
117+
Non-empty default. Specificies the lowest level of the plugin logs that are exported to Cloud Logging. This setting relates to the logs generated by using logging statements in your Wasm code.
118+
This field is can be set only if logging is enabled for the plugin.
119+
If the field is not provided when logging is enabled, it is set to INFO by default.
120+
default_from_api: true
121+
enum_values:
122+
- 'LOG_LEVEL_UNSPECIFIED'
123+
- 'TRACE'
124+
- 'DEBUG'
125+
- 'INFO'
126+
- 'WARN'
127+
- 'ERROR'
128+
- 'CRITICAL'
129+
- name: 'versions'
130+
type: Map
131+
description: |
132+
All versions of this WasmPlugin resource in the key-value format. The key is the resource ID, and the value is the VersionDetails object.
133+
required: true
134+
key_name: 'version_name'
135+
key_description: 'Name of the WasmPluginVersion'
136+
# custom_expand is used for both preventing empty maps being created on update and to remove output fields that are being incorrecty included in the expand when inside a map
137+
custom_expand: 'templates/terraform/custom_expand/wasm_plugin_skip_empty_versions.go.tmpl'
138+
value_type:
139+
name: value
140+
type: NestedObject
141+
properties:
142+
- name: 'createTime'
143+
type: Time
144+
description: 'Output only. The timestamp when the resource was created.'
145+
output: true
146+
- name: 'updateTime'
147+
type: Time
148+
description: 'Output only. The timestamp when the resource was updated.'
149+
output: true
150+
- name: 'description'
151+
type: String
152+
description: |
153+
Optional. A human-readable description of the resource.
154+
- name: 'labels'
155+
type: KeyValuePairs
156+
description: 'Optional. Set of labels associated with the WasmPlugin resource.'
157+
- name: 'imageUri'
158+
type: String
159+
description: |
160+
Optional. URI of the container image containing the plugin, stored in the Artifact Registry. When a new WasmPluginVersion resource is created, the digest of the container image is saved in the imageDigest field.
161+
When downloading an image, the digest value is used instead of an image tag.
162+
- name: 'imageDigest'
163+
type: String
164+
description: |
165+
Output only. The resolved digest for the image specified in the image field. The digest is resolved during the creation of WasmPluginVersion resource.
166+
This field holds the digest value, regardless of whether a tag or digest was originally specified in the image field.
167+
output: true
168+
- name: 'pluginConfigDigest'
169+
type: String
170+
description: |
171+
Output only. This field holds the digest (usually checksum) value for the plugin configuration.
172+
The value is calculated based on the contents of pluginConfigData or the container image defined by the pluginConfigUri field.
173+
output: true
174+
- name: 'pluginConfigData'
175+
type: String
176+
description: |
177+
A base64-encoded string containing the configuration for the plugin. The configuration is provided to the plugin at runtime through the ON_CONFIGURE callback.
178+
When a new WasmPluginVersion resource is created, the digest of the contents is saved in the pluginConfigDigest field.
179+
Conflics with pluginConfigUri.
180+
conflicts:
181+
- pluginConfigUri
182+
validation:
183+
function: 'verify.ValidateBase64String'
184+
- name: 'pluginConfigUri'
185+
type: String
186+
description: |
187+
URI of the plugin configuration stored in the Artifact Registry. The configuration is provided to the plugin at runtime through the ON_CONFIGURE callback.
188+
The container image must contain only a single file with the name plugin.config.
189+
When a new WasmPluginVersion resource is created, the digest of the container image is saved in the pluginConfigDigest field.
190+
Conflics with pluginConfigData.
191+
conflicts:
192+
- pluginConfigData
193+
- name: 'usedBy'
194+
type: Array
195+
description: |
196+
Output only. List of all extensions that use this WasmPlugin resource.
197+
output: true
198+
item_type:
199+
type: NestedObject
200+
properties:
201+
- name: 'name'
202+
type: string
203+
description: 'Output only. Full name of the resource'
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2+
if v == nil {
3+
return map[string]interface{}{}, nil
4+
}
5+
m := make(map[string]interface{})
6+
for _, raw := range v.(*schema.Set).List() {
7+
original := raw.(map[string]interface{})
8+
transformed := make(map[string]interface{})
9+
10+
// Ensure we don't send empty versions
11+
if tpgresource.IsEmptyValue(reflect.ValueOf(original["version_name"])) {
12+
continue
13+
}
14+
15+
transformedDescription, err := expandNetworkServicesWasmPluginVersionsFields(original["description"], d, config)
16+
if err != nil {
17+
return nil, err
18+
} else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !tpgresource.IsEmptyValue(val) {
19+
transformed["description"] = transformedDescription
20+
}
21+
22+
transformedLabels, err := expandNetworkServicesWasmPluginVersionsLabels(original["labels"], d, config)
23+
if err != nil {
24+
return nil, err
25+
} else if val := reflect.ValueOf(transformedLabels); val.IsValid() && !tpgresource.IsEmptyValue(val) {
26+
transformed["labels"] = transformedLabels
27+
}
28+
29+
transformedImageUri, err := expandNetworkServicesWasmPluginVersionsFields(original["image_uri"], d, config)
30+
if err != nil {
31+
return nil, err
32+
} else if val := reflect.ValueOf(transformedImageUri); val.IsValid() && !tpgresource.IsEmptyValue(val) {
33+
transformed["imageUri"] = transformedImageUri
34+
}
35+
36+
transformedPluginConfigData, err := expandNetworkServicesWasmPluginVersionsFields(original["plugin_config_data"], d, config)
37+
if err != nil {
38+
return nil, err
39+
} else if val := reflect.ValueOf(transformedPluginConfigData); val.IsValid() && !tpgresource.IsEmptyValue(val) {
40+
transformed["pluginConfigData"] = transformedPluginConfigData
41+
}
42+
43+
transformedPluginConfigUri, err := expandNetworkServicesWasmPluginVersionsFields(original["plugin_config_uri"], d, config)
44+
if err != nil {
45+
return nil, err
46+
} else if val := reflect.ValueOf(transformedPluginConfigUri); val.IsValid() && !tpgresource.IsEmptyValue(val) {
47+
transformed["pluginConfigUri"] = transformedPluginConfigUri
48+
}
49+
50+
transformedVersionName, err := tpgresource.ExpandString(original["version_name"], d, config)
51+
if err != nil {
52+
return nil, err
53+
}
54+
m[transformedVersionName] = transformed
55+
}
56+
return m, nil
57+
}
58+
59+
func expandNetworkServicesWasmPluginVersionsFields(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
60+
return v, nil
61+
}
62+
63+
func expandNetworkServicesWasmPluginVersionsLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
64+
if v == nil {
65+
return map[string]string{}, nil
66+
}
67+
m := make(map[string]string)
68+
for k, val := range v.(map[string]interface{}) {
69+
m[k] = val.(string)
70+
}
71+
return m, nil
72+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
data "google_project" "project" {}
2+
3+
resource "google_network_services_wasm_plugin" "{{$.PrimaryResourceId}}" {
4+
name = "{{index $.Vars "wasm_plugin_name"}}"
5+
description = "my wasm plugin from a docker repository"
6+
7+
main_version_id = "v1"
8+
9+
labels = {
10+
test_label = "test_value"
11+
}
12+
log_config {
13+
enable = true
14+
sample_rate = 1
15+
min_log_level = "WARN"
16+
}
17+
18+
versions {
19+
version_name = "v1"
20+
description = "v1 version of my wasm plugin"
21+
image_uri = "us-central1-docker.pkg.dev/${data.google_project.project.name}/{index $.Vars "repository_name"}/{index $.Vars "plugin_package_name"}:prod"
22+
23+
labels = {
24+
test_label = "test_value"
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
data "google_project" "project" {}
2+
3+
resource "google_network_services_wasm_plugin" "{{$.PrimaryResourceId}}" {
4+
name = "{{index $.Vars "wasm_plugin_name"}}"
5+
description = "my wasm plugin from a generic repository"
6+
7+
main_version_id = "v1"
8+
9+
labels = {
10+
test_label = "test_value"
11+
}
12+
log_config {
13+
enable = true
14+
sample_rate = 1
15+
min_log_level = "WARN"
16+
}
17+
18+
versions {
19+
version_name = "v1"
20+
description = "v1 version of my wasm plugin"
21+
image_uri = "projects/${data.google_project.project.name}/locations/us-central1/repositories/{index $.Vars "repository_name"}/genericArtifacts/{index $.Vars "plugin_package_name"}:v1"
22+
23+
labels = {
24+
test_label = "test_value"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)