fix and streamline bigtable module, add tests, align to new iam variable name
This commit is contained in:
parent
3a4938874b
commit
efc694ba01
|
@ -13,22 +13,21 @@ This module allows managing a single BigTable instance, including access configu
|
|||
|
||||
```hcl
|
||||
|
||||
module "big-table-instance" {
|
||||
module "bigtable-instance" {
|
||||
source = "./modules/bigtable-instance"
|
||||
project_id = "my-project"
|
||||
name = "instance"
|
||||
cluster_id = "instance"
|
||||
instance_type = "PRODUCTION"
|
||||
zone = "europe-west1-b"
|
||||
tables = {
|
||||
test1 = { table_options = null },
|
||||
test2 = { table_options = {
|
||||
test1 = null,
|
||||
test2 = {
|
||||
split_keys = ["a", "b", "c"]
|
||||
column_family = null
|
||||
}
|
||||
}
|
||||
}
|
||||
iam_members = {
|
||||
viewer = ["user:viewer@testdomain.com"]
|
||||
iam = {
|
||||
"roles/bigtable.user" = ["user:viewer@testdomain.com"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -44,12 +43,12 @@ module "big-table-instance" {
|
|||
| *cluster_id* | The ID of the Cloud Bigtable cluster. | <code title="">string</code> | | <code title="">europe-west1</code> |
|
||||
| *deletion_protection* | Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail. | <code title=""></code> | | <code title="">true</code> |
|
||||
| *display_name* | The human-readable display name of the Bigtable instance. | <code title=""></code> | | <code title="">null</code> |
|
||||
| *iam_members* | Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the instance are preserved. | <code title="map(set(string))">map(set(string))</code> | | <code title="">{}</code> |
|
||||
| *instance_type* | None | <code title="">string</code> | | <code title="">DEVELOPMENT</code> |
|
||||
| *iam* | IAM bindings for topic in {ROLE => [MEMBERS]} format. | <code title="map(list(string))">map(list(string))</code> | | <code title="">{}</code> |
|
||||
| *instance_type* | (deprecated) The instance type to create. One of 'DEVELOPMENT' or 'PRODUCTION'. | <code title="">string</code> | | <code title="">null</code> |
|
||||
| *num_nodes* | The number of nodes in your Cloud Bigtable cluster. | <code title="">number</code> | | <code title="">1</code> |
|
||||
| *storage_type* | The storage type to use. | <code title="">string</code> | | <code title="">SSD</code> |
|
||||
| *table_options_defaults* | Default option of tables created in the BigTable instance. | <code title="object({ split_keys = list(string) column_family = string })">object({...})</code> | | <code title="{ split_keys = [] column_family = null }">...</code> |
|
||||
| *tables* | Tables to be created in the BigTable instance. | <code title="map(object({ table_options = object({ split_keys = list(string) column_family = string }) }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
| *tables* | Tables to be created in the BigTable instance, options can be null. | <code title="map(object({ split_keys = list(string) column_family = string }))">map(object({...}))</code> | | <code title="">{}</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
locals {
|
||||
tables = {
|
||||
for k, v in var.tables : k => v.table_options != null ? v.table_options : var.table_options_defaults
|
||||
for k, v in var.tables : k => v != null ? v : var.table_options_defaults
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,7 @@ resource "google_bigtable_instance" "default" {
|
|||
}
|
||||
|
||||
resource "google_bigtable_instance_iam_binding" "default" {
|
||||
for_each = var.iam_members
|
||||
|
||||
for_each = var.iam
|
||||
project = var.project_id
|
||||
instance = google_bigtable_instance.default.name
|
||||
role = each.key
|
||||
|
|
|
@ -18,8 +18,8 @@ output "id" {
|
|||
description = "An identifier for the resource with format projects/{{project}}/instances/{{name}}."
|
||||
value = google_bigtable_instance.default.id
|
||||
depends_on = [
|
||||
google_bigtable_instance_iam_binding,
|
||||
google_bigtable_table
|
||||
google_bigtable_instance_iam_binding.default,
|
||||
google_bigtable_table.default
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@ output "instance" {
|
|||
description = "BigTable intance."
|
||||
value = google_bigtable_instance.default
|
||||
depends_on = [
|
||||
google_bigtable_instance_iam_binding,
|
||||
google_bigtable_table
|
||||
google_bigtable_instance_iam_binding.default,
|
||||
google_bigtable_table.default
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
variable "iam_members" {
|
||||
description = "Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the instance are preserved."
|
||||
type = map(set(string))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "cluster_id" {
|
||||
description = "The ID of the Cloud Bigtable cluster."
|
||||
type = string
|
||||
|
@ -36,10 +30,16 @@ variable "display_name" {
|
|||
default = null
|
||||
}
|
||||
|
||||
variable "iam" {
|
||||
description = "IAM bindings for topic in {ROLE => [MEMBERS]} format."
|
||||
type = map(list(string))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "instance_type" {
|
||||
description = "The instance type to create. One of \"DEVELOPMENT\" or \"PRODUCTION\". Defaults to \"DEVELOPMENT\""
|
||||
description = "(deprecated) The instance type to create. One of 'DEVELOPMENT' or 'PRODUCTION'."
|
||||
type = string
|
||||
default = "DEVELOPMENT"
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
|
@ -65,12 +65,10 @@ variable "storage_type" {
|
|||
}
|
||||
|
||||
variable "tables" {
|
||||
description = "Tables to be created in the BigTable instance."
|
||||
description = "Tables to be created in the BigTable instance, options can be null."
|
||||
type = map(object({
|
||||
table_options = object({
|
||||
split_keys = list(string)
|
||||
column_family = string
|
||||
})
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2020 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.
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Copyright 2020 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/bigtable-instance"
|
||||
project_id = "my-project"
|
||||
name = "test"
|
||||
iam = {
|
||||
"roles/bigtable.user" = ["user:me@example.com"]
|
||||
}
|
||||
tables = {
|
||||
test-1 = null,
|
||||
test-2 = {
|
||||
split_keys = ["a", "b", "c"]
|
||||
column_family = null
|
||||
}
|
||||
|
||||
}
|
||||
zone = var.zone
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Copyright 2020 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.
|
||||
*/
|
||||
|
||||
variable "zone" {
|
||||
type = string
|
||||
default = "europe-west1-b"
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright 2020 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.
|
||||
|
||||
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def resources(plan_runner):
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
return resources
|
||||
|
||||
|
||||
def test_resource_count(resources):
|
||||
"Test number of resources created."
|
||||
assert len(resources) == 4
|
||||
|
||||
|
||||
def test_iam(resources):
|
||||
"Test IAM binding resources."
|
||||
bindings = [r['values'] for r in resources if r['type']
|
||||
== 'google_bigtable_instance_iam_binding']
|
||||
assert len(bindings) == 1
|
||||
assert bindings[0]['role'] == 'roles/bigtable.user'
|
||||
|
||||
|
||||
def test_tables(resources):
|
||||
"Test table resources."
|
||||
subs = [r['values'] for r in resources if r['type']
|
||||
== 'google_bigtable_table']
|
||||
assert len(subs) == 2
|
||||
assert set(s['name'] for s in subs) == set(['test-1', 'test-2'])
|
Loading…
Reference in New Issue