Skip to content
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

Add support for Logical Views #13306

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions mmv1/products/bigtable/LogicalView.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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: 'LogicalView'
kind: 'bigtable#logicalView'
description: |
A logical view object that can be referenced in SQL queries.
references:
guides:
api: 'https://cloud.google.com/bigtable/docs/reference/admin/rest/v2/projects.instances.logicalViews'
docs:
id_format: 'projects/{{project}}/instances/{{instance}}/logicalViews/{{logical_view_id}}'
base_url: 'projects/{{project}}/instances/{{instance}}/logicalViews?logicalViewId={{logical_view_id}}'
self_link: 'projects/{{project}}/instances/{{instance}}/logicalViews/{{logical_view_id}}'
create_url: 'projects/{{project}}/instances/{{instance}}/logicalViews?logicalViewId={{logical_view_id}}'
update_url: 'projects/{{project}}/instances/{{instance}}/logicalViews/{{logical_view_id}}'
update_verb: 'PATCH'
update_mask: true
delete_url: 'projects/{{project}}/instances/{{instance}}/logicalViews/{{logical_view_id}}'
import_format:
- 'projects/{{project}}/instances/{{instance}}/logicalViews/{{logical_view_id}}'
timeouts:
insert_minutes: 120
update_minutes: 20
delete_minutes: 20
exclude_sweeper: true
examples:
- name: 'bigtable_logical_view'
primary_resource_id: 'logical_view'
vars:
instance_name: 'bt-instance'
table_name: 'bt-table'
logical_view_name: 'bt-logical-view'
# bigtable instance does not use the shared HTTP client, this test creates an instance
skip_vcr: true
parameters:
- name: 'logicalViewId'
type: String
description:
'The unique name of the logical view in the form
`[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.'
url_param_only: true
required: true
immutable: true
- name: 'instance'
type: String
description: 'The name of the instance to create the logical 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 logical view. Values are of the form
`projects/<project>/instances/<instance>/logicalViews/<logicalViewId>`.'
output: true
- name: 'query'
type: String
description:
'The logical view''s select query.'
required: true
33 changes: 33 additions & 0 deletions mmv1/templates/terraform/examples/bigtable_logical_view.tf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "google_bigtable_instance" "instance" {
name = "{{index $.Vars "instance_name"}}"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-a"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = false
}

resource "google_bigtable_table" "table" {
name = "{{index $.Vars "table_name"}}"
instance_name = google_bigtable_instance.instance.name

column_family {
family = "CF"
}
}

resource "google_bigtable_logical_view" "{{$.PrimaryResourceId}}" {
logical_view_id = "{{index $.Vars "logical_view_name"}}"
instance = google_bigtable_instance.instance.name
query = <<EOT
SELECT _key, CF
FROM {{index $.Vars "table_name"}}
EOT

depends_on = [
google_bigtable_table.table
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package bigtable_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-google/google/acctest"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccBigtableLogicalView_update(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: testAccBigtableLogicalView_update(instanceName, tableName, mvName, "col1"),
},
{
ResourceName: "google_bigtable_logical_view.logical_view",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccBigtableLogicalView_update(instanceName, tableName, mvName, "col2"),
},
{
ResourceName: "google_bigtable_logical_view.logical_view",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccBigtableLogicalView_update(instanceName, tableName, mvName, colName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s-c"
zone = "us-central1-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_logical_view" "logical_view" {
logical_view_id = "%s"
instance = google_bigtable_instance.instance.name
query = <<EOT
SELECT _key, CF['%s']
FROM %s
EOT

depends_on = [
google_bigtable_table.table
]
}
`, instanceName, instanceName, tableName, mvName, colName, tableName)
}
Loading