@@ -24,6 +24,7 @@ import (
2424 "log"
2525 "net/http"
2626 "reflect"
27+ "strings"
2728 "time"
2829
2930 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -37,6 +38,7 @@ func ResourceSecureSourceManagerRepository() *schema.Resource {
3738 return & schema.Resource {
3839 Create : resourceSecureSourceManagerRepositoryCreate ,
3940 Read : resourceSecureSourceManagerRepositoryRead ,
41+ Update : resourceSecureSourceManagerRepositoryUpdate ,
4042 Delete : resourceSecureSourceManagerRepositoryDelete ,
4143
4244 Importer : & schema.ResourceImporter {
@@ -45,6 +47,7 @@ func ResourceSecureSourceManagerRepository() *schema.Resource {
4547
4648 Timeouts : & schema.ResourceTimeout {
4749 Create : schema .DefaultTimeout (20 * time .Minute ),
50+ Update : schema .DefaultTimeout (20 * time .Minute ),
4851 Delete : schema .DefaultTimeout (20 * time .Minute ),
4952 },
5053
@@ -75,7 +78,6 @@ func ResourceSecureSourceManagerRepository() *schema.Resource {
7578 "description" : {
7679 Type : schema .TypeString ,
7780 Optional : true ,
78- ForceNew : true ,
7981 Description : `Description of the repository, which cannot exceed 500 characters.` ,
8082 },
8183 "initial_config" : {
@@ -324,6 +326,84 @@ func resourceSecureSourceManagerRepositoryRead(d *schema.ResourceData, meta inte
324326 return nil
325327}
326328
329+ func resourceSecureSourceManagerRepositoryUpdate (d * schema.ResourceData , meta interface {}) error {
330+ config := meta .(* transport_tpg.Config )
331+ userAgent , err := tpgresource .GenerateUserAgentString (d , config .UserAgent )
332+ if err != nil {
333+ return err
334+ }
335+
336+ billingProject := ""
337+
338+ project , err := tpgresource .GetProject (d , config )
339+ if err != nil {
340+ return fmt .Errorf ("Error fetching project for Repository: %s" , err )
341+ }
342+ billingProject = project
343+
344+ obj := make (map [string ]interface {})
345+ descriptionProp , err := expandSecureSourceManagerRepositoryDescription (d .Get ("description" ), d , config )
346+ if err != nil {
347+ return err
348+ } else if v , ok := d .GetOkExists ("description" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , descriptionProp )) {
349+ obj ["description" ] = descriptionProp
350+ }
351+
352+ url , err := tpgresource .ReplaceVars (d , config , "{{SecureSourceManagerBasePath}}projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}" )
353+ if err != nil {
354+ return err
355+ }
356+
357+ log .Printf ("[DEBUG] Updating Repository %q: %#v" , d .Id (), obj )
358+ headers := make (http.Header )
359+ updateMask := []string {}
360+
361+ if d .HasChange ("description" ) {
362+ updateMask = append (updateMask , "description" )
363+ }
364+ // updateMask is a URL parameter but not present in the schema, so ReplaceVars
365+ // won't set it
366+ url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
367+ if err != nil {
368+ return err
369+ }
370+
371+ // err == nil indicates that the billing_project value was found
372+ if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
373+ billingProject = bp
374+ }
375+
376+ // if updateMask is empty we are not updating anything so skip the post
377+ if len (updateMask ) > 0 {
378+ res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
379+ Config : config ,
380+ Method : "PATCH" ,
381+ Project : billingProject ,
382+ RawURL : url ,
383+ UserAgent : userAgent ,
384+ Body : obj ,
385+ Timeout : d .Timeout (schema .TimeoutUpdate ),
386+ Headers : headers ,
387+ })
388+
389+ if err != nil {
390+ return fmt .Errorf ("Error updating Repository %q: %s" , d .Id (), err )
391+ } else {
392+ log .Printf ("[DEBUG] Finished updating Repository %q: %#v" , d .Id (), res )
393+ }
394+
395+ err = SecureSourceManagerOperationWaitTime (
396+ config , res , project , "Updating Repository" , userAgent ,
397+ d .Timeout (schema .TimeoutUpdate ))
398+
399+ if err != nil {
400+ return err
401+ }
402+ }
403+
404+ return resourceSecureSourceManagerRepositoryRead (d , meta )
405+ }
406+
327407func resourceSecureSourceManagerRepositoryDelete (d * schema.ResourceData , meta interface {}) error {
328408 config := meta .(* transport_tpg.Config )
329409 userAgent , err := tpgresource .GenerateUserAgentString (d , config .UserAgent )
0 commit comments