forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add converter for logging_organization_sink #3
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
3
commits into
main
Choose a base branch
from
add-logging-organization-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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
220 changes: 220 additions & 0 deletions
220
mmv1/third_party/tgc/services/logging/logging_organization_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,220 @@ | ||
| package logging | ||
|
|
||
| import ( | ||
| "reflect" | ||
|
|
||
| "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" | ||
| ) | ||
|
|
||
| func ResourceConverterLogOrganizationSink() cai.ResourceConverter { | ||
| return cai.ResourceConverter{ | ||
| AssetType: logSinkAssetType, | ||
| Convert: GetLogOrganizationSinkCaiObject, | ||
| } | ||
| } | ||
|
|
||
| func GetLogOrganizationSinkCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { | ||
| name, err := cai.AssetName(d, config, "//logging.googleapis.com/organizations/{{org_id}}/sinks/{{name}}") | ||
| if err != nil { | ||
| return []cai.Asset{}, err | ||
| } | ||
| obj, err := GetLogOrganizationSinkApiObject(d, config) | ||
| if err != nil { | ||
| return []cai.Asset{}, err | ||
| } | ||
| return []cai.Asset{{ | ||
| Name: name, | ||
| Type: logSinkAssetType, | ||
| Resource: &cai.AssetResource{ | ||
| Version: "v2", | ||
| DiscoveryDocumentURI: "https://logging.googleapis.com/$discovery/rest", | ||
| DiscoveryName: "LogSink", | ||
| Data: obj, | ||
| }, | ||
| }}, nil | ||
| } | ||
|
|
||
| func GetLogOrganizationSinkApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { | ||
| obj := make(map[string]interface{}) | ||
|
|
||
| nameProp, err := expandLogOrganizationSinkName(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 := expandLogOrganizationSinkDestination(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 := expandLogOrganizationSinkFilter(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 := expandLogOrganizationSinkDescription(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 := expandLogOrganizationSinkDisabled(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 := expandLogOrganizationSinkExclusions(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 := expandLogOrganizationSinkIncludeChildren(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 | ||
| } | ||
|
|
||
| interceptChildrenProp, err := expandLogOrganizationSinkInterceptChildren(d.Get("intercept_children"), d, config) | ||
| if err != nil { | ||
| return nil, err | ||
| } else if v, ok := d.GetOkExists("intercept_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(interceptChildrenProp)) && (ok || !reflect.DeepEqual(v, interceptChildrenProp)) { | ||
| obj["interceptChildren"] = interceptChildrenProp | ||
| } | ||
|
|
||
| bigqueryOptionsProp, err := expandLogOrganizationSinkBigqueryOptions(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 | ||
| } | ||
|
|
||
| return obj, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkIncludeChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkInterceptChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkExclusions(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 := expandLogOrganizationSinkExclusionsName(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 := expandLogOrganizationSinkExclusionsDescription(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 := expandLogOrganizationSinkExclusionsFilter(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 := expandLogOrganizationSinkExclusionsDisabled(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 expandLogOrganizationSinkExclusionsName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkExclusionsDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkExclusionsFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkExclusionsDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
|
|
||
| func expandLogOrganizationSinkBigqueryOptions(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 := expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(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 expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { | ||
| return v, nil | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
mmv1/third_party/tgc/tests/data/logging_organization_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,113 @@ | ||
| [ | ||
| { | ||
| "name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink", | ||
| "asset_type": "logging.googleapis.com/LogSink", | ||
| "ancestry_path": "organizations/{{.OrgID}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://logging.googleapis.com/$discovery/rest", | ||
| "discovery_name": "LogSink", | ||
| "parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}", | ||
| "data": { | ||
| "destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset", | ||
| "exclusions": [ | ||
| { | ||
| "description": "Exclude all GCE instance logs", | ||
| "disabled": true, | ||
| "filter": "resource.type = gce_instance", | ||
| "name": "gg-asset-88093-71a3-exclusion" | ||
| } | ||
| ], | ||
| "name": "gg-asset-88093-71a3-sink" | ||
| } | ||
| }, | ||
| "ancestors": [ | ||
| "organizations/{{.OrgID}}" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink-with-children", | ||
| "asset_type": "logging.googleapis.com/LogSink", | ||
| "ancestry_path": "organizations/{{.OrgID}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://logging.googleapis.com/$discovery/rest", | ||
| "discovery_name": "LogSink", | ||
| "parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}", | ||
| "data": { | ||
| "destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset", | ||
| "exclusions": [ | ||
| { | ||
| "description": "Exclude all GCE instance logs", | ||
| "disabled": true, | ||
| "filter": "resource.type = gce_instance", | ||
| "name": "gg-asset-88093-71a3-exclusion" | ||
| } | ||
| ], | ||
| "includeChildren": true, | ||
| "name": "gg-asset-88093-71a3-sink-with-children" | ||
| } | ||
| }, | ||
| "ancestors": [ | ||
| "organizations/{{.OrgID}}" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink-with-intercept", | ||
| "asset_type": "logging.googleapis.com/LogSink", | ||
| "ancestry_path": "organizations/{{.OrgID}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://logging.googleapis.com/$discovery/rest", | ||
| "discovery_name": "LogSink", | ||
| "parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}", | ||
| "data": { | ||
| "destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset", | ||
| "exclusions": [ | ||
| { | ||
| "description": "Exclude all GCE instance logs", | ||
| "disabled": true, | ||
| "filter": "resource.type = gce_instance", | ||
| "name": "gg-asset-88093-71a3-exclusion" | ||
| } | ||
| ], | ||
| "interceptChildren": true, | ||
| "name": "gg-asset-88093-71a3-sink-with-intercept" | ||
| } | ||
| }, | ||
| "ancestors": [ | ||
| "organizations/{{.OrgID}}" | ||
| ] | ||
| }, | ||
| { | ||
| "name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset", | ||
| "asset_type": "bigquery.googleapis.com/Dataset", | ||
| "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}", | ||
| "resource": { | ||
| "version": "v2", | ||
| "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest", | ||
| "discovery_name": "Dataset", | ||
| "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}", | ||
| "data": { | ||
| "datasetReference": { | ||
| "datasetId": "my_dataset" | ||
| }, | ||
| "friendlyName": "", | ||
| "labels": { | ||
| "goog-terraform-provisioned": "true" | ||
| }, | ||
| "location": "US" | ||
| } | ||
| }, | ||
| "iam_policy": { | ||
| "bindings": [ | ||
| { | ||
| "role": "roles/bigquery.dataEditor", | ||
| "members": [ | ||
| "" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] |
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.
Add intercept_children as well.
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.
Done. I've added support for
intercept_childrenand added a test case to validate it.