diff --git a/modules/bigtable-instance/README.md b/modules/bigtable-instance/README.md
index da332180b..23aac694a 100644
--- a/modules/bigtable-instance/README.md
+++ b/modules/bigtable-instance/README.md
@@ -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. | string | | europe-west1 |
| *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. | | | true |
| *display_name* | The human-readable display name of the Bigtable instance. | | | null |
-| *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. | map(set(string)) | | {} |
-| *instance_type* | None | string | | DEVELOPMENT |
+| *iam* | IAM bindings for topic in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} |
+| *instance_type* | (deprecated) The instance type to create. One of 'DEVELOPMENT' or 'PRODUCTION'. | string | | null |
| *num_nodes* | The number of nodes in your Cloud Bigtable cluster. | number | | 1 |
| *storage_type* | The storage type to use. | string | | SSD |
| *table_options_defaults* | Default option of tables created in the BigTable instance. | object({...}) | | ... |
-| *tables* | Tables to be created in the BigTable instance. | map(object({...})) | | {} |
+| *tables* | Tables to be created in the BigTable instance, options can be null. | map(object({...})) | | {} |
## Outputs
diff --git a/modules/bigtable-instance/main.tf b/modules/bigtable-instance/main.tf
index 32c27bb5c..f8660606f 100644
--- a/modules/bigtable-instance/main.tf
+++ b/modules/bigtable-instance/main.tf
@@ -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
diff --git a/modules/bigtable-instance/outputs.tf b/modules/bigtable-instance/outputs.tf
index 2012b5c63..4d7a5217c 100644
--- a/modules/bigtable-instance/outputs.tf
+++ b/modules/bigtable-instance/outputs.tf
@@ -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
]
}
diff --git a/modules/bigtable-instance/variables.tf b/modules/bigtable-instance/variables.tf
index 0e2db64fa..662ac5b34 100644
--- a/modules/bigtable-instance/variables.tf
+++ b/modules/bigtable-instance/variables.tf
@@ -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
- })
+ split_keys = list(string)
+ column_family = string
}))
default = {}
}
diff --git a/tests/modules/bigtable_instance/__init__.py b/tests/modules/bigtable_instance/__init__.py
new file mode 100644
index 000000000..6913f02e3
--- /dev/null
+++ b/tests/modules/bigtable_instance/__init__.py
@@ -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.
diff --git a/tests/modules/bigtable_instance/fixture/main.tf b/tests/modules/bigtable_instance/fixture/main.tf
new file mode 100644
index 000000000..47aa2ed53
--- /dev/null
+++ b/tests/modules/bigtable_instance/fixture/main.tf
@@ -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
+}
diff --git a/tests/modules/bigtable_instance/fixture/variables.tf b/tests/modules/bigtable_instance/fixture/variables.tf
new file mode 100644
index 000000000..2c2d2d037
--- /dev/null
+++ b/tests/modules/bigtable_instance/fixture/variables.tf
@@ -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"
+}
diff --git a/tests/modules/bigtable_instance/test_plan.py b/tests/modules/bigtable_instance/test_plan.py
new file mode 100644
index 000000000..875816ffa
--- /dev/null
+++ b/tests/modules/bigtable_instance/test_plan.py
@@ -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'])