@@ -82,11 +82,13 @@ func sendSecondaryIpRangeIfEmptyDiff(_ context.Context, diff *schema.ResourceDif
82
82
return nil
83
83
}
84
84
85
- // DiffSuppressFunc for fields inside `log_config`.
85
+ // DiffSuppressFunc for `log_config`.
86
86
func subnetworkLogConfigDiffSuppress (k , old , new string , d * schema.ResourceData ) bool {
87
- // If the enable_flow_logs is not enabled, we don't need to check for differences.
88
- if enable_flow_logs := d .Get ("enable_flow_logs" ); ! enable_flow_logs .(bool ) {
89
- return true
87
+ // If enable_flow_logs is enabled and log_config is not set, ignore the diff
88
+ if enable_flow_logs := d .Get ("enable_flow_logs" ); enable_flow_logs .(bool ) {
89
+ logConfig := d .GetRawConfig ().GetAttr ("log_config" )
90
+ logConfigIsEmpty := logConfig .IsNull () || logConfig .LengthInt () == 0
91
+ return logConfigIsEmpty
90
92
}
91
93
92
94
return false
@@ -229,7 +231,7 @@ func GetComputeSubnetworkApiObject(d tpgresource.TerraformResourceData, config *
229
231
enableFlowLogsProp , err := expandComputeSubnetworkEnableFlowLogs (d .Get ("enable_flow_logs" ), d , config )
230
232
if err != nil {
231
233
return nil , err
232
- } else if v , ok := d .GetOkExists ("enable_flow_logs" ); ok || ! reflect .DeepEqual (v , enableFlowLogsProp ) {
234
+ } else if v , ok := d .GetOkExists ("enable_flow_logs" ); ! tpgresource . IsEmptyValue ( reflect . ValueOf ( enableFlowLogsProp )) && ( ok || ! reflect .DeepEqual (v , enableFlowLogsProp ) ) {
233
235
obj ["enableFlowLogs" ] = enableFlowLogsProp
234
236
}
235
237
@@ -343,9 +345,8 @@ func expandComputeSubnetworkLogConfig(v interface{}, d tpgresource.TerraformReso
343
345
return nil , nil
344
346
}
345
347
346
- // set enable field basing on the enable_flow_logs field. It's needed for case when enable_flow_logs
347
- // is set to true to avoid conflict with the API. In that case API will return default values for log_config
348
- transformed ["enable" ] = d .Get ("enable_flow_logs" )
348
+ // send enable = false to ensure logging is disabled if there is no config
349
+ transformed ["enable" ] = false
349
350
return transformed , nil
350
351
}
351
352
0 commit comments