Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmv1/provider/terraform_tgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func (tgc TerraformGoogleConversion) CopyCommonFiles(outputFolder string, genera
"converters/google/resources/services/logging/logging_billing_account_bucket_config.go": "third_party/tgc/services/logging/logging_billing_account_bucket_config.go",
"converters/google/resources/services/appengine/appengine_standard_version.go": "third_party/tgc/services/appengine/appengine_standard_version.go",
"converters/google/resources/services/logging/logging_project_sink.go": "third_party/tgc/services/logging/logging_project_sink.go",
"converters/google/resources/services/logging/logging_organization_sink.go": "third_party/tgc/services/logging/logging_organization_sink.go",
}
tgc.CopyFileList(outputFolder, resourceConverters)
}
Expand Down
1 change: 1 addition & 0 deletions mmv1/third_party/tgc/resource_converters.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func ResourceConverters() map[string][]cai.ResourceConverter {
"google_logging_project_bucket_config": {logging.ResourceConverterLogProjectBucket()},
"google_logging_billing_account_bucket_config": {logging.ResourceConverterLogBillingAccountBucket()},
"google_logging_project_sink": {logging.ResourceConverterLogProjectSink()},
"google_logging_organization_sink": {logging.ResourceConverterLogOrganizationSink()},
"google_cloud_tasks_queue": {cloudtasks.ResourceConverterCloudTasksQueue()},
"google_pubsub_topic": {pubsub.ResourceConverterPubsubTopic()},
"google_kms_crypto_key": {kms.ResourceConverterKMSCryptoKey()},
Expand Down
220 changes: 220 additions & 0 deletions mmv1/third_party/tgc/services/logging/logging_organization_sink.go
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
}

Copy link
Owner

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.

Copy link
Author

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_children and added a test case to validate it.

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 mmv1/third_party/tgc/tests/data/logging_organization_sink.json
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": [
""
]
}
]
}
}
]
Loading
Loading