-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add Observability Project Settings Resource #16532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
melinath
merged 32 commits into
GoogleCloudPlatform:main
from
leowonderful:observability-project-settings-resource
Mar 3, 2026
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
22a3f54
Add datasource for observability project settings
leowonderful d880a29
add required wait to test
leowonderful 0e7dea0
remove retry logic from datasource
leowonderful 0d4da0b
reflect beta, not ga
leowonderful 5cb710d
Add Observability Project Settings resource
leowonderful 4f4eefc
reflect beta, not ga
leowonderful ba961ee
make tests less flaky
leowonderful 6560568
fix example tf.tmpl
leowonderful 0f6adb4
override autogen code
leowonderful 834894a
Add beta version guards
leowonderful b996f5c
Handwritten docs for the datasource
leowonderful 3fdd5f5
run `gofmt` on the templates
leowonderful 7c775da
format yaml correctly
leowonderful 6c3cf88
Add missing version guard
leowonderful acb6c75
eof newlife for yaml
leowonderful 0549bca
Add REST API reference to handwritten datasource docs
leowonderful 3ee5e00
just use a simple pre_* function
leowonderful 5033c12
simplify datasource
leowonderful 0771428
doc linkback
leowonderful 39fc344
make docs reflect beta
leowonderful 20f89a8
fmt fix
leowonderful c88c65d
put import block into version guard
leowonderful de66594
Reduce hardcoding to make datasource more robust
leowonderful c5f79da
Make datasource tests more durable, and also allow passing empty stri…
leowonderful 9c66aa6
Simplify pre_* and add new guide to datasource documentation
leowonderful a99c13a
Add back GetRawConfig :|
leowonderful e4e896d
Move tests, and use `update_mask` to get rid of the pre_update=
leowonderful 5e4e5f4
yaml fmt
leowonderful d6211ec
Merge branch 'main' into observability-project-settings-resource
leowonderful 11d9daa
Fix "too many arguments" by custom defining Wait operation
leowonderful ff4dc7c
remove custom operation and fix OrganizationSettings yaml
leowonderful 4873a9e
rerun CI
leowonderful File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # Copyright 2026 Google Inc. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| --- | ||
| name: 'ProjectSettings' | ||
| description: Manages Cloud Observability settings for a project. | ||
| min_version: 'beta' | ||
| base_url: 'projects/{{project}}/locations/{{location}}/settings' | ||
| self_link: 'projects/{{project}}/locations/{{location}}/settings' | ||
|
|
||
| create_url: 'projects/{{project}}/locations/{{location}}/settings' | ||
| create_verb: 'PATCH' | ||
| update_url: 'projects/{{project}}/locations/{{location}}/settings' | ||
| update_verb: 'PATCH' | ||
| import_format: | ||
| - "projects/{{project}}/locations/{{location}}/settings" | ||
| exclude_delete: true | ||
| autogen_async: true | ||
| update_mask: true | ||
|
|
||
| custom_code: | ||
| pre_create: templates/terraform/pre_create/observability_project_settings.go.tmpl | ||
|
|
||
| async: | ||
| operation: | ||
| timeouts: | ||
| insert_minutes: 10 | ||
| update_minutes: 10 | ||
| base_url: '{{op_id}}' | ||
| result: | ||
| resource_inside_response: true | ||
|
|
||
| examples: | ||
| - name: "observability_project_settings_basic" | ||
| config_path: "templates/terraform/examples/observability_project_settings_basic.tf.tmpl" | ||
| primary_resource_id: "primary" | ||
| external_providers: ["time"] | ||
| vars: | ||
| location: "us" | ||
| kms_key_name: "example-key" | ||
| test_env_vars: | ||
| project_name: 'PROJECT_NAME' | ||
| org_id: 'ORG_ID' | ||
| billing_account: 'BILLING_ACCOUNT' | ||
| test_vars_overrides: | ||
| kms_key_name: 'acctest.BootstrapKMSKeyInLocation(t, "us").CryptoKey.Name' | ||
| - name: "observability_project_settings_basic_global" | ||
| config_path: "templates/terraform/examples/observability_project_settings_basic_global.tf.tmpl" | ||
| primary_resource_id: "primary_global" | ||
| external_providers: ["time"] | ||
| vars: | ||
| location: "global" | ||
| test_env_vars: | ||
| org_id: 'ORG_ID' | ||
| project_name: 'PROJECT_NAME' | ||
| billing_account: 'BILLING_ACCOUNT' | ||
|
|
||
| parameters: | ||
| - name: 'location' | ||
| type: String | ||
| description: 'The location of the settings.' | ||
| url_param_only: true | ||
| required: true | ||
| immutable: true | ||
|
|
||
| properties: | ||
| - name: 'defaultStorageLocation' | ||
| type: String | ||
| description: 'The default storage location for new resources, e.g. buckets. Only valid for global location.' | ||
| - name: 'kmsKeyName' | ||
| type: String | ||
| description: 'The default Cloud KMS key to use for new resources. Only valid for regional locations.' | ||
| - name: 'name' | ||
| type: String | ||
| description: 'The resource name of the settings.' | ||
| output: true | ||
| - name: 'serviceAccountId' | ||
| type: String | ||
| description: 'The service account used by Cloud Observability for this project.' | ||
| output: true |
55 changes: 55 additions & 0 deletions
55
mmv1/templates/terraform/examples/observability_project_settings_basic.tf.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| resource "google_project" "project" { | ||
| provider = "google-beta" | ||
| project_id = "tf-test%{random_suffix}" | ||
| name = "tf-test%{random_suffix}" | ||
| org_id = "%{org_id}" | ||
| deletion_policy = "DELETE" | ||
| } | ||
|
|
||
| resource "google_project_service" "observability_api" { | ||
| provider = "google-beta" | ||
| project = google_project.project.project_id | ||
| service = "observability.googleapis.com" | ||
| disable_on_destroy = false | ||
| } | ||
|
|
||
| # Actively force the creation of the Service Agent identity | ||
| resource "google_project_service_identity" "observability_sa" { | ||
| provider = "google-beta" | ||
| project = google_project.project.project_id | ||
| service = "observability.googleapis.com" | ||
|
|
||
| depends_on = [ | ||
| google_project_service.observability_api | ||
| ] | ||
| } | ||
|
|
||
| # Short buffer for the new identity to propagate to global IAM indexes | ||
| resource "time_sleep" "wait_for_sa_propagation" { | ||
| create_duration = "30s" | ||
| depends_on = [ | ||
| google_project_service_identity.observability_sa | ||
| ] | ||
| } | ||
|
|
||
| resource "google_kms_crypto_key_iam_member" "crypto_key" { | ||
| provider = "google-beta" | ||
| crypto_key_id = "%{kms_key_name}" | ||
| role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
| member = "serviceAccount:${google_project_service_identity.observability_sa.email}" | ||
|
|
||
| depends_on = [ | ||
| time_sleep.wait_for_sa_propagation | ||
| ] | ||
| } | ||
|
|
||
| resource "google_observability_project_settings" "primary" { | ||
| provider = "google-beta" | ||
| location = "us" | ||
| project = google_project.project.project_id | ||
| kms_key_name = "%{kms_key_name}" | ||
|
|
||
| depends_on = [ | ||
| google_kms_crypto_key_iam_member.crypto_key | ||
| ] | ||
| } |
28 changes: 28 additions & 0 deletions
28
mmv1/templates/terraform/examples/observability_project_settings_basic_global.tf.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| resource "google_project" "project" { | ||
| provider = "google-beta" | ||
| project_id = "tf-test%{random_suffix}" | ||
| name = "tf-test%{random_suffix}" | ||
| org_id = "{{index $.TestEnvVars "org_id"}}" | ||
| deletion_policy = "DELETE" | ||
| } | ||
|
|
||
| resource "google_project_service" "observability_api" { | ||
| provider = "google-beta" | ||
| project = google_project.project.project_id | ||
| service = "observability.googleapis.com" | ||
| disable_on_destroy = false | ||
| } | ||
|
|
||
| # Wait for the project to be created and recognized by the Observability API | ||
| resource "time_sleep" "wait_for_settings_propagation" { | ||
| create_duration = "90s" | ||
| depends_on = [google_project_service.observability_api] | ||
| } | ||
|
|
||
| resource "google_observability_project_settings" "primary_global" { | ||
| provider = "google-beta" | ||
| location = "global" | ||
| project = google_project.project.project_id | ||
| default_storage_location = "eu" | ||
| depends_on = [time_sleep.wait_for_settings_propagation] | ||
| } |
14 changes: 14 additions & 0 deletions
14
mmv1/templates/terraform/pre_create/observability_project_settings.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| var masks []string | ||
| if !d.GetRawConfig().GetAttr("default_storage_location").IsNull() { | ||
| masks = append(masks, "defaultStorageLocation") | ||
| } | ||
| if !d.GetRawConfig().GetAttr("kms_key_name").IsNull() { | ||
| masks = append(masks, "kmsKeyName") | ||
| } | ||
|
|
||
| if len(masks) > 0 { | ||
| url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(masks, ",")}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...party/terraform/services/observability/data_source_observability_project_settings.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package observability | ||
|
|
||
| {{if ne $.TargetVersionName "ga" -}} | ||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| "github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
| ) | ||
|
|
||
| func DataSourceObservabilityProjectSettings() *schema.Resource { | ||
|
melinath marked this conversation as resolved.
|
||
| dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceObservabilityProjectSettings().Schema) | ||
|
|
||
| tpgresource.AddRequiredFieldsToSchema(dsSchema, "project") | ||
| tpgresource.AddRequiredFieldsToSchema(dsSchema, "location") | ||
|
|
||
| return &schema.Resource{ | ||
| Read: dataSourceObservabilityProjectSettingsRead, | ||
| Schema: dsSchema, | ||
| } | ||
| } | ||
|
|
||
| func dataSourceObservabilityProjectSettingsRead(d *schema.ResourceData, meta interface{}) error { | ||
|
leowonderful marked this conversation as resolved.
|
||
| project := d.Get("project").(string) | ||
| location := d.Get("location").(string) | ||
|
|
||
| id := fmt.Sprintf("projects/%s/locations/%s/settings", project, location) | ||
| d.SetId(id) | ||
|
|
||
| err := resourceObservabilityProjectSettingsRead(d, meta) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| if d.Id() == "" { | ||
| return fmt.Errorf("%s not found", id) | ||
| } | ||
| return nil | ||
| } | ||
| {{- end }} | ||
73 changes: 73 additions & 0 deletions
73
.../terraform/services/observability/data_source_observability_project_settings_test.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package observability_test | ||
|
|
||
| {{ if ne $.TargetVersionName "ga" -}} | ||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-provider-google/google/acctest" | ||
| "github.com/hashicorp/terraform-provider-google/google/envvar" | ||
| ) | ||
|
|
||
| func TestAccObservabilityProjectSettings_datasource(t *testing.T) { | ||
| t.Parallel() | ||
| context := map[string]interface{}{ | ||
| "project_name": "tf-test-" + acctest.RandString(t, 10), | ||
| "org_id": envvar.GetTestOrgFromEnv(t), | ||
| "billing_account": envvar.GetTestBillingAccountFromEnv(t), | ||
| "location": "us", | ||
| } | ||
| dataResourceName := "data.google_observability_project_settings.settings" | ||
| acctest.VcrTest(t, resource.TestCase{ | ||
| PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), | ||
| ExternalProviders: map[string]resource.ExternalProvider{ | ||
| "time": {}, | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testAccObservabilityProjectSettings_datasource(context), | ||
| Check: acctest.CheckDataSourceStateMatchesResourceState(dataResourceName, "google_observability_project_settings.settings"), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
| func testAccObservabilityProjectSettings_datasource(context map[string]interface{}) string { | ||
| return acctest.Nprintf(` | ||
| resource "google_project" "default" { | ||
| provider = "google-beta" | ||
| project_id = "%{project_name}" | ||
| name = "%{project_name}" | ||
| org_id = "%{org_id}" | ||
| billing_account = "%{billing_account}" | ||
| deletion_policy = "DELETE" | ||
| } | ||
| resource "google_project_service" "observability_service" { | ||
| provider = "google-beta" | ||
| project = google_project.default.project_id | ||
| service = "observability.googleapis.com" | ||
| disable_on_destroy = false | ||
| } | ||
| resource "time_sleep" "wait_for_project" { | ||
| create_duration = "60s" | ||
| depends_on = [google_project_service.observability_service] | ||
| } | ||
|
|
||
| resource "google_observability_project_settings" "settings" { | ||
| provider = "google-beta" | ||
| project = google_project.default.project_id | ||
| location = "%{location}" | ||
| kms_key_name = "" | ||
| depends_on = [time_sleep.wait_for_project] | ||
| } | ||
|
|
||
| data "google_observability_project_settings" "settings" { | ||
| provider = "google-beta" | ||
| project = google_project.default.project_id | ||
| location = "%{location}" | ||
| depends_on = [google_observability_project_settings.settings] | ||
| } | ||
| `, context) | ||
| } | ||
| {{- else }} | ||
| {{- end }} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think d.GetRawConfig() is a little heavy-handed for what you want. It would be easier / more clear to introspect what's already in
obj. It would also be nice (if possible) to avoid setting values inobjhere since they're already set above. Is there a specific reason they need to be re-set?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this is heavy-handed, however, I tried using
d.GetOkExistsand justobj["defaultStorageLocation"]instead and it always failed testing on the empty string case in the datasource test (the mask was not added with either of those cases, and the API complained)d.GetRawConfig()was my last resort to have it reliably detect this case, but I agree we can limit this to mask computation only and stop re-settingobj.