-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(chronicle): Add Terraform support for Chronicle Parser #17774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
govisingh-dotcom
wants to merge
3
commits into
GoogleCloudPlatform:main
Choose a base branch
from
govisingh-dotcom:chronicle-parser-only-govisingh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+458
−0
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
95169e2
feat(chronicle): Add Terraform support for Chronicle Parser
govisingh-dotcom 6257764
test(chronicle): Add update test for parser and add flattener comment
govisingh-dotcom fe203c9
test(chronicle): Ignore version_info during import verification in up…
govisingh-dotcom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,353 @@ | ||
| # Copyright 2026 Google Inc. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| --- | ||
| name: Parser | ||
| description: |- | ||
| A parser is a configuration that parses raw logs of a specific log type into Unified Data Model (UDM) events. | ||
| Chronicle supports both customer-created custom parsers and Google-provided prebuilt parsers. | ||
| references: | ||
| guides: | ||
| 'Custom parsers overview': 'https://cloud.google.com/chronicle/docs/detection/custom-parsers-overview' | ||
| api: 'https://cloud.google.com/chronicle/docs/reference/rest/v1/projects.locations.instances.logTypes.parsers' | ||
| base_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/logTypes/{{logtype}}/parsers | ||
| self_link: projects/{{project}}/locations/{{location}}/instances/{{instance}}/logTypes/{{logtype}}/parsers/{{parser}} | ||
| create_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/logTypes/{{logtype}}/parsers | ||
| update_mask: true | ||
| update_verb: PATCH | ||
| import_format: | ||
| - projects/{{project}}/locations/{{location}}/instances/{{instance}}/logTypes/{{logtype}}/parsers/{{parser}} | ||
| autogen_status: UGFyc2Vy | ||
| autogen_async: false | ||
| samples: | ||
| - name: 'chronicle_parser_basic' | ||
| primary_resource_id: 'example' | ||
| steps: | ||
| - name: 'chronicle_parser_basic' | ||
| test_env_vars: | ||
| chronicle_id: 'CHRONICLE_ID' | ||
| ignore_read_extra: | ||
| - 'state' | ||
| - 'validation_report' | ||
| - 'validation_stage' | ||
| - 'validated_on_empty_logs' | ||
| - name: 'chronicle_parser_full' | ||
| primary_resource_id: 'example' | ||
| steps: | ||
| - name: 'chronicle_parser_full' | ||
| test_env_vars: | ||
| chronicle_id: 'CHRONICLE_ID' | ||
| ignore_read_extra: | ||
| - 'state' | ||
| - 'validation_report' | ||
| - 'validation_stage' | ||
| - 'validated_on_empty_logs' | ||
| - 'low_code.0.field_extractors.0.append_repeated_fields' | ||
| - 'version_info' | ||
| parameters: | ||
| - name: location | ||
| type: String | ||
| required: true | ||
| description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122. | ||
| immutable: true | ||
| url_param_only: true | ||
| - name: instance | ||
| type: String | ||
| required: true | ||
| description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122. | ||
| immutable: true | ||
| url_param_only: true | ||
| - name: logtype | ||
| type: String | ||
| required: true | ||
| description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122. | ||
| immutable: true | ||
| url_param_only: true | ||
| - name: parser | ||
| type: String | ||
| output: true | ||
| custom_flatten: 'templates/terraform/custom_flatten/id_from_name.tmpl' | ||
| description: Output only. The server-generated ID of the parser. | ||
| properties: | ||
| - name: cbn | ||
| type: String | ||
| immutable: true | ||
| description: |- | ||
| if the parser is built using config | ||
| documentation: | ||
| https://cloud.google.com/chronicle/docs/preview/parser-extensions/parsing-overview | ||
| - name: changelogs | ||
| type: NestedObject | ||
| output: true | ||
| description: Changelogs of a parser. | ||
| properties: | ||
| - name: entries | ||
| type: Array | ||
| description: all the changelog of a parser. | ||
| item_type: | ||
| type: NestedObject | ||
| properties: | ||
| - name: changeMessage | ||
| type: String | ||
| description: The changelog message. | ||
| output: true | ||
| - name: createTime | ||
| type: String | ||
| description: Time at which changelog was created. | ||
| output: true | ||
| - name: deleted | ||
| type: Boolean | ||
| description: |- | ||
| Flag whether the entry is added or deleted. | ||
| This will be true in case of rollback and false in case of upgrade. | ||
| output: true | ||
| - name: parserVersion | ||
| type: String | ||
| description: The parser version for which the changelog is created. | ||
| output: true | ||
| - name: createTime | ||
| type: String | ||
| description: Time at which parser was created. | ||
| output: true | ||
| - name: creator | ||
| type: NestedObject | ||
| output: true | ||
| description: Information about the creator of the parser. | ||
| properties: | ||
| - name: author | ||
| type: String | ||
| description: The name of the author, who created this parser. | ||
| output: true | ||
| - name: customer | ||
| type: String | ||
| description: |- | ||
| The customer who created it, This can represent the partner as well. | ||
| In case of prebuilt parser this will be empty. | ||
| output: true | ||
| - name: source | ||
| type: String | ||
| description: |- | ||
| The source of the parser. | ||
| Possible values: | ||
| CUSTOM_GOOGLE_OVERRIDE | ||
| PARTNER | ||
| CUSTOMER | ||
| output: true | ||
| - name: dynamicParsingConfig | ||
| type: String | ||
| description: Dynamic parsing config applied over the parser, if any. | ||
| output: true | ||
| - name: lowCode | ||
| type: NestedObject | ||
| immutable: true | ||
| description: Message to represent LowCodeParser. | ||
| properties: | ||
| - name: fieldExtractors | ||
| type: NestedObject | ||
| description: A representation of a parser extension as a set of field extractors. | ||
| properties: | ||
| - name: appendRepeatedFields | ||
| type: Boolean | ||
| ignore_read: true | ||
| description: |- | ||
| Whether to append repeated fields or not. | ||
| When false, repeated fields will be replaced. | ||
| - name: extractors | ||
| type: Array | ||
| description: List of FieldExtractors. | ||
| item_type: | ||
| type: NestedObject | ||
| properties: | ||
| - name: destinationPath | ||
| type: String | ||
| description: |- | ||
| Path in generated event which is to be populated. This is required if the | ||
| FieldExtractor is used to specify the parser extension. | ||
| - name: fieldPath | ||
| type: String | ||
| description: |- | ||
| Field path could be a json path, xml path or csv column name | ||
| depending on log format. It refers to a section or substring in raw log. | ||
| This is required if the FieldExtractor is used to specify the parser | ||
| extension. | ||
| - name: preconditionOp | ||
| type: String | ||
| description: |- | ||
| Operator used for precondition. | ||
| Possible values: | ||
| EQUALS | ||
| NOT_EQUALS | ||
| - name: preconditionPath | ||
| type: String | ||
| description: |- | ||
| Precondition path could be a json path, xml path or csv column name | ||
| depending on log format. It refers to a section or substring in raw log. | ||
| - name: preconditionValue | ||
| type: String | ||
| description: Precondition value. | ||
| - name: value | ||
| type: String | ||
| description: Value to be mapped to the destination path directly. | ||
| - name: logFormat | ||
| type: String | ||
| description: |- | ||
| Possible values: | ||
| JSON | ||
| CSV | ||
| XML | ||
| - name: preprocessConfig | ||
| type: NestedObject | ||
| description: PreProcessConfig holds the GROK expression to extract the syslog header. | ||
| properties: | ||
| - name: grokRegex | ||
| type: String | ||
| description: |- | ||
| GROK Regex to extract the structured part of the log. | ||
| syntax documentation: | ||
| www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html | ||
| - name: target | ||
| type: String | ||
| description: |- | ||
| Target field name for the structured part of the log. | ||
| This should match a SEMANTIC identifier from the grok expression. | ||
| - name: transformedCbnSnippet | ||
| type: String | ||
| description: CBN snippet generated from field extractors. | ||
| output: true | ||
| - name: log | ||
| type: String | ||
| description: The log used to create this low code parser in the UI. | ||
| - name: name | ||
| type: String | ||
| description: name of the parser resource. | ||
| output: true | ||
| - name: parserExtension | ||
| type: String | ||
| description: Extension applied over the parser, if any. | ||
| output: true | ||
| - name: releaseStage | ||
| type: String | ||
| description: |- | ||
| The release stage of the parser | ||
| After internal validations the prebuilt parser will directly start as | ||
| Release Candidate. The release_stage of prebuilt parsers are changed | ||
| after every release cycle: | ||
| The prebuilt Release Candidate parser is promoted as Release parser. | ||
| The existing prebuilt Release parser is moved to Rollback state. | ||
| and existing prebuilt rollback parser is moved to Archived. | ||
| In case of custom parser: | ||
| When the customer submits a validation passed custom parser it starts as | ||
| Release state. | ||
| And existing one is moved to Rollback stage. | ||
| And the existing rollback is moved to Archived. | ||
| In case a release or release candidate parser is found faulty, | ||
| the parser is marked FAULTY, | ||
| if it is release parser then rollback candidate is moved to release. | ||
| Possible values: | ||
| RELEASE | ||
| RELEASE_CANDIDATE | ||
| ROLLBACK_CANDIDATE | ||
| ARCHIVED | ||
| FAULTY | ||
| ARCHIVED_IN_USE | ||
| output: true | ||
| - name: state | ||
| type: String | ||
| description: |- | ||
| The state of the parser | ||
| Possible values: | ||
| ACTIVE | ||
| INACTIVE | ||
| output: true | ||
| - name: type | ||
| type: String | ||
| description: |- | ||
| The type of the parser | ||
| Possible values: | ||
| CUSTOM | ||
| PREBUILT | ||
| output: true | ||
| - name: validatedOnEmptyLogs | ||
| type: Boolean | ||
| immutable: true | ||
| ignore_read: true | ||
| description: |- | ||
| Flag to bypass parser validation when no logs are found. | ||
| If enabled, the parser won't be be rejected during the validation | ||
| phase when no logs are found. | ||
| - name: validationReport | ||
| type: String | ||
| description: The Validation report generated during parser validation. | ||
| output: true | ||
| - name: validationSkipped | ||
| type: Boolean | ||
| immutable: true | ||
| description: |- | ||
| If true, bypasses parser validation. | ||
| If enabled, the parser won't be rejected during the validation | ||
| phase and validation will be skipped. | ||
| - name: validationStage | ||
| type: String | ||
| description: |- | ||
| The validation stage of the parser | ||
| When a customer submits a new parser for validation, it starts with a | ||
| new stage. | ||
| When parser is picked for validation, it changes to Validation state. | ||
| If validation failed it is marked as failed, and | ||
| existing failed is moved to delete_candidate stage. | ||
| If passes it is moved to passed stage. | ||
| If customer opts to submit it, the parser is moved to Release State. | ||
| Possible values: | ||
| NEW | ||
| VALIDATING | ||
| PASSED | ||
| FAILED | ||
| DELETE_CANDIDATE | ||
| INTERNAL_ERROR | ||
| VALIDATION_SKIPPED | ||
| output: true | ||
| - name: versionInfo | ||
| type: NestedObject | ||
| custom_flatten: 'templates/terraform/custom_flatten/chronicle_parser_version_info.go.tmpl' | ||
| description: |- | ||
| ParserVersionInfo gives the version information of the parser and related | ||
| properties like pinned etc. | ||
| update_mask_fields: | ||
| - 'version_info.auto_upgrade_disabled' | ||
| properties: | ||
| - name: autoUpgradeDisabled | ||
| type: Boolean | ||
| required: true | ||
| description: |- | ||
| Signifies if the parser is disabled for auto upgrade. If true, the parser | ||
| will not be upgraded by the auto upgrade process. | ||
| - name: latestParser | ||
| type: String | ||
| description: |- | ||
| The resource name of latest Parser for this logtype. | ||
| Format: | ||
| projects/{project}/locations/{region}/instances/{instance}/logTypes/{log_type}/parsers/{parser}/{id} | ||
| output: true | ||
| - name: latestParserVersion | ||
| type: String | ||
| description: The version for the latest available stable version of the parser. | ||
| output: true | ||
| - name: rollbackAvailable | ||
| type: Boolean | ||
| description: Signifies if rollback is available for this parser version. | ||
| output: true | ||
| - name: version | ||
| type: String | ||
| description: The version of the parser. | ||
| output: true | ||
14 changes: 14 additions & 0 deletions
14
mmv1/templates/terraform/custom_flatten/chronicle_parser_version_info.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment on the purpose of this file for better readabillity?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure added. Thanks |
||
| if v == nil { | ||
| // If the API returned nil (common for custom parsers), preserve local state. | ||
| return d.Get("version_info") | ||
| } | ||
| original := v.(map[string]interface{}) | ||
| transformed := make(map[string]interface{}) | ||
| transformed["auto_upgrade_disabled"] = original["autoUpgradeDisabled"] | ||
| transformed["latest_parser"] = original["latestParser"] | ||
| transformed["latest_parser_version"] = original["latestParserVersion"] | ||
| transformed["rollback_available"] = original["rollbackAvailable"] | ||
| transformed["version"] = original["version"] | ||
| return []interface{}{transformed} | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
mmv1/templates/terraform/samples/services/chronicle/chronicle_parser_basic.tf.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "google_chronicle_parser" "{{$.PrimaryResourceId}}" { | ||
| location = "us" | ||
| instance = "{{index $.TestEnvVars "chronicle_id"}}" | ||
| logtype = "WINDOWS_DHCP" # Static standard prebuilt log type | ||
| validation_skipped = true | ||
| cbn = "ZHVtbXkgcGFyc2VyIGNvbmZpZw==" # Base64 encoded "dummy parser config" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add update tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually most of the writeable fields for google_chronicle_parser (such as cbn, low_code, and validated_on_empty_logs) are immutable (ForceNew: true), meaning any changes to them force the resource to be recreated. Because of this, we split the configurations into separate basic and full single-step tests to verify these fields.
The only mutable field that supports in-place updates is version_info.auto_upgrade_disabled. I will add a multi-step update test that toggles auto_upgrade_disabled."