forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Add LogSink converter #6
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
Draft
google-labs-jules
wants to merge
7
commits into
main
Choose a base branch
from
add-log-sink-converter
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.
Draft
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e3520dd
feat: Add LogSink converter
google-labs-jules[bot] 311280a
feat: Add LogSink converter
google-labs-jules[bot] a495564
feat: Add LogSink converter
google-labs-jules[bot] 7a7276f
Merge branch 'main' into add-log-sink-converter
hemantadil 1c91434
update ancestry_path
hemantadil 4e826f5
Remove the parent field from data field
hemantadil 970d185
Clean up imports in logging_folder_sink.go
hemantadil 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
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
219 changes: 219 additions & 0 deletions
219
mmv1/third_party/tgc/services/logging/logging_folder_sink.go
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,219 @@ | ||
| package logging | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "reflect" | ||
| "strings" | ||
|
|
||
| "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai" | ||
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" | ||
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" | ||
| ) | ||
|
|
||
| const LogSinkAssetType string = "logging.googleapis.com/LogSink" | ||
|
|
||
| func ResourceConverterLogFolderSink() cai.ResourceConverter { | ||
| return cai.ResourceConverter{ | ||
| AssetType: LogSinkAssetType, | ||
| Convert: GetLogFolderSinkCaiObject, | ||
| } | ||
| } | ||
|
|
||
| func GetLogFolderSinkCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { | ||
| name, err := cai.AssetName(d, config, "//logging.googleapis.com/folders/{{folder}}/sinks/{{name}}") | ||
| if err != nil { | ||
| return []cai.Asset{}, err | ||
| } | ||
| if obj, err := GetLogFolderSinkApiObject(d, config); err == nil { | ||
| return []cai.Asset{{ | ||
| Name: name, | ||
| Type: LogSinkAssetType, | ||
| Resource: &cai.AssetResource{ | ||
| Version: "v2", | ||
| DiscoveryDocumentURI: "https://logging.googleapis.com/$discovery/rest", | ||
| DiscoveryName: "LogSink", | ||
| Data: obj, | ||
| }, | ||
| }}, nil | ||
| } else { | ||
| return []cai.Asset{}, err | ||
| } | ||
| } | ||
|
|
||
| func GetLogFolderSinkApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { | ||
| obj := make(map[string]interface{}) | ||
| nameProp, err := expandLogFolderSinkName(d.Get("name"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { | ||
| obj["name"] = nameProp | ||
| } | ||
|
|
||
| destinationProp, err := expandLogFolderSinkDestination(d.Get("destination"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("destination"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationProp)) && (ok || !reflect.DeepEqual(v, destinationProp)) { | ||
| obj["destination"] = destinationProp | ||
| } | ||
|
|
||
| filterProp, err := expandLogFolderSinkFilter(d.Get("filter"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) { | ||
| obj["filter"] = filterProp | ||
| } | ||
|
|
||
| descriptionProp, err := expandLogFolderSinkDescription(d.Get("description"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { | ||
| obj["description"] = descriptionProp | ||
| } | ||
|
|
||
| disabledProp, err := expandLogFolderSinkDisabled(d.Get("disabled"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) { | ||
| obj["disabled"] = disabledProp | ||
| } | ||
|
|
||
| exclusionsProp, err := expandLogFolderSinkExclusions(d.Get("exclusions"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("exclusions"); !tpgresource.IsEmptyValue(reflect.ValueOf(exclusionsProp)) && (ok || !reflect.DeepEqual(v, exclusionsProp)) { | ||
| obj["exclusions"] = exclusionsProp | ||
| } | ||
|
|
||
| includeChildrenProp, err := expandLogFolderSinkIncludeChildren(d.Get("include_children"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("include_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(includeChildrenProp)) && (ok || !reflect.DeepEqual(v, includeChildrenProp)) { | ||
| obj["includeChildren"] = includeChildrenProp | ||
| } | ||
|
|
||
| bigqueryOptionsProp, err := expandLogFolderSinkBigqueryOptions(d.Get("bigquery_options"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("bigquery_options"); !tpgresource.IsEmptyValue(reflect.ValueOf(bigqueryOptionsProp)) && (ok || !reflect.DeepEqual(v, bigqueryOptionsProp)) { | ||
| obj["bigqueryOptions"] = bigqueryOptionsProp | ||
| } | ||
|
|
||
| folder, ok := d.GetOk("folder") | ||
| if !ok { | ||
| return nil, fmt.Errorf("required field 'folder' is not set") | ||
| } | ||
| folderId := strings.TrimPrefix(folder.(string), "folders/") | ||
| obj["parent"] = fmt.Sprintf("//cloudresourcemanager.googleapis.com/folders/%s", folderId) | ||
|
|
||
| return obj, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkExclusions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| l, ok := v.([]interface{}) | ||
| if !ok { | ||
| return nil, nil | ||
| } | ||
|
|
||
| req := make([]interface{}, 0, len(l)) | ||
| for _, raw := range l { | ||
| if raw == nil { | ||
| continue | ||
| } | ||
| original := raw.(map[string]interface{}) | ||
| transformed := make(map[string]interface{}) | ||
|
|
||
| transformedName, err := expandLogFolderSinkExclusionsName(original["name"], d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if val := reflect.ValueOf(transformedName); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
| transformed["name"] = transformedName | ||
| } | ||
|
|
||
| transformedDescription, err := expandLogFolderSinkExclusionsDescription(original["description"], d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
| transformed["description"] = transformedDescription | ||
| } | ||
|
|
||
| transformedFilter, err := expandLogFolderSinkExclusionsFilter(original["filter"], d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
| transformed["filter"] = transformedFilter | ||
| } | ||
|
|
||
| transformedDisabled, err := expandLogFolderSinkExclusionsDisabled(original["disabled"], d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if val := reflect.ValueOf(transformedDisabled); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
| transformed["disabled"] = transformedDisabled | ||
| } | ||
|
|
||
| req = append(req, transformed) | ||
| } | ||
| return req, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkExclusionsName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkExclusionsDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkExclusionsFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkExclusionsDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkIncludeChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkBigqueryOptions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| l := v.([]interface{}) | ||
| if len(l) == 0 || l[0] == nil { | ||
| return nil, nil | ||
| } | ||
| raw := l[0] | ||
| original := raw.(map[string]interface{}) | ||
| transformed := make(map[string]interface{}) | ||
|
|
||
| transformedUsePartitionedTables, err := expandLogFolderSinkBigqueryOptionsUsePartitionedTables(original["use_partitioned_tables"], d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if val := reflect.ValueOf(transformedUsePartitionedTables); val.IsValid() && !tpgresource.IsEmptyValue(val) { | ||
| transformed["usePartitionedTables"] = transformedUsePartitionedTables | ||
| } | ||
|
|
||
| return transformed, nil | ||
| } | ||
|
|
||
| func expandLogFolderSinkBigqueryOptionsUsePartitionedTables(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
mmv1/third_party/tgc/tests/data/example_google_logging_folder_sink.json
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,50 @@ | ||
| [{ | ||
| "name": "//logging.googleapis.com/folders/{{.FolderID}}/sinks/tf-test-sink", | ||
| "asset_type": "logging.googleapis.com/LogSink", | ||
| "ancestry_path": "{{.Ancestry}}/folder/{{.FolderID}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://logging.googleapis.com/$discovery/rest", | ||
| "discovery_name": "LogSink", | ||
| "parent": "//cloudresourcemanager.googleapis.com/folders/{{.FolderID}}", | ||
| "data": { | ||
| "name": "tf-test-sink", | ||
| "destination": "storage.googleapis.com/tf-test-bucket-{{.Project.Number}}", | ||
| "filter": "severity >= ERROR", | ||
| "includeChildren": true, | ||
| "exclusions": [{ | ||
| "name": "exclude-gce-activity", | ||
| "description": "Exclude GCE activity logs.", | ||
| "filter": "logName:\"logs/compute.googleapis.com%2Factivity_log\"" | ||
| }], | ||
| "bigqueryOptions": { | ||
| "usePartitionedTables": true | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "name": "//storage.googleapis.com/tf-test-bucket-{{.Project.Number}}", | ||
| "asset_type": "storage.googleapis.com/Bucket", | ||
| "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/storage/v1/rest", | ||
| "discovery_name": "Bucket", | ||
| "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}", | ||
| "data": { | ||
| "iamConfiguration": { | ||
| "uniformBucketLevelAccess": { | ||
| "enabled": false | ||
| } | ||
| }, | ||
| "lifecycle": { | ||
| "rule": [] | ||
| }, | ||
| "location": "US", | ||
| "name": "tf-test-bucket-{{.Project.Number}}", | ||
| "project": "{{.Provider.project}}", | ||
| "storageClass": "STANDARD" | ||
| } | ||
| } | ||
| }] |
36 changes: 36 additions & 0 deletions
36
mmv1/third_party/tgc/tests/data/example_google_logging_folder_sink.tf
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,36 @@ | ||
| terraform { | ||
| required_providers { | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = ">= 4.54.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "google" { | ||
| project = "{{.Provider.project}}" | ||
| } | ||
|
|
||
| resource "google_storage_bucket" "test_bucket" { | ||
| name = "tf-test-bucket-{{.Project.Number}}" | ||
| location = "US" | ||
| project = "{{.Provider.project}}" | ||
| } | ||
|
|
||
| resource "google_logging_folder_sink" "test_sink" { | ||
| name = "tf-test-sink" | ||
| folder = "folders/{{.FolderID}}" | ||
| destination = "storage.googleapis.com/${google_storage_bucket.test_bucket.name}" | ||
| filter = "severity >= ERROR" | ||
| include_children = true | ||
|
|
||
| exclusions { | ||
| name = "exclude-gce-activity" | ||
| description = "Exclude GCE activity logs." | ||
| filter = "logName:\"logs/compute.googleapis.com%2Factivity_log\"" | ||
| } | ||
|
|
||
| bigquery_options { | ||
| use_partitioned_tables = true | ||
| } | ||
| } |
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.
There is no parent field inside data field