6
6
"context"
7
7
"fmt"
8
8
"log"
9
+ "strings"
9
10
10
11
"time"
11
12
@@ -387,6 +388,12 @@ func ResourceComputeSecurityPolicy() *schema.Resource {
387
388
ValidateFunc : validation .StringInSlice ([]string {"NORMAL" , "VERBOSE" }, false ),
388
389
Description : `Logging level. Supported values include: "NORMAL", "VERBOSE".` ,
389
390
},
391
+ "user_ip_request_headers" : {
392
+ Type : schema .TypeSet ,
393
+ Optional : true ,
394
+ Description : `An optional list of case-insensitive request header names to use for resolving the callers client IP address.` ,
395
+ Elem : & schema.Schema {Type : schema .TypeString },
396
+ },
390
397
},
391
398
},
392
399
},
@@ -597,6 +604,8 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
597
604
Fingerprint : d .Get ("fingerprint" ).(string ),
598
605
}
599
606
607
+ updateMask := []string {}
608
+
600
609
if d .HasChange ("type" ) {
601
610
securityPolicy .Type = d .Get ("type" ).(string )
602
611
securityPolicy .ForceSendFields = append (securityPolicy .ForceSendFields , "Type" )
@@ -610,6 +619,11 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
610
619
if d .HasChange ("advanced_options_config" ) {
611
620
securityPolicy .AdvancedOptionsConfig = expandSecurityPolicyAdvancedOptionsConfig (d .Get ("advanced_options_config" ).([]interface {}))
612
621
securityPolicy .ForceSendFields = append (securityPolicy .ForceSendFields , "AdvancedOptionsConfig" , "advancedOptionsConfig.jsonParsing" , "advancedOptionsConfig.jsonCustomConfig" , "advancedOptionsConfig.logLevel" )
622
+ securityPolicy .ForceSendFields = append (securityPolicy .ForceSendFields , "advanceOptionConfig.userIpRequestHeaders" )
623
+ if len (securityPolicy .AdvancedOptionsConfig .UserIpRequestHeaders ) == 0 {
624
+ // to clean this list we must send the updateMask of this field on the request.
625
+ updateMask = append (updateMask , "advanced_options_config.user_ip_request_headers" )
626
+ }
613
627
}
614
628
615
629
if d .HasChange ("adaptive_protection_config" ) {
@@ -625,7 +639,7 @@ func resourceComputeSecurityPolicyUpdate(d *schema.ResourceData, meta interface{
625
639
if len (securityPolicy .ForceSendFields ) > 0 {
626
640
client := config .NewComputeClient (userAgent )
627
641
628
- op , err := client .SecurityPolicies .Patch (project , sp , securityPolicy ).Do ()
642
+ op , err := client .SecurityPolicies .Patch (project , sp , securityPolicy ).UpdateMask ( strings . Join ( updateMask , "," )). Do ()
629
643
630
644
if err != nil {
631
645
return errwrap .Wrapf (fmt .Sprintf ("Error updating SecurityPolicy %q: {{err}}" , sp ), err )
@@ -862,9 +876,10 @@ func expandSecurityPolicyAdvancedOptionsConfig(configured []interface{}) *comput
862
876
863
877
data := configured [0 ].(map [string ]interface {})
864
878
return & compute.SecurityPolicyAdvancedOptionsConfig {
865
- JsonParsing : data ["json_parsing" ].(string ),
866
- JsonCustomConfig : expandSecurityPolicyAdvancedOptionsConfigJsonCustomConfig (data ["json_custom_config" ].([]interface {})),
867
- LogLevel : data ["log_level" ].(string ),
879
+ JsonParsing : data ["json_parsing" ].(string ),
880
+ JsonCustomConfig : expandSecurityPolicyAdvancedOptionsConfigJsonCustomConfig (data ["json_custom_config" ].([]interface {})),
881
+ LogLevel : data ["log_level" ].(string ),
882
+ UserIpRequestHeaders : tpgresource .ConvertStringArr (data ["user_ip_request_headers" ].(* schema.Set ).List ()),
868
883
}
869
884
}
870
885
@@ -874,9 +889,10 @@ func flattenSecurityPolicyAdvancedOptionsConfig(conf *compute.SecurityPolicyAdva
874
889
}
875
890
876
891
data := map [string ]interface {}{
877
- "json_parsing" : conf .JsonParsing ,
878
- "json_custom_config" : flattenSecurityPolicyAdvancedOptionsConfigJsonCustomConfig (conf .JsonCustomConfig ),
879
- "log_level" : conf .LogLevel ,
892
+ "json_parsing" : conf .JsonParsing ,
893
+ "json_custom_config" : flattenSecurityPolicyAdvancedOptionsConfigJsonCustomConfig (conf .JsonCustomConfig ),
894
+ "log_level" : conf .LogLevel ,
895
+ "user_ip_request_headers" : schema .NewSet (schema .HashString , tpgresource .ConvertStringArrToInterface (conf .UserIpRequestHeaders )),
880
896
}
881
897
882
898
return []map [string ]interface {}{data }
0 commit comments