15
15
package google
16
16
17
17
import (
18
+ "context"
18
19
"fmt"
19
20
"log"
20
21
"reflect"
@@ -24,6 +25,29 @@ import (
24
25
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
25
26
)
26
27
28
+ func storedInfoTypeCustomizeDiffFunc (diff TerraformResourceDiff ) error {
29
+ oldDict , newDict := diff .GetChange ("dictionary" )
30
+ oldRegex , newRegex := diff .GetChange ("regex" )
31
+ oldLargeCD , newLargeCD := diff .GetChange ("large_custom_dictionary" )
32
+ if ! isEmptyValue (reflect .ValueOf (oldDict )) && isEmptyValue (reflect .ValueOf (newDict )) {
33
+ diff .ForceNew ("dictionary" )
34
+ return nil
35
+ }
36
+ if ! isEmptyValue (reflect .ValueOf (oldRegex )) && isEmptyValue (reflect .ValueOf (newRegex )) {
37
+ diff .ForceNew ("regex" )
38
+ return nil
39
+ }
40
+ if ! isEmptyValue (reflect .ValueOf (oldLargeCD )) && isEmptyValue (reflect .ValueOf (newLargeCD )) {
41
+ diff .ForceNew ("large_custom_dictionary" )
42
+ return nil
43
+ }
44
+ return nil
45
+ }
46
+
47
+ func storedInfoTypeCustomizeDiff (_ context.Context , diff * schema.ResourceDiff , v interface {}) error {
48
+ return storedInfoTypeCustomizeDiffFunc (diff )
49
+ }
50
+
27
51
func ResourceDataLossPreventionStoredInfoType () * schema.Resource {
28
52
return & schema.Resource {
29
53
Create : resourceDataLossPreventionStoredInfoTypeCreate ,
@@ -41,6 +65,8 @@ func ResourceDataLossPreventionStoredInfoType() *schema.Resource {
41
65
Delete : schema .DefaultTimeout (20 * time .Minute ),
42
66
},
43
67
68
+ CustomizeDiff : storedInfoTypeCustomizeDiff ,
69
+
44
70
Schema : map [string ]* schema.Schema {
45
71
"parent" : {
46
72
Type : schema .TypeString ,
@@ -61,7 +87,6 @@ func ResourceDataLossPreventionStoredInfoType() *schema.Resource {
61
87
"dictionary" : {
62
88
Type : schema .TypeList ,
63
89
Optional : true ,
64
- ForceNew : true ,
65
90
Description : `Dictionary which defines the rule.` ,
66
91
MaxItems : 1 ,
67
92
Elem : & schema.Resource {
@@ -114,7 +139,6 @@ phrase and every phrase must contain at least 2 characters that are letters or d
114
139
"large_custom_dictionary" : {
115
140
Type : schema .TypeList ,
116
141
Optional : true ,
117
- ForceNew : true ,
118
142
Description : `Dictionary which defines the rule.` ,
119
143
MaxItems : 1 ,
120
144
Elem : & schema.Resource {
@@ -209,7 +233,6 @@ If any of these artifacts are modified, the dictionary is considered invalid and
209
233
"regex" : {
210
234
Type : schema .TypeList ,
211
235
Optional : true ,
212
- ForceNew : true ,
213
236
Description : `Regular expression which defines the rule.` ,
214
237
MaxItems : 1 ,
215
238
Elem : & schema.Resource {
@@ -223,7 +246,6 @@ Its syntax (https://github.com/google/re2/wiki/Syntax) can be found under the go
223
246
"group_indexes" : {
224
247
Type : schema .TypeList ,
225
248
Optional : true ,
226
- ForceNew : true ,
227
249
Description : `The index of the submatch to extract as findings. When not specified, the entire match is returned. No more than 3 may be included.` ,
228
250
Elem : & schema.Schema {
229
251
Type : schema .TypeInt ,
@@ -442,6 +464,24 @@ func resourceDataLossPreventionStoredInfoTypeUpdate(d *schema.ResourceData, meta
442
464
} else if v , ok := d .GetOkExists ("display_name" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , displayNameProp )) {
443
465
obj ["displayName" ] = displayNameProp
444
466
}
467
+ regexProp , err := expandDataLossPreventionStoredInfoTypeRegex (d .Get ("regex" ), d , config )
468
+ if err != nil {
469
+ return err
470
+ } else if v , ok := d .GetOkExists ("regex" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , regexProp )) {
471
+ obj ["regex" ] = regexProp
472
+ }
473
+ dictionaryProp , err := expandDataLossPreventionStoredInfoTypeDictionary (d .Get ("dictionary" ), d , config )
474
+ if err != nil {
475
+ return err
476
+ } else if v , ok := d .GetOkExists ("dictionary" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , dictionaryProp )) {
477
+ obj ["dictionary" ] = dictionaryProp
478
+ }
479
+ largeCustomDictionaryProp , err := expandDataLossPreventionStoredInfoTypeLargeCustomDictionary (d .Get ("large_custom_dictionary" ), d , config )
480
+ if err != nil {
481
+ return err
482
+ } else if v , ok := d .GetOkExists ("large_custom_dictionary" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , largeCustomDictionaryProp )) {
483
+ obj ["largeCustomDictionary" ] = largeCustomDictionaryProp
484
+ }
445
485
446
486
obj , err = resourceDataLossPreventionStoredInfoTypeEncoder (d , meta , obj )
447
487
if err != nil {
@@ -463,6 +503,18 @@ func resourceDataLossPreventionStoredInfoTypeUpdate(d *schema.ResourceData, meta
463
503
if d .HasChange ("display_name" ) {
464
504
updateMask = append (updateMask , "displayName" )
465
505
}
506
+
507
+ if d .HasChange ("regex" ) {
508
+ updateMask = append (updateMask , "regex" )
509
+ }
510
+
511
+ if d .HasChange ("dictionary" ) {
512
+ updateMask = append (updateMask , "dictionary" )
513
+ }
514
+
515
+ if d .HasChange ("large_custom_dictionary" ) {
516
+ updateMask = append (updateMask , "largeCustomDictionary" )
517
+ }
466
518
// updateMask is a URL parameter but not present in the schema, so replaceVars
467
519
// won't set it
468
520
url , err = addQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
0 commit comments