@@ -93,15 +93,6 @@ Note that it must be at least one character and less than 63 characters
9393 ForceNew : true ,
9494 Description : `The location of the resource. This is the geographical region where the Chronicle instance resides, such as "us" or "europe-west2".` ,
9595 },
96- "watchlist_id" : {
97- Type : schema .TypeString ,
98- Required : true ,
99- ForceNew : true ,
100- Description : `Optional. The ID to use for the watchlist,
101- which will become the final component of the watchlist's resource name.
102- This value should be 4-63 characters, and valid characters
103- are /a-z-/.` ,
104- },
10596 "description" : {
10697 Type : schema .TypeString ,
10798 Optional : true ,
@@ -113,6 +104,16 @@ are /a-z-/.`,
113104 Description : `Optional. Weight applied to the risk score for entities
114105in this watchlist.
115106The default is 1.0 if it is not specified.` ,
107+ },
108+ "watchlist_id" : {
109+ Type : schema .TypeString ,
110+ Computed : true ,
111+ Optional : true ,
112+ ForceNew : true ,
113+ Description : `Optional. The ID to use for the watchlist,
114+ which will become the final component of the watchlist's resource name.
115+ This value should be 4-63 characters, and valid characters
116+ are /a-z-/.` ,
116117 },
117118 "watchlist_user_preferences" : {
118119 Type : schema .TypeList ,
@@ -215,6 +216,17 @@ func resourceChronicleWatchlistCreate(d *schema.ResourceData, meta interface{})
215216 } else if v , ok := d .GetOkExists ("watchlist_user_preferences" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (watchlistUserPreferencesProp )) && (ok || ! reflect .DeepEqual (v , watchlistUserPreferencesProp )) {
216217 obj ["watchlistUserPreferences" ] = watchlistUserPreferencesProp
217218 }
219+ watchlistIdProp , err := expandChronicleWatchlistWatchlistId (d .Get ("watchlist_id" ), d , config )
220+ if err != nil {
221+ return err
222+ } else if v , ok := d .GetOkExists ("watchlist_id" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (watchlistIdProp )) && (ok || ! reflect .DeepEqual (v , watchlistIdProp )) {
223+ obj ["watchlistId" ] = watchlistIdProp
224+ }
225+
226+ obj , err = resourceChronicleWatchlistEncoder (d , meta , obj )
227+ if err != nil {
228+ return err
229+ }
218230
219231 url , err := tpgresource .ReplaceVars (d , config , "{{ChronicleBasePath}}projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists?watchlistId={{watchlist_id}}" )
220232 if err != nil {
@@ -260,6 +272,14 @@ func resourceChronicleWatchlistCreate(d *schema.ResourceData, meta interface{})
260272 }
261273 d .SetId (id )
262274
275+ if tpgresource .IsEmptyValue (reflect .ValueOf (d .Get ("watchlist_id" ))) {
276+ // watchlist id is set by API when unset and required to GET the connection
277+ // it is set by reading the "name" field rather than a field in the response
278+ if err := d .Set ("watchlist_id" , flattenChronicleWatchlistWatchlistId ("" , d , config )); err != nil {
279+ return fmt .Errorf ("Error reading Watchlist ID: %s" , err )
280+ }
281+ }
282+
263283 log .Printf ("[DEBUG] Finished creating Watchlist %q: %#v" , d .Id (), res )
264284
265285 return resourceChronicleWatchlistRead (d , meta )
@@ -334,6 +354,9 @@ func resourceChronicleWatchlistRead(d *schema.ResourceData, meta interface{}) er
334354 if err := d .Set ("watchlist_user_preferences" , flattenChronicleWatchlistWatchlistUserPreferences (res ["watchlistUserPreferences" ], d , config )); err != nil {
335355 return fmt .Errorf ("Error reading Watchlist: %s" , err )
336356 }
357+ if err := d .Set ("watchlist_id" , flattenChronicleWatchlistWatchlistId (res ["watchlistId" ], d , config )); err != nil {
358+ return fmt .Errorf ("Error reading Watchlist: %s" , err )
359+ }
337360
338361 return nil
339362}
@@ -385,6 +408,11 @@ func resourceChronicleWatchlistUpdate(d *schema.ResourceData, meta interface{})
385408 obj ["watchlistUserPreferences" ] = watchlistUserPreferencesProp
386409 }
387410
411+ obj , err = resourceChronicleWatchlistEncoder (d , meta , obj )
412+ if err != nil {
413+ return err
414+ }
415+
388416 url , err := tpgresource .ReplaceVars (d , config , "{{ChronicleBasePath}}projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists/{{watchlist_id}}" )
389417 if err != nil {
390418 return err
@@ -628,6 +656,11 @@ func flattenChronicleWatchlistWatchlistUserPreferencesPinned(v interface{}, d *s
628656 return v
629657}
630658
659+ func flattenChronicleWatchlistWatchlistId (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
660+ parts := strings .Split (d .Get ("name" ).(string ), "/" )
661+ return parts [len (parts )- 1 ]
662+ }
663+
631664func expandChronicleWatchlistMultiplyingFactor (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
632665 return v , nil
633666}
@@ -696,3 +729,13 @@ func expandChronicleWatchlistWatchlistUserPreferences(v interface{}, d tpgresour
696729func expandChronicleWatchlistWatchlistUserPreferencesPinned (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
697730 return v , nil
698731}
732+
733+ func expandChronicleWatchlistWatchlistId (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
734+ return v , nil
735+ }
736+
737+ func resourceChronicleWatchlistEncoder (d * schema.ResourceData , meta interface {}, obj map [string ]interface {}) (map [string ]interface {}, error ) {
738+ // watchlist_id is needed to qualify the URL but cannot be sent in the body
739+ delete (obj , "watchlistId" )
740+ return obj , nil
741+ }
0 commit comments