Skip to content

Commit

Permalink
Added stored_info_type_id field in google_data_loss_prevention_stored…
Browse files Browse the repository at this point in the history
…_info_type (#8057) (#5708)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jun 2, 2023
1 parent a82b9d9 commit 97d4767
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/8057.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dlp: added `stored_info_type_id` field to `google_data_loss_prevention_stored_info_type` resource
```
26 changes: 25 additions & 1 deletion google-beta/resource_data_loss_prevention_stored_info_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ Its syntax (https://github.com/google/re2/wiki/Syntax) can be found under the go
},
ExactlyOneOf: []string{"dictionary", "regex", "large_custom_dictionary"},
},
"stored_info_type_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The storedInfoType ID can contain uppercase and lowercase letters, numbers, and hyphens;
that is, it must match the regular expression: [a-zA-Z\d-_]+. The maximum length is 100
characters. Can be empty to allow the system to generate one.`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -512,7 +521,7 @@ func resourceDataLossPreventionStoredInfoTypeUpdate(d *schema.ResourceData, meta
obj["largeCustomDictionary"] = largeCustomDictionaryProp
}

obj, err = resourceDataLossPreventionStoredInfoTypeEncoder(d, meta, obj)
obj, err = resourceDataLossPreventionStoredInfoTypeUpdateEncoder(d, meta, obj)
if err != nil {
return err
}
Expand Down Expand Up @@ -1136,6 +1145,16 @@ func expandDataLossPreventionStoredInfoTypeLargeCustomDictionaryBigQueryFieldFie
}

func resourceDataLossPreventionStoredInfoTypeEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
newObj := make(map[string]interface{})
newObj["config"] = obj
storedInfoTypeIdProp, ok := d.GetOk("stored_info_type_id")
if ok && storedInfoTypeIdProp != nil {
newObj["storedInfoTypeId"] = storedInfoTypeIdProp
}
return newObj, nil
}

func resourceDataLossPreventionStoredInfoTypeUpdateEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
newObj := make(map[string]interface{})
newObj["config"] = obj
return newObj, nil
Expand All @@ -1160,5 +1179,10 @@ func resourceDataLossPreventionStoredInfoTypeDecoder(d *schema.ResourceData, met
// Name comes back on the top level, so set here
config["name"] = name

configMeta := meta.(*transport_tpg.Config)
if err := d.Set("stored_info_type_id", flattenDataLossPreventionStoredInfoTypeName(res["name"], d, configMeta)); err != nil {
return nil, fmt.Errorf("Error reading StoredInfoType: %s", err)
}

return config, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeBasicExample(t *te
ResourceName: "google_data_loss_prevention_stored_info_type.basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
ImportStateVerifyIgnore: []string{"stored_info_type_id", "parent"},
},
},
})
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeDictionaryExample(
ResourceName: "google_data_loss_prevention_stored_info_type.dictionary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
ImportStateVerifyIgnore: []string{"stored_info_type_id", "parent"},
},
},
})
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeLargeCustomDiction
ResourceName: "google_data_loss_prevention_stored_info_type.large",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
ImportStateVerifyIgnore: []string{"stored_info_type_id", "parent"},
},
},
})
Expand Down Expand Up @@ -170,6 +170,48 @@ resource "google_storage_bucket_object" "object" {
`, context)
}

func TestAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeWithIdExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": acctest.GetTestProjectFromEnv(),
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDataLossPreventionStoredInfoTypeDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeWithIdExample(context),
},
{
ResourceName: "google_data_loss_prevention_stored_info_type.with_stored_info_type_id",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"stored_info_type_id", "parent"},
},
},
})
}

func testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeWithIdExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_data_loss_prevention_stored_info_type" "with_stored_info_type_id" {
parent = "projects/%{project}"
description = "Description"
display_name = "Displayname"
stored_info_type_id = "tf-test-id-%{random_suffix}"
regex {
pattern = "patient"
group_indexes = [2]
}
}
`, context)
}

func testAccCheckDataLossPreventionStoredInfoTypeDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
65 changes: 65 additions & 0 deletions google-beta/resource_data_loss_prevention_stored_info_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,68 @@ resource "google_data_loss_prevention_stored_info_type" "basic" {
}
`, context)
}

func TestAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeStoredInfoTypeId(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project": acctest.GetTestProjectFromEnv(),
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDataLossPreventionStoredInfoTypeDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeStoredInfoTypeId(context),
},
{
ResourceName: "google_data_loss_prevention_stored_info_type.basic",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeStoredInfoTypeIdUpdate(context),
},
{
ResourceName: "google_data_loss_prevention_stored_info_type.basic",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeStoredInfoTypeId(context map[string]interface{}) string {
return Nprintf(`
resource "google_data_loss_prevention_stored_info_type" "basic" {
parent = "projects/%{project}"
description = "Description"
display_name = "Displayname"
stored_info_type_id = "tf-test-%{random_suffix}"
regex {
pattern = "patient"
group_indexes = [2]
}
}
`, context)
}

func testAccDataLossPreventionStoredInfoType_dlpStoredInfoTypeStoredInfoTypeIdUpdate(context map[string]interface{}) string {
return Nprintf(`
resource "google_data_loss_prevention_stored_info_type" "basic" {
parent = "projects/%{project}"
description = "Description"
display_name = "Displayname"
stored_info_type_id = "tf-test-update-%{random_suffix}"
regex {
pattern = "patient"
group_indexes = [2]
}
}
`, context)
}
22 changes: 22 additions & 0 deletions website/docs/r/data_loss_prevention_stored_info_type.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ resource "google_storage_bucket_object" "object" {
source = "./test-fixtures/dlp/words.txt"
}
```
## Example Usage - Dlp Stored Info Type With Id


```hcl
resource "google_data_loss_prevention_stored_info_type" "with_stored_info_type_id" {
parent = "projects/my-project-name"
description = "Description"
display_name = "Displayname"
stored_info_type_id = "id-"
regex {
pattern = "patient"
group_indexes = [2]
}
}
```

## Argument Reference

Expand All @@ -116,6 +132,12 @@ The following arguments are supported:
(Optional)
User set display name of the info type.

* `stored_info_type_id` -
(Optional)
The storedInfoType ID can contain uppercase and lowercase letters, numbers, and hyphens;
that is, it must match the regular expression: [a-zA-Z\d-_]+. The maximum length is 100
characters. Can be empty to allow the system to generate one.

* `regex` -
(Optional)
Regular expression which defines the rule.
Expand Down

0 comments on commit 97d4767

Please sign in to comment.