Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
209 changes: 209 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,209 @@
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?version=v2",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ?version=v2

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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
Copy Markdown
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
Copy Markdown
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.

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 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
}
86 changes: 86 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,86 @@
[
{
"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": "//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": [
""
]
}
]
}
}
]
38 changes: 38 additions & 0 deletions mmv1/third_party/tgc/tests/data/logging_organization_sink.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
resource "google_bigquery_dataset" "my_dataset" {
project = "{{.Provider.project}}"
dataset_id = "my_dataset"
location = "US"
}

resource "google_logging_organization_sink" "my_sink" {
name = "gg-asset-88093-71a3-sink"
org_id = "{{.OrgID}}"
destination = "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/${google_bigquery_dataset.my_dataset.dataset_id}"
include_children = false
exclusions {
name = "gg-asset-88093-71a3-exclusion"
description = "Exclude all GCE instance logs"
filter = "resource.type = gce_instance"
disabled = true
}
}

resource "google_bigquery_dataset_iam_member" "my_iam" {
project = "{{.Provider.project}}"
dataset_id = google_bigquery_dataset.my_dataset.dataset_id
role = "roles/bigquery.dataEditor"
member = google_logging_organization_sink.my_sink.writer_identity
}

resource "google_logging_organization_sink" "my_sink_with_children" {
name = "gg-asset-88093-71a3-sink-with-children"
org_id = "{{.OrgID}}"
destination = "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/${google_bigquery_dataset.my_dataset.dataset_id}"
include_children = true
exclusions {
name = "gg-asset-88093-71a3-exclusion"
description = "Exclude all GCE instance logs"
filter = "resource.type = gce_instance"
disabled = true
}
}
Loading