Skip to content

Commit 705d5ff

Browse files
Add Observability TraceScope resource and tests (#15304)
Co-authored-by: Shuya Ma <[email protected]>
1 parent 81b088a commit 705d5ff

File tree

6 files changed

+240
-0
lines changed

6 files changed

+240
-0
lines changed
Lines changed: 85 additions & 0 deletions
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+
---
15+
name: TraceScope
16+
min_version: 'beta'
17+
description: A trace scope is a collection of resources whose traces are queried together
18+
base_url: projects/{{project}}/locations/{{location}}/traceScopes
19+
update_mask: true
20+
self_link: projects/{{project}}/locations/{{location}}/traceScopes/{{trace_scope_id}}
21+
create_url: projects/{{project}}/locations/{{location}}/traceScopes?traceScopeId={{trace_scope_id}}
22+
update_verb: PATCH
23+
id_format: projects/{{project}}/locations/{{location}}/traceScopes/{{trace_scope_id}}
24+
import_format:
25+
- projects/{{project}}/locations/{{location}}/traceScopes/{{trace_scope_id}}
26+
examples:
27+
- name: observability_trace_scope_basic
28+
primary_resource_id: observability_trace_scope
29+
min_version: beta
30+
vars:
31+
trace_scope_id: test-scope
32+
test_env_vars:
33+
org_id: 'ORG_ID'
34+
timeouts:
35+
insert_minutes: 20
36+
update_minutes: 20
37+
delete_minutes: 20
38+
parameters:
39+
- name: location
40+
type: String
41+
description: GCP region the TraceScope is stored in. Only `global` is supported.
42+
immutable: true
43+
url_param_only: true
44+
required: true
45+
- name: traceScopeId
46+
type: String
47+
description: A client-assigned identifier for the trace scope.
48+
immutable: true
49+
url_param_only: true
50+
required: true
51+
properties:
52+
- name: createTime
53+
type: String
54+
description: The creation timestamp of the trace scope.
55+
output: true
56+
- name: description
57+
type: String
58+
description: |-
59+
Describes this trace scope.
60+
61+
The maximum length of the description is 8000 characters.
62+
- name: name
63+
type: String
64+
description: |-
65+
Identifier. The resource name of the trace scope.
66+
67+
For example:
68+
69+
projects/my-project/locations/global/traceScopes/my-trace-scope
70+
output: true
71+
- name: resourceNames
72+
type: Array
73+
description: |-
74+
Names of the projects that are included in this trace scope.
75+
76+
* `projects/[PROJECT_ID]`
77+
78+
A trace scope can include a maximum of 20 projects.
79+
required: true
80+
item_type:
81+
type: String
82+
- name: updateTime
83+
type: String
84+
description: The last update timestamp of the trace scope.
85+
output: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
---
15+
name: Observability
16+
display_name: Observability
17+
scopes:
18+
- https://www.googleapis.com/auth/cloud-platform
19+
versions:
20+
- base_url: https://observability.googleapis.com/v1/
21+
name: 'ga'
22+
- base_url: https://observability.googleapis.com/v1/
23+
name: 'beta'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
resource "google_observability_trace_scope" "{{$.PrimaryResourceId}}" {
2+
depends_on = [google_project.project-2]
3+
provider = google-beta
4+
trace_scope_id = "{{index $.Vars "trace_scope_id"}}"
5+
location = "global"
6+
resource_names = [
7+
"projects/${data.google_project.project.project_id}",
8+
"projects/${google_project.project-2.project_id}",
9+
]
10+
description = "A trace scope configured with Terraform"
11+
}
12+
13+
data "google_project" "project" {
14+
provider = google-beta
15+
}
16+
17+
resource "google_project" "project-2" {
18+
provider = google-beta
19+
project_id = "tf-test%{random_suffix}"
20+
name = "tf-test%{random_suffix}"
21+
org_id = "{{index $.TestEnvVars "org_id"}}"
22+
deletion_policy = "DELETE"
23+
}

mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ var ServicesListBeta = mapOf(
611611
"displayName" to "Notebooks",
612612
"path" to "./google-beta/services/notebooks"
613613
),
614+
"observability" to mapOf(
615+
"name" to "observability",
616+
"displayName" to "Observability",
617+
"path" to "./google-beta/services/observability"
618+
),
614619
"oracledatabase" to mapOf(
615620
"name" to "oracledatabase",
616621
"displayName" to "OracleDatabase",

mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ var ServicesListGa = mapOf(
606606
"displayName" to "Notebooks",
607607
"path" to "./google/services/notebooks"
608608
),
609+
"observability" to mapOf(
610+
"name" to "observability",
611+
"displayName" to "Observability",
612+
"path" to "./google/services/observability"
613+
),
609614
"oracledatabase" to mapOf(
610615
"name" to "oracledatabase",
611616
"displayName" to "OracleDatabase",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package observability_test
2+
3+
import (
4+
{{ if ne $.TargetVersionName `ga` -}}
5+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
6+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
7+
"github.com/hashicorp/terraform-provider-google/google/envvar"
8+
{{- end }}
9+
"github.com/hashicorp/terraform-provider-google/google/acctest"
10+
11+
"testing"
12+
)
13+
14+
func TestAccObservabilityTraceScope_update(t *testing.T) {
15+
{{ if ne $.TargetVersionName `ga` -}}
16+
t.Parallel()
17+
18+
context := map[string]interface{}{
19+
"org_id": envvar.GetTestOrgFromEnv(t),
20+
"random_suffix": acctest.RandString(t, 10),
21+
}
22+
23+
acctest.VcrTest(t, resource.TestCase{
24+
PreCheck: func() { acctest.AccTestPreCheck(t) },
25+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
26+
Steps: []resource.TestStep{
27+
{
28+
Config: testAccObservabilityTraceScope_basic(context),
29+
},
30+
{
31+
ResourceName: "google_observability_trace_scope.observability_trace_scope",
32+
ImportState: true,
33+
ImportStateVerify: true,
34+
ImportStateVerifyIgnore: []string{"location", "trace_scope_id"},
35+
},
36+
{
37+
Config: testAccObservabilityTraceScope_update(context),
38+
ConfigPlanChecks: resource.ConfigPlanChecks{
39+
PreApply: []plancheck.PlanCheck{
40+
plancheck.ExpectResourceAction("google_observability_trace_scope.observability_trace_scope", plancheck.ResourceActionUpdate),
41+
},
42+
},
43+
},
44+
{
45+
ResourceName: "google_observability_trace_scope.observability_trace_scope",
46+
ImportState: true,
47+
ImportStateVerify: true,
48+
ImportStateVerifyIgnore: []string{"location", "trace_scope_id"},
49+
},
50+
},
51+
})
52+
{{- end }}
53+
}
54+
55+
func testAccObservabilityTraceScope_basic(context map[string]interface{}) string {
56+
return acctest.Nprintf(`
57+
resource "google_observability_trace_scope" "observability_trace_scope" {
58+
provider = google-beta
59+
trace_scope_id = "tf-test-test-scope%{random_suffix}"
60+
location = "global"
61+
resource_names = [
62+
"projects/${data.google_project.project.project_id}",
63+
]
64+
description = "A trace scope configured with Terraform"
65+
}
66+
67+
data "google_project" "project" {
68+
provider = google-beta
69+
}
70+
`, context)
71+
}
72+
73+
func testAccObservabilityTraceScope_update(context map[string]interface{}) string {
74+
return acctest.Nprintf(`
75+
resource "google_observability_trace_scope" "observability_trace_scope" {
76+
depends_on = [google_project.project-2]
77+
provider = google-beta
78+
trace_scope_id = "tf-test-test-scope%{random_suffix}"
79+
location = "global"
80+
resource_names = [
81+
"projects/${data.google_project.project.project_id}",
82+
"projects/${google_project.project-2.project_id}",
83+
]
84+
description = "A new description"
85+
}
86+
87+
data "google_project" "project" {
88+
provider = google-beta
89+
}
90+
91+
resource "google_project" "project-2" {
92+
provider = google-beta
93+
project_id = "tf-test%{random_suffix}"
94+
name = "tf-test%{random_suffix}"
95+
org_id = "%{org_id}"
96+
deletion_policy = "DELETE"
97+
}
98+
`, context)
99+
}

0 commit comments

Comments
 (0)