You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/develop/add-fields.md
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -167,6 +167,12 @@ Replace `String` in the field type with one of the following options:
167
167
key_name: 'KEY_NAME'
168
168
key_description: |
169
169
MULTILINE_KEY_FIELD_DESCRIPTION
170
+
# Map of primitive values
171
+
value_type:
172
+
name: mapIntegerName
173
+
type: Integer
174
+
175
+
# Map of complex values
170
176
value_type:
171
177
name: mapObjectName
172
178
type: NestedObject
@@ -177,7 +183,7 @@ Replace `String` in the field type with one of the following options:
177
183
MULTI_LINE_FIELD_DESCRIPTION
178
184
```
179
185
180
-
This type is only used for string -> complex type mappings, use "KeyValuePairs" for simple mappings. Complex maps can't be represented natively in Terraform, and this type is transformed into an associative array (TypeSet) with the key merged into the object alongside other top-level fields.
186
+
This type is used for general-case string -> non-string type mappings, use "KeyValuePairs" for string -> string mappings. Complex maps can't be represented natively in Terraform, and this type is transformed into an associative array (TypeSet) with the key merged into the object alongside other top-level fields.
181
187
182
188
For `key_name` and `key_description`, provide a domain-appropriate name and description. For example, a map that references a specific type of resource would generally use the singular resource kind as the key name (such as "topic" for PubSub Topic) and a descriptor of the expected format depending on the context (such as resourceId vs full resource name).
Copy file name to clipboardExpand all lines: docs/content/reference/resource.md
+134Lines changed: 134 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -325,6 +325,140 @@ Example:
325
325
mutex: 'alloydb/instance/{{name}}'
326
326
```
327
327
328
+
## Sweeper
329
+
330
+
Sweepers are a testing infrastructure mechanism that automatically clean up resources created during tests. They run before tests start and can be run manually to clean up dangling resources. Sweepers help prevent test failures due to resource quota limits and reduce cloud infrastructure costs by removing test resources that were not properly cleaned up.
331
+
332
+
Sweeper generation is enabled by default, except in the following conditions which require customization here:
333
+
334
+
- Resources with custom deletion code
335
+
- Resources with parent-child relationships (unless the parent relationship is configured)
336
+
- Resources with complex URL parameters that aren't simple region/project parameters
337
+
338
+
Define the sweeper block in a resource to override these exclusions and enable sweeper generation for that resource.
339
+
340
+
### `exclude_sweeper`
341
+
342
+
If set to `true`, no sweeper will be generated for this resource. This is useful for resources that cannot or should not be automatically cleaned up.
343
+
344
+
Default: `false`
345
+
346
+
Example:
347
+
348
+
```yaml
349
+
exclude_sweeper: true
350
+
```
351
+
352
+
### `sweeper`
353
+
354
+
Configures how test resources are swept (cleaned up) after tests. The sweeper system helps ensure resources created during tests are properly removed, even when tests fail unexpectedly. All fields within the `sweeper` block are optional, with reasonable defaults provided when not specified. See [sweeper.go ↗](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/api/resource/sweeper.go) for the implementation.
355
+
356
+
- `identifier_field`: Specifies which field in the API resource object should be used to identify resources for deletion. If not specified, defaults to "name" if present in the resource, otherwise falls back to "id".
357
+
358
+
- `prefixes`: Specifies name prefixes that identify resources eligible for sweeping. Resources whose names start with any of these prefixes will be deleted. By default, resources with the `tf-test-` prefix are automatically eligible for sweeping even if no prefixes are specified.
359
+
360
+
- `url_substitutions`: Allows customizing URL parameters when listing resources. Each map entry represents a set of key-value pairs to substitute in the URL template. This is commonly used to specify regions to sweep in. If not specified, the sweeper will only run in the default region (us-central1) and zone (us-central1-a).
361
+
362
+
- `dependencies`: Lists other resource types that must be swept before this one. This ensures proper cleanup order for resources with dependencies. If not specified, no dependencies are assumed.
363
+
364
+
- `parent`: Configures sweeping for resources that depend on parent resources (like a nodepool that belongs to a cluster).
365
+
366
+
Required fields:
367
+
- `resource_type`: The type of the parent resource (for example, "google_container_cluster")
368
+
- `child_field`: The field in your resource that references the parent (for example, "cluster")
369
+
- At least one of `parent_field` or `template` is required
370
+
371
+
Options for getting parent reference:
372
+
- `parent_field`: The field from parent to use (typically "name" or "id")
373
+
- `template`: A template string like "projects/{{project}}/locations/{{location}}/clusters/{{value}}"
374
+
375
+
Options for processing the parent field value:
376
+
- `parent_field_extract_name`: When set to true, extracts just the resource name from a self_link URL by taking the portion after the last slash. This is useful when the parent field contains a fully-qualified resource URL (like "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/my-network" or "projects/my-project/zones/us-central1-a/instances/my-instance") but you only need the final resource name component ("my-network" or "my-instance").
377
+
378
+
- `parent_field_regex`: A regex pattern with a capture group to extract a specific portion of the parent field value. This is useful when you need more control over extracting parts of complex resource identifiers. The pattern must contain at least one capture group (in parentheses), and the first capture group's match will be used as the extracted value.
379
+
380
+
- `query_string`: Allows appending additional query parameters to the resource's delete URL when performing delete operations. Format should include the starting character, for example, "?force=true" or "&verbose=true". If not specified, no additional query parameters are added.
381
+
382
+
- `ensure_value`: Specifies a field that must be set to a specific value before deletion. Used for resources that have fields like 'deletionProtectionEnabled' that must be explicitly disabled before the resource can be deleted. All fields within the `ensure_value` block are required except `include_full_resource`:
383
+
384
+
- `field`: The API field name that needs to be updated before deletion. Can include dot notation for nested fields (for example, "settings.deletionProtectionEnabled").
385
+
386
+
- `value`: The required value that `field` must be set to before deletion. For boolean fields use "true" or "false", for integers use string representation, for string fields use the exact string value required.
387
+
388
+
- `include_full_resource`: Determines whether to send the entire resource object with the updated field (true) or to send just the field that needs updating (false). Some APIs require the full resource to be sent in update operations. Default: `false`.
389
+
390
+
Examples:
391
+
392
+
Basic sweeper configuration:
393
+
394
+
```yaml
395
+
sweeper:
396
+
prefixes:
397
+
- "tf-test-"
398
+
- "tmp-"
399
+
```
400
+
401
+
Sweeper with parent-child relationship (basic):
402
+
403
+
```yaml
404
+
sweeper:
405
+
dependencies: # sweep google_compute_instance before attempting to sweep this resource
0 commit comments