-
Notifications
You must be signed in to change notification settings - Fork 2k
Add support for Materialized Views #13251
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
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c15a1f5
Add support for Materialized Views
ron-gal 8040e53
Add support for Materialized Views
ron-gal 8522d25
Update mmv1/templates/terraform/examples/bigtable_materialized_view.t…
ron-gal 96d897e
Update mmv1/products/bigtable/MaterializedView.yaml
ron-gal 9bcb917
Update mmv1/products/bigtable/MaterializedView.yaml
ron-gal 00e2876
Update mmv1/third_party/terraform/services/bigtable/resource_bigtable…
ron-gal 153eab5
Update mmv1/templates/terraform/examples/bigtable_materialized_view.t…
ron-gal 2152211
Update mmv1/templates/terraform/examples/bigtable_materialized_view.t…
ron-gal edc12a3
Fix test
ron-gal 0c65e43
Fix tests
ron-gal 0c22693
Merge branch 'GoogleCloudPlatform:main' into mat_views
ron-gal 8ae003d
Update resource_bigtable_materialized_view_test.go
ron-gal 96ae287
Update MaterializedView.yaml
ron-gal 6d99472
Update mmv1/products/bigtable/MaterializedView.yaml
melinath a567580
Update bigtable_materialized_view.tf.tmpl
ron-gal c50284e
Update resource_bigtable_materialized_view_test.go
ron-gal 026e06d
fix tests
ron-gal 643aeb5
fix tests
ron-gal 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2025 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: 'MaterializedView' | ||
kind: 'bigtable#materializedView' | ||
description: | | ||
A materialized view object that can be referenced in SQL queries. | ||
references: | ||
guides: | ||
api: 'https://cloud.google.com/bigtable/docs/reference/admin/rest/v2/projects.instances.materializedViews' | ||
docs: | ||
id_format: 'projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}' | ||
base_url: 'projects/{{project}}/instances/{{instance}}/materializedViews?materializedViewId={{materialized_view_id}}' | ||
self_link: 'projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}' | ||
create_url: 'projects/{{project}}/instances/{{instance}}/materializedViews?materializedViewId={{materialized_view_id}}' | ||
update_url: 'projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}' | ||
update_verb: 'PATCH' | ||
update_mask: true | ||
delete_url: 'projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}' | ||
import_format: | ||
- 'projects/{{project}}/instances/{{instance}}/materializedViews/{{materialized_view_id}}' | ||
timeouts: | ||
insert_minutes: 120 | ||
update_minutes: 20 | ||
delete_minutes: 20 | ||
exclude_sweeper: true | ||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
examples: | ||
- name: 'bigtable_materialized_view' | ||
primary_resource_id: 'materialized_view' | ||
vars: | ||
instance_name: 'bt-instance' | ||
table_name: 'bt-table' | ||
materialized_view_name: 'bt-materialized-view' | ||
deletion_protection: 'true' | ||
test_vars_overrides: | ||
'deletion_protection': 'false' | ||
oics_vars_overrides: | ||
'deletion_protection': 'false' | ||
# bigtable instance does not use the shared HTTP client, this test creates an instance | ||
skip_vcr: true | ||
parameters: | ||
- name: 'materializedViewId' | ||
type: String | ||
description: | ||
'The unique name of the materialized view in the form | ||
`[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.' | ||
melinath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
url_param_only: true | ||
required: true | ||
immutable: true | ||
- name: 'instance' | ||
type: String | ||
description: 'The name of the instance to create the materialized view within.' | ||
url_param_only: true | ||
immutable: true | ||
diff_suppress_func: 'tpgresource.CompareResourceNames' | ||
properties: | ||
- name: 'name' | ||
type: String | ||
description: | ||
'The unique name of the requested materialized view. Values are of the form | ||
`projects/<project>/instances/<instance>/materializedViews/<materializedViewId>`.' | ||
output: true | ||
- name: 'query' | ||
type: String | ||
description: | ||
'The materialized view''s select query.' | ||
required: true | ||
immutable: true | ||
- name: 'deletionProtection' | ||
type: Boolean | ||
description: | ||
'Set to true to make the MaterializedView protected against deletion.' |
35 changes: 35 additions & 0 deletions
35
mmv1/templates/terraform/examples/bigtable_materialized_view.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,35 @@ | ||
resource "google_bigtable_instance" "instance" { | ||
name = "{{index $.Vars "instance_name"}}" | ||
cluster { | ||
cluster_id = "cluster-1" | ||
zone = "us-east1-b" | ||
num_nodes = 3 | ||
storage_type = "HDD" | ||
} | ||
|
||
deletion_protection = {{index $.Vars "deletion_protection"}} | ||
} | ||
|
||
resource "google_bigtable_table" "table" { | ||
name = "{{index $.Vars "table_name"}}" | ||
instance_name = google_bigtable_instance.instance.name | ||
|
||
column_family { | ||
family = "CF" | ||
} | ||
} | ||
|
||
resource "google_bigtable_materialized_view" "{{$.PrimaryResourceId}}" { | ||
materialized_view_id = "{{index $.Vars "materialized_view_name"}}" | ||
instance = google_bigtable_instance.instance.name | ||
deletion_protection = false | ||
query = <<EOT | ||
SELECT _key, COUNT(CF['col1']) as Count | ||
FROM ` + "`{{index $.Vars "table_name"}}`" + ` | ||
GROUP BY _key | ||
EOT | ||
|
||
depends_on = [ | ||
google_bigtable_table.table | ||
] | ||
} |
88 changes: 88 additions & 0 deletions
88
mmv1/third_party/terraform/services/bigtable/resource_bigtable_materialized_view_test.go
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,88 @@ | ||
package bigtable_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/plancheck" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccBigtableMaterializedView_deletionProtection(t *testing.T) { | ||
// bigtable instance does not use the shared HTTP client, this test creates an instance | ||
acctest.SkipIfVcr(t) | ||
t.Parallel() | ||
|
||
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) | ||
tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) | ||
mvName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccBigtableMaterializedView_deletionProtection(instanceName, tableName, mvName, true), | ||
}, | ||
{ | ||
ResourceName: "google_bigtable_materialized_view.materialized_view", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccBigtableMaterializedView_deletionProtection(instanceName, tableName, mvName, false), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
PreApply: []plancheck.PlanCheck{ | ||
plancheck.ExpectResourceAction("google_bigtable_materialized_view.materialized_view", plancheck.ResourceActionUpdate), | ||
}, | ||
}, | ||
}, | ||
{ | ||
ResourceName: "google_bigtable_materialized_view.materialized_view", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccBigtableMaterializedView_deletionProtection(instanceName, tableName, mvName string, deletion_protection bool) string { | ||
return fmt.Sprintf(` | ||
resource "google_bigtable_instance" "instance" { | ||
name = "%s" | ||
cluster { | ||
cluster_id = "%s-c" | ||
zone = "us-east1-b" | ||
} | ||
deletion_protection = false | ||
} | ||
resource "google_bigtable_table" "table" { | ||
name = "%s" | ||
instance_name = google_bigtable_instance.instance.id | ||
column_family { | ||
family = "CF" | ||
} | ||
} | ||
resource "google_bigtable_materialized_view" "materialized_view" { | ||
materialized_view_id = "%s" | ||
instance = google_bigtable_instance.instance.name | ||
deletion_protection = %v | ||
query = <<EOT | ||
SELECT _key, COUNT(CF['col']) as Count | ||
FROM %s | ||
GROUP BY _key | ||
EOT | ||
depends_on = [ | ||
google_bigtable_table.table | ||
] | ||
} | ||
`, instanceName, instanceName, tableName, mvName, deletion_protection, fmt.Sprintf("`%s`", tableName)) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.