Skip to content

Commit b8b18ee

Browse files
tyh2333Philip Jonany
authored and
Philip Jonany
committed
Adding a new cloud logging resource LogScope to Terraform (GoogleCloudPlatform#11763)
1 parent 242827e commit b8b18ee

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

mmv1/products/logging/LogScope.yaml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
--- !ruby/object:Api::Resource
15+
name: 'LogScope'
16+
base_url: '{{parent}}/locations/{{location}}/logScopes'
17+
create_url: '{{parent}}/locations/{{location}}/logScopes?logScopeId={{name}}'
18+
self_link: '{{parent}}/locations/{{location}}/logScopes/{{name}}'
19+
import_format: ['{{%parent}}/locations/{{location}}/logScopes/{{name}}']
20+
update_verb: :PATCH
21+
update_mask: true
22+
references: !ruby/object:Api::Resource::ReferenceLinks
23+
guides:
24+
'Official Documentation': 'https://cloud.google.com/logging/docs/apis'
25+
api: 'https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.locations.logScopes'
26+
description: 'Describes a group of resources to read log entries from'
27+
examples:
28+
- !ruby/object:Provider::Terraform::Examples
29+
name: 'logging_log_scope_basic'
30+
primary_resource_id: 'logging_log_scope'
31+
vars:
32+
log_scope_name: 'my-log-scope'
33+
log_view_name_1: 'view1'
34+
log_view_name_2: 'view2'
35+
test_env_vars:
36+
project: :PROJECT_NAME
37+
custom_code: !ruby/object:Provider::Terraform::CustomCode
38+
encoder: templates/terraform/encoders/logging_log_scope.go.erb
39+
parameters:
40+
- !ruby/object:Api::Type::String
41+
name: parent
42+
description: The parent of the resource.
43+
url_param_only: true
44+
immutable: true
45+
default_from_api: true
46+
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
47+
- !ruby/object:Api::Type::String
48+
name: location
49+
description:
50+
'The location of the resource. The supported locations are: global,
51+
us-central1, us-east1, us-west1, asia-east1, europe-west1.'
52+
url_param_only: true
53+
immutable: true
54+
default_from_api: true
55+
properties:
56+
- !ruby/object:Api::Type::String
57+
name: name
58+
description:
59+
'The resource name of the log scope. For example:
60+
\`projects/my-project/locations/global/logScopes/my-log-scope\`'
61+
required: true
62+
immutable: true
63+
ignore_read: true
64+
diff_suppress_func: 'tpgresource.CompareResourceNames'
65+
- !ruby/object:Api::Type::Array
66+
# This has to be camelCase, even though it's snakeCase in proto definiation.
67+
name: resourceNames
68+
item_type: Api::Type::String
69+
required: true
70+
description:
71+
'Names of one or more parent resources : * \`projects/[PROJECT_ID]\`
72+
May alternatively be one or more views :
73+
* \`projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]\`
74+
A log scope can include a maximum of 50 projects and a maximum of 100 resources in total.'
75+
- !ruby/object:Api::Type::String
76+
name: description
77+
description: Describes this log scopes.
78+
- !ruby/object:Api::Type::String
79+
name: createTime
80+
description: Output only. The creation timestamp of the log scopes.
81+
output: true
82+
- !ruby/object:Api::Type::String
83+
name: updateTime
84+
description: Output only. The last update timestamp of the log scopes.
85+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<%- # the license inside this block applies to this file
2+
# Copyright 2023 Google Inc.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
-%>
15+
// Extract any empty fields from the bucket field.
16+
// Extract parent, location from name
17+
parent := d.Get("parent").(string)
18+
name := d.Get("name").(string)
19+
parent, err := tpgresource.ExtractFieldByPattern("parent", parent, name, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*")
20+
if err != nil {
21+
return nil, fmt.Errorf("error extracting parent field: %s", err)
22+
}
23+
location := d.Get("location").(string)
24+
location, err = tpgresource.ExtractFieldByPattern("location", location, name, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/logScopes/.*")
25+
if err != nil {
26+
return nil, fmt.Errorf("error extracting location field: %s", err)
27+
}
28+
// Set parent to the extracted value.
29+
d.Set("parent", parent)
30+
// Set all the other fields to their short forms before forming url and setting ID.
31+
name = tpgresource.GetResourceNameFromSelfLink(name)
32+
d.Set("location", location)
33+
d.Set("name", name)
34+
return obj, nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "google_logging_log_scope" "<%= ctx[:primary_resource_id] %>" {
2+
parent = "projects/<%= ctx[:test_env_vars]['project'] %>"
3+
location = "global"
4+
name = "projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/logScopes/<%= ctx[:vars]['log_scope_name'] %>"
5+
resource_names = [
6+
"projects/<%= ctx[:test_env_vars]['project'] %>",
7+
"projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/buckets/_Default/views/<%= ctx[:vars]['log_view_name_1'] %>",
8+
"projects/<%= ctx[:test_env_vars]['project'] %>/locations/global/buckets/_Default/views/<%= ctx[:vars]['log_view_name_2'] %>"
9+
]
10+
description = "A log scope configured with Terraform"
11+
}

0 commit comments

Comments
 (0)