Skip to content

Commit 581b00f

Browse files
Add google_logging_organization_sink to TGC tfplan2cai (#15522)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent fb4f6bc commit 581b00f

File tree

5 files changed

+386
-0
lines changed

5 files changed

+386
-0
lines changed

mmv1/provider/terraform_tgc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ func (tgc TerraformGoogleConversion) CopyCommonFiles(outputFolder string, genera
435435
"converters/google/resources/services/logging/logging_billing_account_bucket_config.go": "third_party/tgc/services/logging/logging_billing_account_bucket_config.go",
436436
"converters/google/resources/services/appengine/appengine_standard_version.go": "third_party/tgc/services/appengine/appengine_standard_version.go",
437437
"converters/google/resources/services/logging/logging_project_sink.go": "third_party/tgc/services/logging/logging_project_sink.go",
438+
"converters/google/resources/services/logging/logging_organization_sink.go": "third_party/tgc/services/logging/logging_organization_sink.go",
438439
}
439440
tgc.CopyFileList(outputFolder, resourceConverters)
440441
}

mmv1/third_party/tgc/resource_converters.go.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func ResourceConverters() map[string][]cai.ResourceConverter {
139139
"google_logging_project_bucket_config": {logging.ResourceConverterLogProjectBucket()},
140140
"google_logging_billing_account_bucket_config": {logging.ResourceConverterLogBillingAccountBucket()},
141141
"google_logging_project_sink": {logging.ResourceConverterLogProjectSink()},
142+
"google_logging_organization_sink": {logging.ResourceConverterLogOrganizationSink()},
142143
"google_cloud_tasks_queue": {cloudtasks.ResourceConverterCloudTasksQueue()},
143144
"google_pubsub_topic": {pubsub.ResourceConverterPubsubTopic()},
144145
"google_kms_crypto_key": {kms.ResourceConverterKMSCryptoKey()},
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
package logging
2+
3+
import (
4+
"reflect"
5+
6+
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai"
7+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
8+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
9+
)
10+
11+
func ResourceConverterLogOrganizationSink() cai.ResourceConverter {
12+
return cai.ResourceConverter{
13+
AssetType: logSinkAssetType,
14+
Convert: GetLogOrganizationSinkCaiObject,
15+
}
16+
}
17+
18+
func GetLogOrganizationSinkCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
19+
name, err := cai.AssetName(d, config, "//logging.googleapis.com/organizations/{{org_id}}/sinks/{{name}}")
20+
if err != nil {
21+
return []cai.Asset{}, err
22+
}
23+
obj, err := GetLogOrganizationSinkApiObject(d, config)
24+
if err != nil {
25+
return []cai.Asset{}, err
26+
}
27+
return []cai.Asset{{
28+
Name: name,
29+
Type: logSinkAssetType,
30+
Resource: &cai.AssetResource{
31+
Version: "v2",
32+
DiscoveryDocumentURI: "https://logging.googleapis.com/$discovery/rest",
33+
DiscoveryName: "LogSink",
34+
Data: obj,
35+
},
36+
}}, nil
37+
}
38+
39+
func GetLogOrganizationSinkApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
40+
obj := make(map[string]interface{})
41+
42+
nameProp, err := expandLogOrganizationSinkName(d.Get("name"), d, config)
43+
if err != nil {
44+
return nil, err
45+
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
46+
obj["name"] = nameProp
47+
}
48+
49+
destinationProp, err := expandLogOrganizationSinkDestination(d.Get("destination"), d, config)
50+
if err != nil {
51+
return nil, err
52+
} else if v, ok := d.GetOkExists("destination"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationProp)) && (ok || !reflect.DeepEqual(v, destinationProp)) {
53+
obj["destination"] = destinationProp
54+
}
55+
56+
filterProp, err := expandLogOrganizationSinkFilter(d.Get("filter"), d, config)
57+
if err != nil {
58+
return nil, err
59+
} else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) {
60+
obj["filter"] = filterProp
61+
}
62+
63+
descriptionProp, err := expandLogOrganizationSinkDescription(d.Get("description"), d, config)
64+
if err != nil {
65+
return nil, err
66+
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
67+
obj["description"] = descriptionProp
68+
}
69+
70+
disabledProp, err := expandLogOrganizationSinkDisabled(d.Get("disabled"), d, config)
71+
if err != nil {
72+
return nil, err
73+
} else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) {
74+
obj["disabled"] = disabledProp
75+
}
76+
77+
exclusionsProp, err := expandLogOrganizationSinkExclusions(d.Get("exclusions"), d, config)
78+
if err != nil {
79+
return nil, err
80+
} else if v, ok := d.GetOkExists("exclusions"); !tpgresource.IsEmptyValue(reflect.ValueOf(exclusionsProp)) && (ok || !reflect.DeepEqual(v, exclusionsProp)) {
81+
obj["exclusions"] = exclusionsProp
82+
}
83+
84+
includeChildrenProp, err := expandLogOrganizationSinkIncludeChildren(d.Get("include_children"), d, config)
85+
if err != nil {
86+
return nil, err
87+
} else if v, ok := d.GetOkExists("include_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(includeChildrenProp)) && (ok || !reflect.DeepEqual(v, includeChildrenProp)) {
88+
obj["includeChildren"] = includeChildrenProp
89+
}
90+
91+
interceptChildrenProp, err := expandLogOrganizationSinkInterceptChildren(d.Get("intercept_children"), d, config)
92+
if err != nil {
93+
return nil, err
94+
} else if v, ok := d.GetOkExists("intercept_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(interceptChildrenProp)) && (ok || !reflect.DeepEqual(v, interceptChildrenProp)) {
95+
obj["interceptChildren"] = interceptChildrenProp
96+
}
97+
98+
bigqueryOptionsProp, err := expandLogOrganizationSinkBigqueryOptions(d.Get("bigquery_options"), d, config)
99+
if err != nil {
100+
return nil, err
101+
} else if v, ok := d.GetOkExists("bigquery_options"); !tpgresource.IsEmptyValue(reflect.ValueOf(bigqueryOptionsProp)) && (ok || !reflect.DeepEqual(v, bigqueryOptionsProp)) {
102+
obj["bigqueryOptions"] = bigqueryOptionsProp
103+
}
104+
105+
return obj, nil
106+
}
107+
108+
func expandLogOrganizationSinkName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
109+
return v, nil
110+
}
111+
112+
func expandLogOrganizationSinkDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
113+
return v, nil
114+
}
115+
116+
func expandLogOrganizationSinkFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
117+
return v, nil
118+
}
119+
120+
func expandLogOrganizationSinkDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
121+
return v, nil
122+
}
123+
124+
func expandLogOrganizationSinkDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
125+
return v, nil
126+
}
127+
128+
func expandLogOrganizationSinkIncludeChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
129+
return v, nil
130+
}
131+
132+
func expandLogOrganizationSinkInterceptChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
133+
return v, nil
134+
}
135+
136+
func expandLogOrganizationSinkExclusions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
137+
l, ok := v.([]interface{})
138+
if !ok {
139+
return nil, nil
140+
}
141+
req := make([]interface{}, 0, len(l))
142+
for _, raw := range l {
143+
if raw == nil {
144+
continue
145+
}
146+
original := raw.(map[string]interface{})
147+
transformed := make(map[string]interface{})
148+
149+
transformedName, err := expandLogOrganizationSinkExclusionsName(original["name"], d, config)
150+
if err != nil {
151+
return nil, err
152+
} else if val := reflect.ValueOf(transformedName); val.IsValid() && !tpgresource.IsEmptyValue(val) {
153+
transformed["name"] = transformedName
154+
}
155+
156+
transformedDescription, err := expandLogOrganizationSinkExclusionsDescription(original["description"], d, config)
157+
if err != nil {
158+
return nil, err
159+
} else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !tpgresource.IsEmptyValue(val) {
160+
transformed["description"] = transformedDescription
161+
}
162+
163+
transformedFilter, err := expandLogOrganizationSinkExclusionsFilter(original["filter"], d, config)
164+
if err != nil {
165+
return nil, err
166+
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) {
167+
transformed["filter"] = transformedFilter
168+
}
169+
170+
transformedDisabled, err := expandLogOrganizationSinkExclusionsDisabled(original["disabled"], d, config)
171+
if err != nil {
172+
return nil, err
173+
} else if val := reflect.ValueOf(transformedDisabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
174+
transformed["disabled"] = transformedDisabled
175+
}
176+
177+
req = append(req, transformed)
178+
}
179+
180+
return req, nil
181+
}
182+
183+
func expandLogOrganizationSinkExclusionsName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
184+
return v, nil
185+
}
186+
187+
func expandLogOrganizationSinkExclusionsDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
188+
return v, nil
189+
}
190+
191+
func expandLogOrganizationSinkExclusionsFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
192+
return v, nil
193+
}
194+
195+
func expandLogOrganizationSinkExclusionsDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
196+
return v, nil
197+
}
198+
199+
func expandLogOrganizationSinkBigqueryOptions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
200+
l := v.([]interface{})
201+
if len(l) == 0 || l[0] == nil {
202+
return nil, nil
203+
}
204+
raw := l[0]
205+
original := raw.(map[string]interface{})
206+
transformed := make(map[string]interface{})
207+
208+
transformedUsePartitionedTables, err := expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(original["use_partitioned_tables"], d, config)
209+
if err != nil {
210+
return nil, err
211+
} else if val := reflect.ValueOf(transformedUsePartitionedTables); val.IsValid() && !tpgresource.IsEmptyValue(val) {
212+
transformed["usePartitionedTables"] = transformedUsePartitionedTables
213+
}
214+
215+
return transformed, nil
216+
}
217+
218+
func expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
219+
return v, nil
220+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
[
2+
{
3+
"name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink",
4+
"asset_type": "logging.googleapis.com/LogSink",
5+
"ancestry_path": "organizations/{{.OrgID}}",
6+
"resource": {
7+
"version": "v2",
8+
"discovery_document_uri": "https://logging.googleapis.com/$discovery/rest",
9+
"discovery_name": "LogSink",
10+
"parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}",
11+
"data": {
12+
"destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset",
13+
"exclusions": [
14+
{
15+
"description": "Exclude all GCE instance logs",
16+
"disabled": true,
17+
"filter": "resource.type = gce_instance",
18+
"name": "gg-asset-88093-71a3-exclusion"
19+
}
20+
],
21+
"name": "gg-asset-88093-71a3-sink"
22+
}
23+
},
24+
"ancestors": [
25+
"organizations/{{.OrgID}}"
26+
]
27+
},
28+
{
29+
"name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink-with-children",
30+
"asset_type": "logging.googleapis.com/LogSink",
31+
"ancestry_path": "organizations/{{.OrgID}}",
32+
"resource": {
33+
"version": "v2",
34+
"discovery_document_uri": "https://logging.googleapis.com/$discovery/rest",
35+
"discovery_name": "LogSink",
36+
"parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}",
37+
"data": {
38+
"destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset",
39+
"exclusions": [
40+
{
41+
"description": "Exclude all GCE instance logs",
42+
"disabled": true,
43+
"filter": "resource.type = gce_instance",
44+
"name": "gg-asset-88093-71a3-exclusion"
45+
}
46+
],
47+
"includeChildren": true,
48+
"name": "gg-asset-88093-71a3-sink-with-children"
49+
}
50+
},
51+
"ancestors": [
52+
"organizations/{{.OrgID}}"
53+
]
54+
},
55+
{
56+
"name": "//logging.googleapis.com/organizations/{{.OrgID}}/sinks/gg-asset-88093-71a3-sink-with-intercept",
57+
"asset_type": "logging.googleapis.com/LogSink",
58+
"ancestry_path": "organizations/{{.OrgID}}",
59+
"resource": {
60+
"version": "v2",
61+
"discovery_document_uri": "https://logging.googleapis.com/$discovery/rest",
62+
"discovery_name": "LogSink",
63+
"parent": "//cloudresourcemanager.googleapis.com/organizations/{{.OrgID}}",
64+
"data": {
65+
"destination": "bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset",
66+
"exclusions": [
67+
{
68+
"description": "Exclude all GCE instance logs",
69+
"disabled": true,
70+
"filter": "resource.type = gce_instance",
71+
"name": "gg-asset-88093-71a3-exclusion"
72+
}
73+
],
74+
"interceptChildren": true,
75+
"name": "gg-asset-88093-71a3-sink-with-intercept"
76+
}
77+
},
78+
"ancestors": [
79+
"organizations/{{.OrgID}}"
80+
]
81+
},
82+
{
83+
"name": "//bigquery.googleapis.com/projects/{{.Provider.project}}/datasets/my_dataset",
84+
"asset_type": "bigquery.googleapis.com/Dataset",
85+
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
86+
"resource": {
87+
"version": "v2",
88+
"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/bigquery/v2/rest",
89+
"discovery_name": "Dataset",
90+
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
91+
"data": {
92+
"datasetReference": {
93+
"datasetId": "my_dataset"
94+
},
95+
"friendlyName": "",
96+
"labels": {
97+
"goog-terraform-provisioned": "true"
98+
},
99+
"location": "US"
100+
}
101+
},
102+
"iam_policy": {
103+
"bindings": [
104+
{
105+
"role": "roles/bigquery.dataEditor",
106+
"members": [
107+
""
108+
]
109+
}
110+
]
111+
}
112+
}
113+
]

0 commit comments

Comments
 (0)