Skip to content

Commit 14ed602

Browse files
Fixes issue #24052 related to google_chronicle_reference_list resource (#15036) (#24250)
[upstream:58550b1c4dde492e4bea6c4e20551d3d022ffdec] Signed-off-by: Modular Magician <[email protected]>
1 parent d8e0034 commit 14ed602

File tree

5 files changed

+201
-67
lines changed

5 files changed

+201
-67
lines changed

.changelog/15036.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:note
2+
chronicle: made the `scope_info` field in `google_chronicle_reference_list` configurable
3+
```

google/services/chronicle/resource_chronicle_reference_list.go

Lines changed: 89 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,37 @@ REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING
110110
REFERENCE_LIST_SYNTAX_TYPE_REGEX
111111
REFERENCE_LIST_SYNTAX_TYPE_CIDR`,
112112
},
113+
"scope_info": {
114+
Type: schema.TypeList,
115+
Optional: true,
116+
Description: `ScopeInfo specifies the scope info of the reference list.`,
117+
MaxItems: 1,
118+
Elem: &schema.Resource{
119+
Schema: map[string]*schema.Schema{
120+
"reference_list_scope": {
121+
Type: schema.TypeList,
122+
Optional: true,
123+
Description: `ReferenceListScope specifies the list of scope names of the reference list.`,
124+
MaxItems: 1,
125+
Elem: &schema.Resource{
126+
Schema: map[string]*schema.Schema{
127+
"scope_names": {
128+
Type: schema.TypeList,
129+
Optional: true,
130+
DiffSuppressFunc: tpgresource.ProjectNumberDiffSuppress,
131+
Description: `Optional. The list of scope names of the reference list. The scope names should be
132+
full resource names and should be of the format:
133+
"projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}".`,
134+
Elem: &schema.Schema{
135+
Type: schema.TypeString,
136+
},
137+
},
138+
},
139+
},
140+
},
141+
},
142+
},
143+
},
113144
"display_name": {
114145
Type: schema.TypeString,
115146
Computed: true,
@@ -142,35 +173,6 @@ This is returned only when the view is REFERENCE_LIST_VIEW_FULL.`,
142173
Type: schema.TypeString,
143174
},
144175
},
145-
"scope_info": {
146-
Type: schema.TypeList,
147-
Computed: true,
148-
Description: `ScopeInfo specifies the scope info of the reference list.`,
149-
Elem: &schema.Resource{
150-
Schema: map[string]*schema.Schema{
151-
"reference_list_scope": {
152-
Type: schema.TypeList,
153-
Required: true,
154-
Description: `ReferenceListScope specifies the list of scope names of the reference list.`,
155-
MaxItems: 1,
156-
Elem: &schema.Resource{
157-
Schema: map[string]*schema.Schema{
158-
"scope_names": {
159-
Type: schema.TypeList,
160-
Optional: true,
161-
Description: `Optional. The list of scope names of the reference list. The scope names should be
162-
full resource names and should be of the format:
163-
"projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}".`,
164-
Elem: &schema.Schema{
165-
Type: schema.TypeString,
166-
},
167-
},
168-
},
169-
},
170-
},
171-
},
172-
},
173-
},
174176
"project": {
175177
Type: schema.TypeString,
176178
Optional: true,
@@ -202,6 +204,12 @@ func resourceChronicleReferenceListCreate(d *schema.ResourceData, meta interface
202204
} else if v, ok := d.GetOkExists("entries"); !tpgresource.IsEmptyValue(reflect.ValueOf(entriesProp)) && (ok || !reflect.DeepEqual(v, entriesProp)) {
203205
obj["entries"] = entriesProp
204206
}
207+
scopeInfoProp, err := expandChronicleReferenceListScopeInfo(d.Get("scope_info"), d, config)
208+
if err != nil {
209+
return err
210+
} else if v, ok := d.GetOkExists("scope_info"); !tpgresource.IsEmptyValue(reflect.ValueOf(scopeInfoProp)) && (ok || !reflect.DeepEqual(v, scopeInfoProp)) {
211+
obj["scopeInfo"] = scopeInfoProp
212+
}
205213
syntaxTypeProp, err := expandChronicleReferenceListSyntaxType(d.Get("syntax_type"), d, config)
206214
if err != nil {
207215
return err
@@ -356,6 +364,12 @@ func resourceChronicleReferenceListUpdate(d *schema.ResourceData, meta interface
356364
} else if v, ok := d.GetOkExists("entries"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, entriesProp)) {
357365
obj["entries"] = entriesProp
358366
}
367+
scopeInfoProp, err := expandChronicleReferenceListScopeInfo(d.Get("scope_info"), d, config)
368+
if err != nil {
369+
return err
370+
} else if v, ok := d.GetOkExists("scope_info"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, scopeInfoProp)) {
371+
obj["scopeInfo"] = scopeInfoProp
372+
}
359373
syntaxTypeProp, err := expandChronicleReferenceListSyntaxType(d.Get("syntax_type"), d, config)
360374
if err != nil {
361375
return err
@@ -380,6 +394,10 @@ func resourceChronicleReferenceListUpdate(d *schema.ResourceData, meta interface
380394
updateMask = append(updateMask, "entries")
381395
}
382396

397+
if d.HasChange("scope_info") {
398+
updateMask = append(updateMask, "scopeInfo")
399+
}
400+
383401
if d.HasChange("syntax_type") {
384402
updateMask = append(updateMask, "syntaxType")
385403
}
@@ -571,6 +589,48 @@ func expandChronicleReferenceListEntriesValue(v interface{}, d tpgresource.Terra
571589
return v, nil
572590
}
573591

592+
func expandChronicleReferenceListScopeInfo(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
593+
l := v.([]interface{})
594+
if len(l) == 0 || l[0] == nil {
595+
return nil, nil
596+
}
597+
raw := l[0]
598+
original := raw.(map[string]interface{})
599+
transformed := make(map[string]interface{})
600+
601+
transformedReferenceListScope, err := expandChronicleReferenceListScopeInfoReferenceListScope(original["reference_list_scope"], d, config)
602+
if err != nil {
603+
return nil, err
604+
} else if val := reflect.ValueOf(transformedReferenceListScope); val.IsValid() && !tpgresource.IsEmptyValue(val) {
605+
transformed["referenceListScope"] = transformedReferenceListScope
606+
}
607+
608+
return transformed, nil
609+
}
610+
611+
func expandChronicleReferenceListScopeInfoReferenceListScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
612+
l := v.([]interface{})
613+
if len(l) == 0 || l[0] == nil {
614+
return nil, nil
615+
}
616+
raw := l[0]
617+
original := raw.(map[string]interface{})
618+
transformed := make(map[string]interface{})
619+
620+
transformedScopeNames, err := expandChronicleReferenceListScopeInfoReferenceListScopeScopeNames(original["scope_names"], d, config)
621+
if err != nil {
622+
return nil, err
623+
} else if val := reflect.ValueOf(transformedScopeNames); val.IsValid() && !tpgresource.IsEmptyValue(val) {
624+
transformed["scopeNames"] = transformedScopeNames
625+
}
626+
627+
return transformed, nil
628+
}
629+
630+
func expandChronicleReferenceListScopeInfoReferenceListScopeScopeNames(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
631+
return v, nil
632+
}
633+
574634
func expandChronicleReferenceListSyntaxType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
575635
return v, nil
576636
}

google/services/chronicle/resource_chronicle_reference_list_generated_test.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,32 @@ func TestAccChronicleReferenceList_chronicleReferencelistBasicExample(t *testing
5353

5454
func testAccChronicleReferenceList_chronicleReferencelistBasicExample(context map[string]interface{}) string {
5555
return acctest.Nprintf(`
56+
resource "google_chronicle_data_access_scope" "test_scope" {
57+
location = "us"
58+
instance = "%{chronicle_id}"
59+
data_access_scope_id = "tf-test-scope-id%{random_suffix}"
60+
description = "test scope description"
61+
allowed_data_access_labels {
62+
log_type = "GCP_CLOUDAUDIT"
63+
}
64+
}
65+
5666
resource "google_chronicle_reference_list" "example" {
57-
location = "us"
58-
instance = "%{chronicle_id}"
59-
reference_list_id = "tf_test_reference_list_id%{random_suffix}"
60-
description = "referencelist-description"
61-
entries {
62-
value = "referencelist-entry-value"
63-
}
64-
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING"
67+
location = "us"
68+
instance = "%{chronicle_id}"
69+
reference_list_id = "tf_test_reference_list_id%{random_suffix}"
70+
description = "referencelist-description"
71+
entries {
72+
value = "referencelist-entry-value"
73+
}
74+
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING"
75+
scope_info {
76+
reference_list_scope {
77+
scope_names = [
78+
google_chronicle_data_access_scope.test_scope.name
79+
]
80+
}
81+
}
6582
}
6683
`, context)
6784
}

google/services/chronicle/resource_chronicle_reference_list_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ func TestAccChronicleReferenceList_chronicleReferencelistBasicExample_update(t *
2929
t.Parallel()
3030

3131
context := map[string]interface{}{
32-
"chronicle_id": envvar.GetTestChronicleInstanceIdFromEnv(t),
33-
"random_suffix": acctest.RandString(t, 10),
32+
"chronicle_id": envvar.GetTestChronicleInstanceIdFromEnv(t),
33+
"random_suffix": acctest.RandString(t, 10),
34+
"data_access_scope_id": "test-scope-id" + acctest.RandString(t, 5),
35+
"data_access_scope_id_new": "new-test-scope-id" + acctest.RandString(t, 5),
3436
}
3537

3638
acctest.VcrTest(t, resource.TestCase{
@@ -61,6 +63,16 @@ func TestAccChronicleReferenceList_chronicleReferencelistBasicExample_update(t *
6163

6264
func testAccChronicleReferenceList_chronicleReferencelistBasicExample_basic(context map[string]interface{}) string {
6365
return acctest.Nprintf(`
66+
resource "google_chronicle_data_access_scope" "test_scope" {
67+
location = "us"
68+
instance = "%{chronicle_id}"
69+
data_access_scope_id = "%{data_access_scope_id}"
70+
description = "test scope description"
71+
allowed_data_access_labels {
72+
log_type = "GCP_CLOUDAUDIT"
73+
}
74+
}
75+
6476
resource "google_chronicle_reference_list" "example" {
6577
location = "us"
6678
instance = "%{chronicle_id}"
@@ -70,12 +82,29 @@ resource "google_chronicle_reference_list" "example" {
7082
value = "referencelist-entry-value"
7183
}
7284
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING"
85+
scope_info {
86+
reference_list_scope {
87+
scope_names = [
88+
google_chronicle_data_access_scope.test_scope.name
89+
]
90+
}
91+
}
7392
}
7493
`, context)
7594
}
7695

7796
func testAccChronicleReferenceList_chronicleReferencelistBasicExample_update(context map[string]interface{}) string {
7897
return acctest.Nprintf(`
98+
resource "google_chronicle_data_access_scope" "test_scope" {
99+
location = "us"
100+
instance = "%{chronicle_id}"
101+
data_access_scope_id = "%{data_access_scope_id_new}"
102+
description = "test scope description"
103+
allowed_data_access_labels {
104+
log_type = "GITHUB"
105+
}
106+
}
107+
79108
resource "google_chronicle_reference_list" "example" {
80109
location = "us"
81110
instance = "%{chronicle_id}"
@@ -85,6 +114,13 @@ resource "google_chronicle_reference_list" "example" {
85114
value = "referencelist-entry-value-updated"
86115
}
87116
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_REGEX"
117+
scope_info {
118+
reference_list_scope {
119+
scope_names = [
120+
google_chronicle_data_access_scope.test_scope.name
121+
]
122+
}
123+
}
88124
}
89125
`, context)
90126
}

website/docs/r/chronicle_reference_list.html.markdown

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,32 @@ To get more information about ReferenceList, see:
3434

3535

3636
```hcl
37+
resource "google_chronicle_data_access_scope" "test_scope" {
38+
location = "us"
39+
instance = "00000000-0000-0000-0000-000000000000"
40+
data_access_scope_id = "scope-id"
41+
description = "test scope description"
42+
allowed_data_access_labels {
43+
log_type = "GCP_CLOUDAUDIT"
44+
}
45+
}
46+
3747
resource "google_chronicle_reference_list" "example" {
38-
location = "us"
39-
instance = "00000000-0000-0000-0000-000000000000"
40-
reference_list_id = "reference_list_id"
41-
description = "referencelist-description"
42-
entries {
43-
value = "referencelist-entry-value"
44-
}
45-
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING"
48+
location = "us"
49+
instance = "00000000-0000-0000-0000-000000000000"
50+
reference_list_id = "reference_list_id"
51+
description = "referencelist-description"
52+
entries {
53+
value = "referencelist-entry-value"
54+
}
55+
syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING"
56+
scope_info {
57+
reference_list_scope {
58+
scope_names = [
59+
google_chronicle_data_access_scope.test_scope.name
60+
]
61+
}
62+
}
4663
}
4764
```
4865

@@ -89,6 +106,11 @@ The following arguments are supported:
89106
- Must be unique.
90107

91108

109+
* `scope_info` -
110+
(Optional)
111+
ScopeInfo specifies the scope info of the reference list.
112+
Structure is [documented below](#nested_scope_info).
113+
92114
* `project` - (Optional) The ID of the project in which the resource belongs.
93115
If it is not provided, the provider project is used.
94116

@@ -100,6 +122,22 @@ The following arguments are supported:
100122
(Required)
101123
Required. The value of the entry. Maximum length is 512 characters.
102124

125+
<a name="nested_scope_info"></a>The `scope_info` block supports:
126+
127+
* `reference_list_scope` -
128+
(Optional)
129+
ReferenceListScope specifies the list of scope names of the reference list.
130+
Structure is [documented below](#nested_scope_info_reference_list_scope).
131+
132+
133+
<a name="nested_scope_info_reference_list_scope"></a>The `reference_list_scope` block supports:
134+
135+
* `scope_names` -
136+
(Optional)
137+
Optional. The list of scope names of the reference list. The scope names should be
138+
full resource names and should be of the format:
139+
"projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}".
140+
103141
## Attributes Reference
104142

105143
In addition to the arguments listed above, the following computed attributes are exported:
@@ -111,10 +149,6 @@ In addition to the arguments listed above, the following computed attributes are
111149
Format:
112150
projects/{project}/locations/{location}/instances/{instance}/referenceLists/{reference_list}
113151

114-
* `scope_info` -
115-
ScopeInfo specifies the scope info of the reference list.
116-
Structure is [documented below](#nested_scope_info).
117-
118152
* `display_name` -
119153
Output only. The unique display name of the reference list.
120154

@@ -130,22 +164,6 @@ In addition to the arguments listed above, the following computed attributes are
130164
Output only. The count of self-authored rules using the reference list.
131165

132166

133-
<a name="nested_scope_info"></a>The `scope_info` block contains:
134-
135-
* `reference_list_scope` -
136-
(Required)
137-
ReferenceListScope specifies the list of scope names of the reference list.
138-
Structure is [documented below](#nested_scope_info_reference_list_scope).
139-
140-
141-
<a name="nested_scope_info_reference_list_scope"></a>The `reference_list_scope` block supports:
142-
143-
* `scope_names` -
144-
(Optional)
145-
Optional. The list of scope names of the reference list. The scope names should be
146-
full resource names and should be of the format:
147-
"projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}".
148-
149167
## Timeouts
150168

151169
This resource provides the following

0 commit comments

Comments
 (0)