@@ -95,6 +95,30 @@ func ResourceApigeeInstance() *schema.Resource {
9595 Description : `The Apigee Organization associated with the Apigee instance,
9696in the format 'organizations/{{org_name}}'.` ,
9797 },
98+ "access_logging_config" : {
99+ Type : schema .TypeList ,
100+ Optional : true ,
101+ Description : `Access logging configuration enables the access logging feature at the instance.
102+ Apigee customers can enable access logging to ship the access logs to their own project's cloud logging.` ,
103+ MaxItems : 1 ,
104+ Elem : & schema.Resource {
105+ Schema : map [string ]* schema.Schema {
106+ "enabled" : {
107+ Type : schema .TypeBool ,
108+ Required : true ,
109+ Description : `Boolean flag that specifies whether the customer access log feature is enabled.` ,
110+ },
111+ "filter" : {
112+ Type : schema .TypeString ,
113+ Optional : true ,
114+ Description : `Ship the access log entries that match the statusCode defined in the filter.
115+ The statusCode is the only expected/supported filter field. (Ex: statusCode)
116+ The filter will parse it to the Common Expression Language semantics for expression
117+ evaluation to build the filter condition. (Ex: "filter": statusCode >= 200 && statusCode < 300 )` ,
118+ },
119+ },
120+ },
121+ },
98122 "consumer_accept_list" : {
99123 Type : schema .TypeList ,
100124 Computed : true ,
@@ -225,6 +249,12 @@ func resourceApigeeInstanceCreate(d *schema.ResourceData, meta interface{}) erro
225249 } else if v , ok := d .GetOkExists ("consumer_accept_list" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (consumerAcceptListProp )) && (ok || ! reflect .DeepEqual (v , consumerAcceptListProp )) {
226250 obj ["consumerAcceptList" ] = consumerAcceptListProp
227251 }
252+ accessLoggingConfigProp , err := expandApigeeInstanceAccessLoggingConfig (d .Get ("access_logging_config" ), d , config )
253+ if err != nil {
254+ return err
255+ } else if v , ok := d .GetOkExists ("access_logging_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (accessLoggingConfigProp )) && (ok || ! reflect .DeepEqual (v , accessLoggingConfigProp )) {
256+ obj ["accessLoggingConfig" ] = accessLoggingConfigProp
257+ }
228258
229259 lockName , err := tpgresource .ReplaceVars (d , config , "{{org_id}}/apigeeInstances" )
230260 if err != nil {
@@ -347,6 +377,9 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error
347377 if err := d .Set ("service_attachment" , flattenApigeeInstanceServiceAttachment (res ["serviceAttachment" ], d , config )); err != nil {
348378 return fmt .Errorf ("Error reading Instance: %s" , err )
349379 }
380+ if err := d .Set ("access_logging_config" , flattenApigeeInstanceAccessLoggingConfig (res ["accessLoggingConfig" ], d , config )); err != nil {
381+ return fmt .Errorf ("Error reading Instance: %s" , err )
382+ }
350383
351384 return nil
352385}
@@ -367,6 +400,12 @@ func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
367400 } else if v , ok := d .GetOkExists ("consumer_accept_list" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , consumerAcceptListProp )) {
368401 obj ["consumerAcceptList" ] = consumerAcceptListProp
369402 }
403+ accessLoggingConfigProp , err := expandApigeeInstanceAccessLoggingConfig (d .Get ("access_logging_config" ), d , config )
404+ if err != nil {
405+ return err
406+ } else if v , ok := d .GetOkExists ("access_logging_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , accessLoggingConfigProp )) {
407+ obj ["accessLoggingConfig" ] = accessLoggingConfigProp
408+ }
370409
371410 lockName , err := tpgresource .ReplaceVars (d , config , "{{org_id}}/apigeeInstances" )
372411 if err != nil {
@@ -387,6 +426,10 @@ func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
387426 if d .HasChange ("consumer_accept_list" ) {
388427 updateMask = append (updateMask , "consumerAcceptList" )
389428 }
429+
430+ if d .HasChange ("access_logging_config" ) {
431+ updateMask = append (updateMask , "accessLoggingConfig" )
432+ }
390433 // updateMask is a URL parameter but not present in the schema, so ReplaceVars
391434 // won't set it
392435 url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
@@ -574,6 +617,29 @@ func flattenApigeeInstanceServiceAttachment(v interface{}, d *schema.ResourceDat
574617 return v
575618}
576619
620+ func flattenApigeeInstanceAccessLoggingConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
621+ if v == nil {
622+ return nil
623+ }
624+ original := v .(map [string ]interface {})
625+ if len (original ) == 0 {
626+ return nil
627+ }
628+ transformed := make (map [string ]interface {})
629+ transformed ["enabled" ] =
630+ flattenApigeeInstanceAccessLoggingConfigEnabled (original ["enabled" ], d , config )
631+ transformed ["filter" ] =
632+ flattenApigeeInstanceAccessLoggingConfigFilter (original ["filter" ], d , config )
633+ return []interface {}{transformed }
634+ }
635+ func flattenApigeeInstanceAccessLoggingConfigEnabled (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
636+ return v
637+ }
638+
639+ func flattenApigeeInstanceAccessLoggingConfigFilter (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
640+ return v
641+ }
642+
577643func expandApigeeInstanceName (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
578644 return v , nil
579645}
@@ -605,3 +671,37 @@ func expandApigeeInstanceDiskEncryptionKeyName(v interface{}, d tpgresource.Terr
605671func expandApigeeInstanceConsumerAcceptList (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
606672 return v , nil
607673}
674+
675+ func expandApigeeInstanceAccessLoggingConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
676+ l := v .([]interface {})
677+ if len (l ) == 0 || l [0 ] == nil {
678+ return nil , nil
679+ }
680+ raw := l [0 ]
681+ original := raw .(map [string ]interface {})
682+ transformed := make (map [string ]interface {})
683+
684+ transformedEnabled , err := expandApigeeInstanceAccessLoggingConfigEnabled (original ["enabled" ], d , config )
685+ if err != nil {
686+ return nil , err
687+ } else if val := reflect .ValueOf (transformedEnabled ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
688+ transformed ["enabled" ] = transformedEnabled
689+ }
690+
691+ transformedFilter , err := expandApigeeInstanceAccessLoggingConfigFilter (original ["filter" ], d , config )
692+ if err != nil {
693+ return nil , err
694+ } else if val := reflect .ValueOf (transformedFilter ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
695+ transformed ["filter" ] = transformedFilter
696+ }
697+
698+ return transformed , nil
699+ }
700+
701+ func expandApigeeInstanceAccessLoggingConfigEnabled (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
702+ return v , nil
703+ }
704+
705+ func expandApigeeInstanceAccessLoggingConfigFilter (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
706+ return v , nil
707+ }
0 commit comments