Migrate bigquery-dataset tests
This commit is contained in:
parent
230a1034ec
commit
1c7f8f5907
|
@ -35,7 +35,7 @@ module "bigquery-dataset" {
|
|||
view_1 = "my-project|my-dataset|my-table"
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=5
|
||||
# tftest modules=1 resources=5 inventory=simple.yaml
|
||||
```
|
||||
|
||||
### IAM roles
|
||||
|
@ -51,7 +51,7 @@ module "bigquery-dataset" {
|
|||
"roles/bigquery.dataOwner" = ["user:user1@example.org"]
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=2 inventory=iam.yaml
|
||||
```
|
||||
|
||||
### Dataset options
|
||||
|
@ -70,7 +70,7 @@ module "bigquery-dataset" {
|
|||
max_time_travel_hours = 168
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=1
|
||||
# tftest modules=1 resources=1 inventory=options.yaml
|
||||
```
|
||||
|
||||
### Tables and views
|
||||
|
@ -100,7 +100,7 @@ module "bigquery-dataset" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=2 inventory=tables.yaml
|
||||
```
|
||||
|
||||
If partitioning is needed, populate the `partitioning` variable using either the `time` or `range` attribute.
|
||||
|
@ -132,7 +132,7 @@ module "bigquery-dataset" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=2 inventory=partitioning.yaml
|
||||
```
|
||||
|
||||
To create views use the `view` variable. If you're querying a table created by the same module `terraform apply` will initially fail and eventually succeed once the underlying table has been created. You can probably also use the module's output in the view's query to create a dependency on the table.
|
||||
|
@ -170,7 +170,7 @@ module "bigquery-dataset" {
|
|||
}
|
||||
}
|
||||
|
||||
# tftest modules=1 resources=3
|
||||
# tftest modules=1 resources=3 inventory=views.yaml
|
||||
```
|
||||
<!-- BEGIN TFDOC -->
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# 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.
|
||||
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my-dataset
|
||||
project: my-project
|
||||
module.bigquery-dataset.google_bigquery_dataset_iam_binding.bindings["roles/bigquery.dataOwner"]:
|
||||
condition: []
|
||||
dataset_id: my-dataset
|
||||
members:
|
||||
- user:user1@example.org
|
||||
project: my-project
|
||||
role: roles/bigquery.dataOwner
|
||||
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
||||
google_bigquery_dataset_iam_binding: 1
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2022 Google LLC
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -12,15 +12,14 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import pytest
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my-dataset
|
||||
default_partition_expiration_ms: null
|
||||
default_table_expiration_ms: 3600000
|
||||
delete_contents_on_destroy: false
|
||||
location: EU
|
||||
project: my-project
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def resources(plan_runner):
|
||||
_, resources = plan_runner()
|
||||
return resources
|
||||
|
||||
|
||||
def test_resource_count(resources):
|
||||
"Test number of resources created."
|
||||
assert len(resources) == 1
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2022 Google LLC
|
||||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
@ -11,3 +11,18 @@
|
|||
# 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.
|
||||
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my-dataset
|
||||
location: EU
|
||||
project: my-project
|
||||
module.bigquery-dataset.google_bigquery_table.default["table_a"]:
|
||||
time_partitioning:
|
||||
- field: null
|
||||
require_partition_filter: null
|
||||
type: DAY
|
||||
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
||||
google_bigquery_table: 1
|
|
@ -0,0 +1,46 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# 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.
|
||||
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my-dataset
|
||||
description: Terraform managed.
|
||||
location: EU
|
||||
project: my-project
|
||||
module.bigquery-dataset.google_bigquery_dataset_access.group_by_email["reader-group"]:
|
||||
dataset_id: my-dataset
|
||||
group_by_email: playground-test@ludomagno.net
|
||||
project: my-project
|
||||
role: READER
|
||||
module.bigquery-dataset.google_bigquery_dataset_access.special_group["project_owners"]:
|
||||
dataset_id: my-dataset
|
||||
project: my-project
|
||||
role: OWNER
|
||||
special_group: projectOwners
|
||||
module.bigquery-dataset.google_bigquery_dataset_access.user_by_email["owner"]:
|
||||
dataset_id: my-dataset
|
||||
project: my-project
|
||||
role: OWNER
|
||||
user_by_email: ludo@ludomagno.net
|
||||
module.bigquery-dataset.google_bigquery_dataset_access.views["view_1"]:
|
||||
dataset_id: my-dataset
|
||||
project: my-project
|
||||
view:
|
||||
- dataset_id: my-dataset
|
||||
project_id: my-project
|
||||
table_id: my-table
|
||||
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
||||
google_bigquery_dataset_access: 4
|
|
@ -0,0 +1,39 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# 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.
|
||||
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my_dataset
|
||||
project: my-project
|
||||
module.bigquery-dataset.google_bigquery_table.default["countries"]:
|
||||
clustering: null
|
||||
dataset_id: my_dataset
|
||||
deletion_protection: true
|
||||
description: Terraform managed.
|
||||
friendly_name: Countries
|
||||
materialized_view: []
|
||||
project: my-project
|
||||
range_partitioning: []
|
||||
schema: '[{"name":"country","type":"STRING"},{"name":"population","type":"INT64"}]'
|
||||
table_id: countries
|
||||
time_partitioning: []
|
||||
view: []
|
||||
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
||||
google_bigquery_table: 1
|
||||
modules: 1
|
||||
resources: 2
|
||||
|
||||
outputs: {}
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2023 Google LLC
|
||||
#
|
||||
# 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.
|
||||
|
||||
values:
|
||||
module.bigquery-dataset.google_bigquery_dataset.default:
|
||||
dataset_id: my_dataset
|
||||
location: EU
|
||||
project: my-project
|
||||
module.bigquery-dataset.google_bigquery_table.default["countries"]:
|
||||
dataset_id: my_dataset
|
||||
friendly_name: Countries
|
||||
module.bigquery-dataset.google_bigquery_table.views["population"]:
|
||||
dataset_id: my_dataset
|
||||
deletion_protection: true
|
||||
friendly_name: Population
|
||||
project: my-project
|
||||
table_id: population
|
||||
view:
|
||||
- query: SELECT SUM(population) FROM my_dataset.countries
|
||||
use_legacy_sql: false
|
||||
|
||||
counts:
|
||||
google_bigquery_dataset: 1
|
||||
google_bigquery_table: 2
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 Google LLC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module "test" {
|
||||
source = "../../../../modules/bigquery-dataset"
|
||||
project_id = "my-project"
|
||||
id = "test"
|
||||
}
|
Loading…
Reference in New Issue