Skip to content

Commit d64cd90

Browse files
Add google_chronicle_retrohunt resource to chronicle (#12776) (#20962)
[upstream:f26eca6e692fe0f20a2aa596c0d8efca8d224831] Signed-off-by: Modular Magician <[email protected]>
1 parent 7a78213 commit d64cd90

File tree

3 files changed

+266
-0
lines changed

3 files changed

+266
-0
lines changed

.changelog/12776.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_chronicle_retrohunt`
3+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package chronicle
4+
5+
import (
6+
"encoding/json"
7+
"fmt"
8+
"time"
9+
10+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
11+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
12+
)
13+
14+
type ChronicleOperationWaiter struct {
15+
Config *transport_tpg.Config
16+
UserAgent string
17+
Project string
18+
tpgresource.CommonOperationWaiter
19+
}
20+
21+
func (w *ChronicleOperationWaiter) QueryOp() (interface{}, error) {
22+
if w == nil {
23+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
24+
}
25+
26+
region := tpgresource.GetRegionFromRegionalSelfLink(w.CommonOperationWaiter.Op.Name)
27+
28+
// Returns the proper get.
29+
url := fmt.Sprintf("https://%s-chronicle.googleapis.com/v1beta/%s", region, w.CommonOperationWaiter.Op.Name)
30+
31+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
32+
Config: w.Config,
33+
Method: "GET",
34+
Project: w.Project,
35+
RawURL: url,
36+
UserAgent: w.UserAgent,
37+
})
38+
}
39+
40+
func createChronicleWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*ChronicleOperationWaiter, error) {
41+
w := &ChronicleOperationWaiter{
42+
Config: config,
43+
UserAgent: userAgent,
44+
Project: project,
45+
}
46+
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
47+
return nil, err
48+
}
49+
return w, nil
50+
}
51+
52+
func ChronicleOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
53+
w, err := createChronicleWaiter(config, op, project, activity, userAgent)
54+
if err != nil {
55+
return err
56+
}
57+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
58+
return err
59+
}
60+
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
61+
}
62+
63+
func ChronicleOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
64+
if val, ok := op["name"]; !ok || val == "" {
65+
// This was a synchronous call - there is no operation to wait for.
66+
return nil
67+
}
68+
w, err := createChronicleWaiter(config, op, project, activity, userAgent)
69+
if err != nil {
70+
// If w is nil, the op was synchronous.
71+
return err
72+
}
73+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
# ----------------------------------------------------------------------------
3+
#
4+
# *** AUTO GENERATED CODE *** Type: MMv1 ***
5+
#
6+
# ----------------------------------------------------------------------------
7+
#
8+
# This file is automatically generated by Magic Modules and manual
9+
# changes will be clobbered when the file is regenerated.
10+
#
11+
# Please read more about how to change this file in
12+
# .github/CONTRIBUTING.md.
13+
#
14+
# ----------------------------------------------------------------------------
15+
subcategory: "Chronicle"
16+
description: |-
17+
Retrohunt is an execution of a Rule over a time range in the past.
18+
---
19+
20+
# google_chronicle_retrohunt
21+
22+
Retrohunt is an execution of a Rule over a time range in the past.
23+
24+
25+
To get more information about Retrohunt, see:
26+
27+
* [API documentation](https://cloud.google.com/chronicle/docs/reference/rest/v1alpha/projects.locations.instances.rules.retrohunts)
28+
* How-to Guides
29+
* [Google SecOps Guides](https://cloud.google.com/chronicle/docs/secops/secops-overview)
30+
31+
## Example Usage - Chronicle Retrohunt Basic
32+
33+
34+
```hcl
35+
resource "google_chronicle_rule" "my-rule" {
36+
provider = "google-beta"
37+
location = "us"
38+
instance = "00000000-0000-0000-0000-000000000000"
39+
deletion_policy = "FORCE"
40+
text = <<-EOT
41+
rule test_rule { meta: events: $userid = $e.principal.user.userid match: $userid over 10m condition: $e }
42+
EOT
43+
}
44+
45+
resource "google_chronicle_retrohunt" "example" {
46+
provider = "google-beta"
47+
location = "us"
48+
instance = "00000000-0000-0000-0000-000000000000"
49+
rule = element(split("/", resource.google_chronicle_rule.my-rule.name), length(split("/", resource.google_chronicle_rule.my-rule.name)) - 1)
50+
process_interval {
51+
start_time = "2025-01-01T00:00:00Z"
52+
end_time = "2025-01-01T12:00:00Z"
53+
}
54+
}
55+
```
56+
57+
## Argument Reference
58+
59+
The following arguments are supported:
60+
61+
62+
* `process_interval` -
63+
(Required)
64+
Represents a time interval, encoded as a Timestamp start (inclusive) and a
65+
Timestamp end (exclusive).
66+
The start must be less than or equal to the end.
67+
When the start equals the end, the interval is empty (matches no time).
68+
When both start and end are unspecified, the interval matches any time.
69+
Structure is [documented below](#nested_process_interval).
70+
71+
* `location` -
72+
(Required)
73+
The location of the resource. This is the geographical region where the Chronicle instance resides, such as "us" or "europe-west2".
74+
75+
* `instance` -
76+
(Required)
77+
The unique identifier for the Chronicle instance, which is the same as the customer ID.
78+
79+
* `rule` -
80+
(Required)
81+
The Rule ID of the rule.
82+
83+
84+
<a name="nested_process_interval"></a>The `process_interval` block supports:
85+
86+
* `start_time` -
87+
(Required)
88+
Inclusive start of the interval.
89+
90+
* `end_time` -
91+
(Required)
92+
Exclusive end of the interval.
93+
94+
- - -
95+
96+
97+
* `retrohunt` -
98+
(Optional)
99+
The retrohunt ID of the Retrohunt. A retrohunt is an execution of a Rule over a time range in the past.
100+
101+
* `project` - (Optional) The ID of the project in which the resource belongs.
102+
If it is not provided, the provider project is used.
103+
104+
105+
## Attributes Reference
106+
107+
In addition to the arguments listed above, the following computed attributes are exported:
108+
109+
* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/instances/{{instance}}/rules/{{rule}}/retrohunts/{{retrohunt}}`
110+
111+
* `progress_percentage` -
112+
Output only. Percent progress of the retrohunt towards completion, from 0.00 to 100.00.
113+
114+
* `name` -
115+
The resource name of the retrohunt.
116+
Retrohunt is the child of a rule revision. {rule} in the format below is
117+
structured as {rule_id@revision_id}.
118+
Format:
119+
projects/{project}/locations/{location}/instances/{instance}/rules/{rule}/retrohunts/{retrohunt}
120+
121+
* `execution_interval` -
122+
Represents a time interval, encoded as a Timestamp start (inclusive) and a
123+
Timestamp end (exclusive).
124+
The start must be less than or equal to the end.
125+
When the start equals the end, the interval is empty (matches no time).
126+
When both start and end are unspecified, the interval matches any time.
127+
Structure is [documented below](#nested_execution_interval).
128+
129+
* `state` -
130+
Output only. The state of the retrohunt.
131+
Possible values:
132+
RUNNING
133+
DONE
134+
CANCELLED
135+
FAILED
136+
137+
138+
<a name="nested_execution_interval"></a>The `execution_interval` block contains:
139+
140+
* `end_time` -
141+
(Optional)
142+
Optional. Exclusive end of the interval.
143+
If specified, a Timestamp matching this interval will have to be before the
144+
end.
145+
146+
* `start_time` -
147+
(Optional)
148+
Optional. Inclusive start of the interval.
149+
If specified, a Timestamp matching this interval will have to be the same
150+
or after the start.
151+
152+
## Timeouts
153+
154+
This resource provides the following
155+
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
156+
157+
- `create` - Default is 20 minutes.
158+
- `delete` - Default is 20 minutes.
159+
160+
## Import
161+
162+
163+
Retrohunt can be imported using any of these accepted formats:
164+
165+
* `projects/{{project}}/locations/{{location}}/instances/{{instance}}/rules/{{rule}}/retrohunts/{{retrohunt}}`
166+
* `{{project}}/{{location}}/{{instance}}/{{rule}}/{{retrohunt}}`
167+
* `{{location}}/{{instance}}/{{rule}}/{{retrohunt}}`
168+
169+
170+
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Retrohunt using one of the formats above. For example:
171+
172+
```tf
173+
import {
174+
id = "projects/{{project}}/locations/{{location}}/instances/{{instance}}/rules/{{rule}}/retrohunts/{{retrohunt}}"
175+
to = google_chronicle_retrohunt.default
176+
}
177+
```
178+
179+
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Retrohunt can be imported using one of the formats above. For example:
180+
181+
```
182+
$ terraform import google_chronicle_retrohunt.default projects/{{project}}/locations/{{location}}/instances/{{instance}}/rules/{{rule}}/retrohunts/{{retrohunt}}
183+
$ terraform import google_chronicle_retrohunt.default {{project}}/{{location}}/{{instance}}/{{rule}}/{{retrohunt}}
184+
$ terraform import google_chronicle_retrohunt.default {{location}}/{{instance}}/{{rule}}/{{retrohunt}}
185+
```
186+
187+
## User Project Overrides
188+
189+
This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).

0 commit comments

Comments
 (0)