Skip to content

Commit

Permalink
Adding support for optional watchlist_id in google_chronicle_watchlis…
Browse files Browse the repository at this point in the history
…t resource (#12673)
  • Loading branch information
ankitgoyal0301 authored Jan 3, 2025
1 parent 843d813 commit 8dbff06
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
21 changes: 18 additions & 3 deletions mmv1/products/chronicle/Watchlist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,30 @@ import_format:
- projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists/{{watchlist_id}}
update_verb: PATCH
update_mask: true

custom_code:
encoder: 'templates/terraform/encoders/chronicle_watchlist.go.tmpl'
post_create: 'templates/terraform/post_create/chronicle_watchlist_id.go.tmpl'
examples:
- name: 'chronicle_watchlist_basic'
primary_resource_id: 'example'
min_version: 'beta'
vars:
name: watchlist_name
watchlist_id: watchlist-id
description: watchlist-description
test_env_vars:
chronicle_id: 'CHRONICLE_ID'
- name: 'chronicle_watchlist_without_id'
primary_resource_id: 'example'
min_version: 'beta'
vars:
name: watchlist-name
description: watchlist-description
test_env_vars:
chronicle_id: 'CHRONICLE_ID'
# The watchlist_id is an optional field. If watchlist_id is not provided, the system will generate one.
# See AIP-133 for details: https://google.aip.dev/133#user-specified-ids
exclude_import_test: true

parameters:
- name: location
Expand All @@ -58,9 +72,10 @@ parameters:
which will become the final component of the watchlist's resource name.
This value should be 4-63 characters, and valid characters
are /a-z-/.
required: false
immutable: true
url_param_only: true
required: true
default_from_api: true
custom_flatten: 'templates/terraform/custom_flatten/id_from_name.tmpl'
properties:
- name: name
type: String
Expand Down
3 changes: 3 additions & 0 deletions mmv1/templates/terraform/encoders/chronicle_watchlist.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// watchlist_id is needed to qualify the URL but cannot be sent in the body
delete(obj, "watchlistId")
return obj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "google_chronicle_watchlist" "{{$.PrimaryResourceId}}" {
provider = "google-beta"
location = "us"
instance = "{{index $.TestEnvVars "chronicle_id"}}"
watchlist_id = "{{index $.Vars "name"}}"
watchlist_id = "{{index $.Vars "watchlist_id"}}"
description = "{{index $.Vars "description"}}"
display_name = "{{index $.Vars "name"}}"
multiplying_factor = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "google_chronicle_watchlist" "{{$.PrimaryResourceId}}" {
provider = "google-beta"
location = "us"
instance = "{{index $.TestEnvVars "chronicle_id"}}"
description = "{{index $.Vars "description"}}"
display_name = "{{index $.Vars "name"}}"
multiplying_factor = 1
entity_population_mechanism {
manual {

}
}
watchlist_user_preferences {
pinned = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if tpgresource.IsEmptyValue(reflect.ValueOf(d.Get("watchlist_id"))) {
// watchlist id is set by API when unset and required to GET the connection
// it is set by reading the "name" field rather than a field in the response
if err := d.Set("watchlist_id", flattenChronicleWatchlistWatchlistId("", d, config)); err != nil {
return fmt.Errorf("Error reading Watchlist ID: %s", err)
}
}

0 comments on commit 8dbff06

Please sign in to comment.