Skip to content

Commit

Permalink
Add the DLP switch for replace_with_info_type_config. (#4920) (#9446)
Browse files Browse the repository at this point in the history
* Add the DLP switch for replace_with_info_type_config.

* Add override note.

* format of example.

* change name - add Config.

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jun 25, 2021
1 parent a10e31f commit 379bcb4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/4920.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dlp: Added `replace_with_info_type_config` to `dlp_deidentify_template`.
```
26 changes: 26 additions & 0 deletions google/resource_data_loss_prevention_deidentify_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`,
},
},
},
"replace_with_info_type_config": {
Type: schema.TypeBool,
Optional: true,
Description: `Replace each matching finding with the name of the info type.`,
},
},
},
},
Expand Down Expand Up @@ -626,6 +631,8 @@ func flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransfor
transformed := make(map[string]interface{})
transformed["replace_config"] =
flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationReplaceConfig(original["replaceConfig"], d, config)
transformed["replace_with_info_type_config"] =
flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationReplaceWithInfoTypeConfig(original["replaceWithInfoTypeConfig"], d, config)
transformed["character_mask_config"] =
flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationCharacterMaskConfig(original["characterMaskConfig"], d, config)
return []interface{}{transformed}
Expand Down Expand Up @@ -862,6 +869,10 @@ func flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransfor
return v
}

func flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationReplaceWithInfoTypeConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v != nil
}

func flattenDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationCharacterMaskConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1050,6 +1061,13 @@ func expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransform
transformed["replaceConfig"] = transformedReplaceConfig
}

transformedReplaceWithInfoTypeConfig, err := expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationReplaceWithInfoTypeConfig(original["replace_with_info_type_config"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedReplaceWithInfoTypeConfig); val.IsValid() && !isEmptyValue(val) {
transformed["replaceWithInfoTypeConfig"] = transformedReplaceWithInfoTypeConfig
}

transformedCharacterMaskConfig, err := expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationCharacterMaskConfig(original["character_mask_config"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1272,6 +1290,14 @@ func expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransform
return v, nil
}

func expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationReplaceWithInfoTypeConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
if v == nil || !v.(bool) {
return nil, nil
}

return struct{}{}, nil
}

func expandDataLossPreventionDeidentifyTemplateDeidentifyConfigInfoTypeTransformationsTransformationsPrimitiveTransformationCharacterMaskConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ resource "google_data_loss_prevention_deidentify_template" "basic" {
deidentify_config {
info_type_transformations {
transformations {
info_types {
name = "FIRST_NAME"
}
primitive_transformation {
replace_with_info_type_config = true
}
}
transformations {
info_types {
name = "PHONE_NUMBER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ resource "google_data_loss_prevention_deidentify_template" "basic" {
deidentify_config {
info_type_transformations {
transformations {
info_types {
name = "FIRST_NAME"
}
primitive_transformation {
replace_with_info_type_config = true
}
}
transformations {
info_types {
name = "PHONE_NUMBER"
Expand Down Expand Up @@ -168,6 +178,10 @@ The `primitive_transformation` block supports:
Replace each input value with a given value.
Structure is documented below.

* `replace_with_info_type_config` -
(Optional)
Replace each matching finding with the name of the info type.

* `character_mask_config` -
(Optional)
Partially mask a string by replacing a given number of characters with a fixed character.
Expand Down

0 comments on commit 379bcb4

Please sign in to comment.