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

Expand Test Coverage #387

Merged
merged 17 commits into from
Nov 28, 2023
Merged
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## Unreleased

### Features
* Add `default` to columns when defining a `materialize_table` [#374](https://github.com/MaterializeInc/terraform-provider-materialize/pull/374)
* Add `expose_progress` to source resources [#374](https://github.com/MaterializeInc/terraform-provider-materialize/pull/374)
* Support the [row type](https://materialize.com/docs/sql/create-type/#row-properties) in `materialize_type` [#374](https://github.com/MaterializeInc/terraform-provider-materialize/pull/374)

### BugFixes

### Misc

### Breaking Changes
* Remove `session_variables` from `materialize_role` [#374](https://github.com/MaterializeInc/terraform-provider-materialize/pull/374)

## 0.3.2 - 2023-11-24

### Features
Expand Down
9 changes: 0 additions & 9 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,13 @@ resource "materialize_role" "example_role" {
### Optional

- `comment` (String) **Private Preview** Comment on an object in the database.
- `session_variable` (Block List) Session variable. (see [below for nested schema](#nestedblock--session_variable))

### Read-Only

- `id` (String) The ID of this resource.
- `inherit` (Boolean) Grants the role the ability to inheritance of privileges of other roles. Unlike PostgreSQL, Materialize does not currently support `NOINHERIT`
- `qualified_sql_name` (String) The fully qualified name of the role.

<a id="nestedblock--session_variable"></a>
### Nested Schema for `session_variable`

Required:

- `name` (String) The name of the session variable.
- `value` (String) The value for the session variable.

## Import

Import is supported using the following syntax:
Expand Down
14 changes: 14 additions & 0 deletions docs/resources/source_load_generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ resource "materialize_source_load_generator" "example_source_load_generator" {
- `comment` (String) **Private Preview** Comment on an object in the database.
- `counter_options` (Block List) Counter Options. (see [below for nested schema](#nestedblock--counter_options))
- `database_name` (String) The identifier for the source database. Defaults to `MZ_DATABASE` environment variable if set or `materialize` if environment variable is not set.
- `expose_progress` (Block List, Max: 1) The name of the progress subsource for the source. If this is not specified, the subsource will be named `<src_name>_progress`. (see [below for nested schema](#nestedblock--expose_progress))
- `marketing_options` (Block List) Marketing Options. (see [below for nested schema](#nestedblock--marketing_options))
- `ownership_role` (String) The owernship role of the object.
- `schema_name` (String) The identifier for the source schema. Defaults to `public`.
Expand Down Expand Up @@ -78,6 +79,19 @@ Optional:
- `tick_interval` (String) The interval at which the next datum should be emitted. Defaults to one second.


<a id="nestedblock--expose_progress"></a>
### Nested Schema for `expose_progress`

Required:

- `name` (String) The expose_progress name.

Optional:

- `database_name` (String) The expose_progress database name. Defaults to `MZ_DATABASE` environment variable if set or `materialize` if environment variable is not set.
- `schema_name` (String) The expose_progress schema name. Defaults to `public`


<a id="nestedblock--marketing_options"></a>
### Nested Schema for `marketing_options`

Expand Down
3 changes: 2 additions & 1 deletion docs/resources/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Required:
Optional:

- `comment` (String) **Private Preview** Comment on an object in the database.
- `nullable` (Boolean) Do not allow the column to contain NULL values. Columns without this constraint can contain NULL values.
- `default` (String) A default value to use for the column in an INSERT statement if an explicit value is not provided. If not specified, `NULL` is assumed..
- `nullable` (Boolean) Do not allow the column to contain `NULL` values. Columns without this constraint can contain `NULL` values.

## Import

Expand Down
10 changes: 10 additions & 0 deletions docs/resources/type.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ resource "materialize_type" "map_type" {
- `list_properties` (Block List, Max: 1) List properties. (see [below for nested schema](#nestedblock--list_properties))
- `map_properties` (Block List, Max: 1) Map properties. (see [below for nested schema](#nestedblock--map_properties))
- `ownership_role` (String) The owernship role of the object.
- `row_properties` (Block List) Row properties. (see [below for nested schema](#nestedblock--row_properties))
- `schema_name` (String) The identifier for the type schema. Defaults to `public`.

### Read-Only
Expand All @@ -73,6 +74,15 @@ Required:
- `key_type` (String) Creates a custom map whose keys are of `KEY TYPE`. `KEY TYPE` must resolve to text.
- `value_type` (String) Creates a custom map whose values are of `VALUE TYPE`.


<a id="nestedblock--row_properties"></a>
### Nested Schema for `row_properties`

Required:

- `field_name` (String) The name of a field in a row type.
- `field_type` (String) The data type of a field indicated by `FIELD NAME`.

## Import

Import is supported using the following syntax:
Expand Down
6 changes: 6 additions & 0 deletions integration/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ resource "materialize_cluster" "cluster_source" {
name = "cluster_sources"
}

resource "materialize_cluster" "cluster_sink" {
name = "cluster_sinks"
size = "3xsmall"
replication_factor = 1
}

resource "materialize_cluster_grant" "cluster_grant_usage" {
role_name = materialize_role.role_1.name
privilege = "USAGE"
Expand Down
13 changes: 0 additions & 13 deletions integration/role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ resource "materialize_role" "grantee" {

resource "materialize_role" "target" {
name = "target"

session_variable {
name = "datestyle"
value = "ISO, MDY"
}
session_variable {
name = "emit_timestamp_notice"
value = "true"
}
session_variable {
name = "max_query_result_size"
value = "1073741824"
}
}

resource "materialize_grant_system_privilege" "role_1_system_createrole" {
Expand Down
45 changes: 36 additions & 9 deletions integration/sink.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
resource "materialize_sink_kafka" "sink_kafka" {
name = "sink_kafka"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name
comment = "sink comment"
size = "3xsmall"
name = "sink_kafka"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name
comment = "sink comment"
size = "3xsmall"
topic = "topic1"
key = ["counter"]
key_not_enforced = true
from {
name = materialize_source_load_generator.load_generator.name
database_name = materialize_source_load_generator.load_generator.database_name
schema_name = materialize_source_load_generator.load_generator.schema_name
}
topic = "topic1"
kafka_connection {
name = materialize_connection_kafka.kafka_connection.name
database_name = materialize_connection_kafka.kafka_connection.database_name
schema_name = materialize_connection_kafka.kafka_connection.schema_name
}
format {
avro {
schema_registry_connection {
Expand All @@ -19,16 +26,36 @@ resource "materialize_sink_kafka" "sink_kafka" {
}
}
}
envelope {
debezium = true
}
}

resource "materialize_sink_kafka" "sink_kafka_cluster" {
name = "sink_kafka_cluster"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name
cluster_name = materialize_cluster.cluster_sink.name
topic = "topic1"
key = ["counter"]
key_not_enforced = true
snapshot = true
from {
name = materialize_source_load_generator.load_generator.name
database_name = materialize_source_load_generator.load_generator.database_name
schema_name = materialize_source_load_generator.load_generator.schema_name
}
kafka_connection {
name = materialize_connection_kafka.kafka_connection.name
database_name = materialize_connection_kafka.kafka_connection.database_name
schema_name = materialize_connection_kafka.kafka_connection.schema_name
}
format {
json = true
}
envelope {
debezium = true
upsert = true
}
key = ["counter"]
key_not_enforced = true
}

output "qualified_sink_kafka" {
Expand Down
12 changes: 11 additions & 1 deletion integration/table.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ resource "materialize_table" "simple_table" {
type = "text"
nullable = true
}

column {
name = "column_4"
type = "text"
default = "NULL"
}
column {
name = "column_5"
type = "text"
nullable = true
default = "NULL"
}
}

resource "materialize_table_grant" "table_grant_select" {
Expand Down
51 changes: 51 additions & 0 deletions integration/type.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
resource "materialize_type" "row_type" {
name = "row_type"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name

row_properties {
field_name = "a"
field_type = "int4"
}
row_properties {
field_name = "b"
field_type = "text"
}
}

resource "materialize_type" "row_nested_type" {
name = "nested_row_type"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name

row_properties {
field_name = "a"
field_type = materialize_type.row_type.qualified_sql_name
}
row_properties {
field_name = "b"
field_type = "float8"
}
}

resource "materialize_type" "list_type" {
name = "int4_list"
schema_name = materialize_schema.schema.name
Expand All @@ -8,6 +38,16 @@ resource "materialize_type" "list_type" {
}
}

resource "materialize_type" "list_nested_type" {
name = "int4_nested_list"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name

list_properties {
element_type = materialize_type.list_type.qualified_sql_name
}
}

resource "materialize_type" "map_type" {
name = "int4_map"
schema_name = materialize_schema.schema.name
Expand All @@ -19,6 +59,17 @@ resource "materialize_type" "map_type" {
}
}

resource "materialize_type" "map_nested_type" {
name = "int4_nested_map"
schema_name = materialize_schema.schema.name
database_name = materialize_database.database.name

map_properties {
key_type = "text"
value_type = materialize_type.map_type.qualified_sql_name
}
}

resource "materialize_type_grant" "type_grant_usage" {
role_name = materialize_role.role_1.name
privilege = "USAGE"
Expand Down
27 changes: 19 additions & 8 deletions pkg/materialize/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/jmoiron/sqlx"
)

// https://github.com/MaterializeInc/materialize/blob/main/test/sqllogictest/managed_cluster.slt
// https://materialize.com/docs/sql/create-cluster/

func TestClusterCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE CLUSTER "cluster" REPLICAS \(\);`).WillReturnResult(sqlmock.NewResult(1, 1))
Expand All @@ -19,7 +22,7 @@ func TestClusterCreate(t *testing.T) {
})
}

func TestClusterManagedSizeCreate(t *testing.T) {
func TestClusterManagedCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall';`).WillReturnResult(sqlmock.NewResult(1, 1))

Expand All @@ -32,28 +35,28 @@ func TestClusterManagedSizeCreate(t *testing.T) {
})
}

func TestClusterManagedSizeDiskCreate(t *testing.T) {
func TestClusterManagedReplicationFactorCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall', DISK;`).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall', REPLICATION FACTOR 3;`).WillReturnResult(sqlmock.NewResult(1, 1))

o := MaterializeObject{Name: "cluster"}
b := NewClusterBuilder(db, o)
b.Size("xsmall")
b.Disk(true)
b.ReplicationFactor(3)
if err := b.Create(); err != nil {
t.Fatal(err)
}
})
}

func TestClusterManagedSizeReplicationCreate(t *testing.T) {
func TestClusterManagedSizeDiskCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall', REPLICATION FACTOR 2;`).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall', DISK;`).WillReturnResult(sqlmock.NewResult(1, 1))

o := MaterializeObject{Name: "cluster"}
b := NewClusterBuilder(db, o)
b.Size("xsmall")
b.ReplicationFactor(2)
b.Disk(true)
if err := b.Create(); err != nil {
t.Fatal(err)
}
Expand All @@ -62,7 +65,15 @@ func TestClusterManagedSizeReplicationCreate(t *testing.T) {

func TestClusterManagedAllCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE CLUSTER "cluster" SIZE 'xsmall', REPLICATION FACTOR 2, AVAILABILITY ZONES = \['us-east-1'\], INTROSPECTION INTERVAL = '1s', INTROSPECTION DEBUGGING = TRUE, IDLE ARRANGEMENT MERGE EFFORT = 1;`).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(`
CREATE CLUSTER "cluster"
SIZE 'xsmall',
REPLICATION FACTOR 2,
AVAILABILITY ZONES = \['us-east-1'\],
INTROSPECTION INTERVAL = '1s',
INTROSPECTION DEBUGGING = TRUE,
IDLE ARRANGEMENT MERGE EFFORT = 1;
`).WillReturnResult(sqlmock.NewResult(1, 1))

o := MaterializeObject{Name: "cluster"}
b := NewClusterBuilder(db, o)
Expand Down
Loading