diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 3479eba6..c19662a2 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -46,7 +46,8 @@ Import is supported using the following syntax: ```shell # Clusters can be imported using the cluster id: -terraform import materialize_cluster.example_cluster +terraform import materialize_cluster.example_cluster : # Cluster id and information be found in the `mz_catalog.mz_clusters` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/cluster_replica b/docs/resources/cluster_replica index 45c9114c..23b759ef 100644 --- a/docs/resources/cluster_replica +++ b/docs/resources/cluster_replica @@ -46,7 +46,8 @@ Import is supported using the following syntax: ```shell # Cluster replicas can be imported using the cluster replica id: -terraform import materialize_cluster_replica.example_1_cluster_replica +terraform import materialize_cluster_replica.example_1_cluster_replica : # Cluster replica id and information be found in the `mz_catalog.mz_cluster_replicas` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` \ No newline at end of file diff --git a/docs/resources/cluster_replica.md b/docs/resources/cluster_replica.md index db6cf23f..d0d35da8 100644 --- a/docs/resources/cluster_replica.md +++ b/docs/resources/cluster_replica.md @@ -48,7 +48,8 @@ Import is supported using the following syntax: ```shell # Cluster replicas can be imported using the cluster replica id: -terraform import materialize_cluster_replica.example_1_cluster_replica +terraform import materialize_cluster_replica.example_1_cluster_replica : # Cluster replica id and information be found in the `mz_catalog.mz_cluster_replicas` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/connection_aws_privatelink.md b/docs/resources/connection_aws_privatelink.md index 95369632..9cc8d165 100644 --- a/docs/resources/connection_aws_privatelink.md +++ b/docs/resources/connection_aws_privatelink.md @@ -57,7 +57,8 @@ Import is supported using the following syntax: ```shell #Connections can be imported using the connection id: -terraform import materialize_connection_aws_privatelink.example +terraform import materialize_connection_aws_privatelink.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/connection_confluent_schema_registry.md b/docs/resources/connection_confluent_schema_registry.md index 409bc060..b33949e4 100644 --- a/docs/resources/connection_confluent_schema_registry.md +++ b/docs/resources/connection_confluent_schema_registry.md @@ -184,7 +184,8 @@ Import is supported using the following syntax: ```shell #Connections can be imported using the connection id: -terraform import materialize_connection_confluent_schema_registry.example +terraform import materialize_connection_confluent_schema_registry.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/connection_kafka.md b/docs/resources/connection_kafka.md index 02c7f010..3443642d 100644 --- a/docs/resources/connection_kafka.md +++ b/docs/resources/connection_kafka.md @@ -251,8 +251,9 @@ Optional: Import is supported using the following syntax: ```shell -#Connections can be imported using the connection id: -terraform import materialize_connection_kafka.example +# Connections can be imported using the connection id: +terraform import materialize_connection_kafka.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/connection_postgres.md b/docs/resources/connection_postgres.md index 1b95ead0..ad8f0ed3 100644 --- a/docs/resources/connection_postgres.md +++ b/docs/resources/connection_postgres.md @@ -226,5 +226,8 @@ Import is supported using the following syntax: ```shell # Connections can be imported using the connection id: -terraform import materialize_connection_postgres.example +terraform import materialize_connection_postgres.example : + +# Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/connection_ssh_tunnel.md b/docs/resources/connection_ssh_tunnel.md index 0bf18356..959e81b9 100644 --- a/docs/resources/connection_ssh_tunnel.md +++ b/docs/resources/connection_ssh_tunnel.md @@ -59,7 +59,8 @@ Import is supported using the following syntax: ```shell #Connections can be imported using the connection id: -terraform import materialize_connection_ssh_tunnel.example +terraform import materialize_connection_ssh_tunnel.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/index.md b/docs/resources/index.md index bc644646..a2819a58 100644 --- a/docs/resources/index.md +++ b/docs/resources/index.md @@ -80,7 +80,8 @@ Import is supported using the following syntax: ```shell # Indexes can be imported using the index id: -terraform import materialize_index.example_index +terraform import materialize_index.example_index : # Index id and information be found in the `mz_catalog.mz_indexes` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/materialized_view.md b/docs/resources/materialized_view.md index 308e3f6c..db6d4b48 100644 --- a/docs/resources/materialized_view.md +++ b/docs/resources/materialized_view.md @@ -65,7 +65,8 @@ Import is supported using the following syntax: ```shell # Materialized views can be imported using the materialized view id: -terraform import materialize_materialized_view.example_materialize_view +terraform import materialize_materialized_view.example_materialize_view : # Materialized view id and information be found in the `mz_catalog.mz_materialized_views` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/role.md b/docs/resources/role.md index e0578ddb..b46d62dc 100644 --- a/docs/resources/role.md +++ b/docs/resources/role.md @@ -41,7 +41,8 @@ Import is supported using the following syntax: ```shell # Roles can be imported using the role id: -terraform import materialize_role.example_role +terraform import materialize_role.example_role : # Role id and information be found in the `mz_catalog.mz_roles` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/schema.md b/docs/resources/schema.md index 2dac0d8b..7d0a8ef2 100644 --- a/docs/resources/schema.md +++ b/docs/resources/schema.md @@ -43,7 +43,8 @@ Import is supported using the following syntax: ```shell # Schemas can be imported using the schema id: -terraform import materialize_schema.example_schema +terraform import materialize_schema.example_schema : # Schema id and information be found in the `mz_catalog.mz_schemas` table +# The role is the role where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/secret.md b/docs/resources/secret.md index 52bbd1e2..37584fb2 100644 --- a/docs/resources/secret.md +++ b/docs/resources/secret.md @@ -45,7 +45,8 @@ Import is supported using the following syntax: ```shell # Secrets can be imported using the secret id: -terraform import materialize_secret.example_secret +terraform import materialize_secret.example_secret : # Secret id and information be found in the `mz_catalog.mz_secrets` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/sink_kafka.md b/docs/resources/sink_kafka.md index b015b94c..a35c0a89 100644 --- a/docs/resources/sink_kafka.md +++ b/docs/resources/sink_kafka.md @@ -148,7 +148,8 @@ Import is supported using the following syntax: ```shell # Sinks can be imported using the sink id: -terraform import materialize_sink_kafka.example_sink_kafka +terraform import materialize_sink_kafka.example_sink_kafka : # Sink id and information be found in the `mz_catalog.mz_sinks` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/source_kafka.md b/docs/resources/source_kafka.md index 47226747..04e821f3 100644 --- a/docs/resources/source_kafka.md +++ b/docs/resources/source_kafka.md @@ -348,7 +348,8 @@ Import is supported using the following syntax: ```shell # Sources can be imported using the source id: -terraform import materialize_source_kafka.example_source_kafka +terraform import materialize_source_kafka.example_source_kafka : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/source_load_generator.md b/docs/resources/source_load_generator.md index 3a3c9722..68063895 100644 --- a/docs/resources/source_load_generator.md +++ b/docs/resources/source_load_generator.md @@ -125,7 +125,8 @@ Import is supported using the following syntax: ```shell # Sources can be imported using the source id: -terraform import materialize_source_load_generator.example_source_load_generator +terraform import materialize_source_load_generator.example_source_load_generator : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/source_postgres.md b/docs/resources/source_postgres.md index 7efc3dc1..e9a4c75f 100644 --- a/docs/resources/source_postgres.md +++ b/docs/resources/source_postgres.md @@ -124,7 +124,8 @@ Import is supported using the following syntax: ```shell # Sources can be imported using the source id: -terraform import materialize_source_postgres.example_source_postgres +terraform import materialize_source_postgres.example_source_postgres : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/source_webhook.md b/docs/resources/source_webhook.md index 21d78673..45933c77 100644 --- a/docs/resources/source_webhook.md +++ b/docs/resources/source_webhook.md @@ -150,7 +150,8 @@ Import is supported using the following syntax: ```shell # Sources can be imported using the source id: -terraform import materialize_source_webhook.example_source_webhook +terraform import materialize_source_webhook.example_source_webhook : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/table.md b/docs/resources/table.md index 338247ba..8f2ab959 100644 --- a/docs/resources/table.md +++ b/docs/resources/table.md @@ -75,7 +75,8 @@ Import is supported using the following syntax: ```shell # Tables can be imported using the table id: -terraform import materialize_table.example_table +terraform import materialize_table.example_table : # Table id and information be found in the `mz_catalog.mz_tables` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/type.md b/docs/resources/type.md index 02ea3869..b12f116b 100644 --- a/docs/resources/type.md +++ b/docs/resources/type.md @@ -89,7 +89,8 @@ Import is supported using the following syntax: ```shell # Types can be imported using the type id: -terraform import materialize_type.example_type +terraform import materialize_type.example_type : # Type id and information be found in the `mz_catalog.mz_types` table +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/docs/resources/view.md b/docs/resources/view.md index 58be274f..514bc322 100644 --- a/docs/resources/view.md +++ b/docs/resources/view.md @@ -63,7 +63,8 @@ Import is supported using the following syntax: ```shell # Views can be imported using the view id: -terraform import materialize_view.example_view +terraform import materialize_view.example_view : # View id and information be found in the `mz_catalog.mz_views` +# The region is the region where the database is located (e.g. aws/us-east-1) ``` diff --git a/examples/resources/materialize_cluster/import.sh b/examples/resources/materialize_cluster/import.sh index aad30b6e..8e297930 100644 --- a/examples/resources/materialize_cluster/import.sh +++ b/examples/resources/materialize_cluster/import.sh @@ -1,4 +1,5 @@ # Clusters can be imported using the cluster id: -terraform import materialize_cluster.example_cluster +terraform import materialize_cluster.example_cluster : # Cluster id and information be found in the `mz_catalog.mz_clusters` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_cluster_replica/import.sh b/examples/resources/materialize_cluster_replica/import.sh index ca898e20..1811901d 100644 --- a/examples/resources/materialize_cluster_replica/import.sh +++ b/examples/resources/materialize_cluster_replica/import.sh @@ -1,4 +1,5 @@ # Cluster replicas can be imported using the cluster replica id: -terraform import materialize_cluster_replica.example_1_cluster_replica +terraform import materialize_cluster_replica.example_1_cluster_replica : # Cluster replica id and information be found in the `mz_catalog.mz_cluster_replicas` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_connection_aws_privatelink/import.sh b/examples/resources/materialize_connection_aws_privatelink/import.sh index 6a650f27..2832a886 100644 --- a/examples/resources/materialize_connection_aws_privatelink/import.sh +++ b/examples/resources/materialize_connection_aws_privatelink/import.sh @@ -1,4 +1,5 @@ #Connections can be imported using the connection id: -terraform import materialize_connection_aws_privatelink.example +terraform import materialize_connection_aws_privatelink.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_connection_confluent_schema_registry/import.sh b/examples/resources/materialize_connection_confluent_schema_registry/import.sh index 36ff7772..04ea89b3 100644 --- a/examples/resources/materialize_connection_confluent_schema_registry/import.sh +++ b/examples/resources/materialize_connection_confluent_schema_registry/import.sh @@ -1,4 +1,5 @@ #Connections can be imported using the connection id: -terraform import materialize_connection_confluent_schema_registry.example +terraform import materialize_connection_confluent_schema_registry.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_connection_kafka/import.sh b/examples/resources/materialize_connection_kafka/import.sh index 2fb7bba0..a28477ca 100644 --- a/examples/resources/materialize_connection_kafka/import.sh +++ b/examples/resources/materialize_connection_kafka/import.sh @@ -1,4 +1,5 @@ -#Connections can be imported using the connection id: -terraform import materialize_connection_kafka.example +# Connections can be imported using the connection id: +terraform import materialize_connection_kafka.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_connection_postgres/import.sh b/examples/resources/materialize_connection_postgres/import.sh index 42835bde..3712d86b 100644 --- a/examples/resources/materialize_connection_postgres/import.sh +++ b/examples/resources/materialize_connection_postgres/import.sh @@ -1,2 +1,5 @@ # Connections can be imported using the connection id: -terraform import materialize_connection_postgres.example \ No newline at end of file +terraform import materialize_connection_postgres.example : + +# Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_connection_ssh_tunnel/import.sh b/examples/resources/materialize_connection_ssh_tunnel/import.sh index 70e56fd9..5252847b 100644 --- a/examples/resources/materialize_connection_ssh_tunnel/import.sh +++ b/examples/resources/materialize_connection_ssh_tunnel/import.sh @@ -1,4 +1,5 @@ #Connections can be imported using the connection id: -terraform import materialize_connection_ssh_tunnel.example +terraform import materialize_connection_ssh_tunnel.example : # Connection id and information be found in the `mz_catalog.mz_connections` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_index/import.sh b/examples/resources/materialize_index/import.sh index c504c2ef..5f25a14e 100644 --- a/examples/resources/materialize_index/import.sh +++ b/examples/resources/materialize_index/import.sh @@ -1,4 +1,5 @@ # Indexes can be imported using the index id: -terraform import materialize_index.example_index +terraform import materialize_index.example_index : # Index id and information be found in the `mz_catalog.mz_indexes` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_materialized_view/import.sh b/examples/resources/materialize_materialized_view/import.sh index 41c69803..e4e43dba 100644 --- a/examples/resources/materialize_materialized_view/import.sh +++ b/examples/resources/materialize_materialized_view/import.sh @@ -1,4 +1,5 @@ # Materialized views can be imported using the materialized view id: -terraform import materialize_materialized_view.example_materialize_view +terraform import materialize_materialized_view.example_materialize_view : # Materialized view id and information be found in the `mz_catalog.mz_materialized_views` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_role/import.sh b/examples/resources/materialize_role/import.sh index 9e6dd18d..a9904507 100644 --- a/examples/resources/materialize_role/import.sh +++ b/examples/resources/materialize_role/import.sh @@ -1,4 +1,5 @@ # Roles can be imported using the role id: -terraform import materialize_role.example_role +terraform import materialize_role.example_role : # Role id and information be found in the `mz_catalog.mz_roles` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_schema/import.sh b/examples/resources/materialize_schema/import.sh index 22f97f5f..a1c93472 100644 --- a/examples/resources/materialize_schema/import.sh +++ b/examples/resources/materialize_schema/import.sh @@ -1,4 +1,5 @@ # Schemas can be imported using the schema id: -terraform import materialize_schema.example_schema +terraform import materialize_schema.example_schema : # Schema id and information be found in the `mz_catalog.mz_schemas` table +# The role is the role where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_secret/import.sh b/examples/resources/materialize_secret/import.sh index 515574c2..743e6104 100644 --- a/examples/resources/materialize_secret/import.sh +++ b/examples/resources/materialize_secret/import.sh @@ -1,4 +1,5 @@ # Secrets can be imported using the secret id: -terraform import materialize_secret.example_secret +terraform import materialize_secret.example_secret : # Secret id and information be found in the `mz_catalog.mz_secrets` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_sink_kafka/import.sh b/examples/resources/materialize_sink_kafka/import.sh index 673901e8..c2de2231 100644 --- a/examples/resources/materialize_sink_kafka/import.sh +++ b/examples/resources/materialize_sink_kafka/import.sh @@ -1,4 +1,5 @@ # Sinks can be imported using the sink id: -terraform import materialize_sink_kafka.example_sink_kafka +terraform import materialize_sink_kafka.example_sink_kafka : # Sink id and information be found in the `mz_catalog.mz_sinks` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_source_kafka/import.sh b/examples/resources/materialize_source_kafka/import.sh index 090ae504..50e66884 100644 --- a/examples/resources/materialize_source_kafka/import.sh +++ b/examples/resources/materialize_source_kafka/import.sh @@ -1,4 +1,5 @@ # Sources can be imported using the source id: -terraform import materialize_source_kafka.example_source_kafka +terraform import materialize_source_kafka.example_source_kafka : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_source_load_generator/import.sh b/examples/resources/materialize_source_load_generator/import.sh index b1a61b17..e6606ee9 100644 --- a/examples/resources/materialize_source_load_generator/import.sh +++ b/examples/resources/materialize_source_load_generator/import.sh @@ -1,4 +1,5 @@ # Sources can be imported using the source id: -terraform import materialize_source_load_generator.example_source_load_generator +terraform import materialize_source_load_generator.example_source_load_generator : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_source_postgres/import.sh b/examples/resources/materialize_source_postgres/import.sh index 9e82cc2c..b288d9ee 100644 --- a/examples/resources/materialize_source_postgres/import.sh +++ b/examples/resources/materialize_source_postgres/import.sh @@ -1,4 +1,5 @@ # Sources can be imported using the source id: -terraform import materialize_source_postgres.example_source_postgres +terraform import materialize_source_postgres.example_source_postgres : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_source_webhook/import.sh b/examples/resources/materialize_source_webhook/import.sh index e475c347..33e1ff81 100644 --- a/examples/resources/materialize_source_webhook/import.sh +++ b/examples/resources/materialize_source_webhook/import.sh @@ -1,4 +1,5 @@ # Sources can be imported using the source id: -terraform import materialize_source_webhook.example_source_webhook +terraform import materialize_source_webhook.example_source_webhook : # Source id and information be found in the `mz_catalog.mz_sources` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_table/import.sh b/examples/resources/materialize_table/import.sh index 3475c477..a22c4e16 100644 --- a/examples/resources/materialize_table/import.sh +++ b/examples/resources/materialize_table/import.sh @@ -1,4 +1,5 @@ # Tables can be imported using the table id: -terraform import materialize_table.example_table +terraform import materialize_table.example_table : # Table id and information be found in the `mz_catalog.mz_tables` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_type/import.sh b/examples/resources/materialize_type/import.sh index f20d98d0..311b70ba 100644 --- a/examples/resources/materialize_type/import.sh +++ b/examples/resources/materialize_type/import.sh @@ -1,4 +1,5 @@ # Types can be imported using the type id: -terraform import materialize_type.example_type +terraform import materialize_type.example_type : # Type id and information be found in the `mz_catalog.mz_types` table +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/examples/resources/materialize_view/import.sh b/examples/resources/materialize_view/import.sh index 9aef80ee..cce5a990 100644 --- a/examples/resources/materialize_view/import.sh +++ b/examples/resources/materialize_view/import.sh @@ -1,4 +1,5 @@ # Views can be imported using the view id: -terraform import materialize_view.example_view +terraform import materialize_view.example_view : # View id and information be found in the `mz_catalog.mz_views` +# The region is the region where the database is located (e.g. aws/us-east-1) diff --git a/pkg/datasources/datasource_cluster.go b/pkg/datasources/datasource_cluster.go index bbb367b8..5a610c4c 100644 --- a/pkg/datasources/datasource_cluster.go +++ b/pkg/datasources/datasource_cluster.go @@ -4,6 +4,7 @@ import ( "context" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -77,6 +78,6 @@ func clusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) return diag.FromErr(err) } - d.SetId("clusters") + d.SetId(utils.TransformIdWithRegion("clusters")) return diags } diff --git a/pkg/datasources/datasource_cluster_replica.go b/pkg/datasources/datasource_cluster_replica.go index 2241e6d9..35384cbb 100644 --- a/pkg/datasources/datasource_cluster_replica.go +++ b/pkg/datasources/datasource_cluster_replica.go @@ -4,6 +4,7 @@ import ( "context" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -77,6 +78,6 @@ func clusterReplicaRead(ctx context.Context, d *schema.ResourceData, meta interf return diag.FromErr(err) } - d.SetId("cluster_replicas") + d.SetId(utils.TransformIdWithRegion("cluster_replicas")) return diags } diff --git a/pkg/datasources/datasource_current_cluster.go b/pkg/datasources/datasource_current_cluster.go index fdfc34f3..a25c105a 100644 --- a/pkg/datasources/datasource_current_cluster.go +++ b/pkg/datasources/datasource_current_cluster.go @@ -3,6 +3,7 @@ package datasources import ( "context" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/jmoiron/sqlx" @@ -28,7 +29,7 @@ func currentClusterRead(ctx context.Context, d *schema.ResourceData, meta interf conn.QueryRow("SHOW CLUSTER;").Scan(&name) d.Set("name", name) - d.SetId("current_cluster") + d.SetId(utils.TransformIdWithRegion("current_cluster")) return diags } diff --git a/pkg/datasources/datasource_current_database.go b/pkg/datasources/datasource_current_database.go index d71e5f89..9f53d01a 100644 --- a/pkg/datasources/datasource_current_database.go +++ b/pkg/datasources/datasource_current_database.go @@ -3,6 +3,7 @@ package datasources import ( "context" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/jmoiron/sqlx" @@ -28,7 +29,7 @@ func currentDatabaseRead(ctx context.Context, d *schema.ResourceData, meta inter conn.QueryRow("SHOW DATABASE;").Scan(&name) d.Set("name", name) - d.SetId("current_database") + d.SetId(utils.TransformIdWithRegion("current_database")) return diags } diff --git a/pkg/datasources/datasource_egress_ips.go b/pkg/datasources/datasource_egress_ips.go index 600c3522..eba3db4b 100644 --- a/pkg/datasources/datasource_egress_ips.go +++ b/pkg/datasources/datasource_egress_ips.go @@ -7,6 +7,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/jmoiron/sqlx" @@ -64,7 +65,7 @@ func EgressIpsRead(ctx context.Context, d *schema.ResourceData, meta interface{} return diag.FromErr(err) } - d.SetId("egress_ips") + d.SetId(utils.TransformIdWithRegion("egress_ips")) return diags } diff --git a/pkg/datasources/datasource_role.go b/pkg/datasources/datasource_role.go index 78b02b21..ac829671 100644 --- a/pkg/datasources/datasource_role.go +++ b/pkg/datasources/datasource_role.go @@ -4,6 +4,7 @@ import ( "context" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -57,6 +58,6 @@ func roleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia return diag.FromErr(err) } - d.SetId("roles") + d.SetId(utils.TransformIdWithRegion("roles")) return diags } diff --git a/pkg/datasources/datasource_schema.go b/pkg/datasources/datasource_schema.go index 33d38837..e80ccdad 100644 --- a/pkg/datasources/datasource_schema.go +++ b/pkg/datasources/datasource_schema.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -72,9 +73,9 @@ func schemaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d if databaseName != "" { id := fmt.Sprintf("%s|schemas", databaseName) - d.SetId(id) + d.SetId(utils.TransformIdWithRegion(id)) } else { - d.SetId("schemas") + d.SetId(utils.TransformIdWithRegion("schemas")) } return diags diff --git a/pkg/datasources/utils.go b/pkg/datasources/utils.go index 7b2f2a74..7c2b391a 100644 --- a/pkg/datasources/utils.go +++ b/pkg/datasources/utils.go @@ -3,6 +3,7 @@ package datasources import ( "fmt" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -16,5 +17,5 @@ func SetId(resource, databaseName, schemaName string, d *schema.ResourceData) { id = resource } - d.SetId(id) + d.SetId(utils.TransformIdWithRegion(id)) } diff --git a/pkg/provider/acceptance_cluster_replica_test.go b/pkg/provider/acceptance_cluster_replica_test.go index 63f8d49e..ae03fadf 100644 --- a/pkg/provider/acceptance_cluster_replica_test.go +++ b/pkg/provider/acceptance_cluster_replica_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -136,7 +137,7 @@ func testAccCheckClusterReplicaExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("cluster replica not found: %s", name) } - _, err := materialize.ScanClusterReplica(db, r.Primary.ID) + _, err := materialize.ScanClusterReplica(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -149,9 +150,9 @@ func testAccCheckAllClusterReplicaDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanClusterReplica(db, r.Primary.ID) + _, err := materialize.ScanClusterReplica(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Cluster replica %v still exists", r.Primary.ID) + return fmt.Errorf("Cluster replica %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_cluster_test.go b/pkg/provider/acceptance_cluster_test.go index d33b3625..9849cd80 100644 --- a/pkg/provider/acceptance_cluster_test.go +++ b/pkg/provider/acceptance_cluster_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -375,7 +376,7 @@ func testAccCheckClusterExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("cluster not found: %s", name) } - _, err := materialize.ScanCluster(db, r.Primary.ID) + _, err := materialize.ScanCluster(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -388,9 +389,9 @@ func testAccCheckAllClusterDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanCluster(db, r.Primary.ID) + _, err := materialize.ScanCluster(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Cluster %v still exists", r.Primary.ID) + return fmt.Errorf("Cluster %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_connection_confluent_schema_registry_test.go b/pkg/provider/acceptance_connection_confluent_schema_registry_test.go index 15d8f731..6bc96f38 100644 --- a/pkg/provider/acceptance_connection_confluent_schema_registry_test.go +++ b/pkg/provider/acceptance_connection_confluent_schema_registry_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -129,7 +130,7 @@ func testAccCheckConnConfluentSchemaRegistryExists(name string) resource.TestChe if !ok { return fmt.Errorf("connection confluent schema registry not found: %s", name) } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -142,9 +143,9 @@ func testAccCheckAllConnConfluentSchemaRegistryDestroyed(s *terraform.State) err continue } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("connection %v still exists", r.Primary.ID) + return fmt.Errorf("connection %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_connection_kafka_test.go b/pkg/provider/acceptance_connection_kafka_test.go index 8e958607..b406b276 100644 --- a/pkg/provider/acceptance_connection_kafka_test.go +++ b/pkg/provider/acceptance_connection_kafka_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -267,7 +268,7 @@ func testAccCheckConnKafkaExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("connection kafka not found: %s", name) } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -280,9 +281,9 @@ func testAccCheckAllConnKafkaDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("connection %v still exists", r.Primary.ID) + return fmt.Errorf("connection %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_connection_postgres_test.go b/pkg/provider/acceptance_connection_postgres_test.go index c82944d6..3ffcb692 100644 --- a/pkg/provider/acceptance_connection_postgres_test.go +++ b/pkg/provider/acceptance_connection_postgres_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -165,7 +166,7 @@ func testAccCheckConnPostgresExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("connection postgres not found: %s", name) } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -178,9 +179,9 @@ func testAccCheckAllConnPostgresDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanConnection(db, r.Primary.ID) + _, err := materialize.ScanConnection(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("connection %v still exists", r.Primary.ID) + return fmt.Errorf("connection %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_connection_ssh_tunnel_test.go b/pkg/provider/acceptance_connection_ssh_tunnel_test.go index 6de0052c..be662ba9 100644 --- a/pkg/provider/acceptance_connection_ssh_tunnel_test.go +++ b/pkg/provider/acceptance_connection_ssh_tunnel_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -139,7 +140,7 @@ func testAccCheckConnSshTunnelExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("connection ssh tunnel not found: %s", name) } - _, err := materialize.ScanConnectionSshTunnel(db, r.Primary.ID) + _, err := materialize.ScanConnectionSshTunnel(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -152,9 +153,9 @@ func testAccCheckAllConnSshTunnelDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanConnectionSshTunnel(db, r.Primary.ID) + _, err := materialize.ScanConnectionSshTunnel(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("connection %v still exists", r.Primary.ID) + return fmt.Errorf("connection %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_index_test.go b/pkg/provider/acceptance_index_test.go index 0043f440..8d1400ff 100644 --- a/pkg/provider/acceptance_index_test.go +++ b/pkg/provider/acceptance_index_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -159,7 +160,7 @@ func testAccCheckIndexExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("index not found: %s", name) } - _, err := materialize.ScanIndex(db, r.Primary.ID) + _, err := materialize.ScanIndex(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -180,9 +181,9 @@ func testAccCheckAllIndexDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanIndex(db, r.Primary.ID) + _, err := materialize.ScanIndex(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("index %v still exists", r.Primary.ID) + return fmt.Errorf("index %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_materialized_view_test.go b/pkg/provider/acceptance_materialized_view_test.go index 51634345..5ad31b27 100644 --- a/pkg/provider/acceptance_materialized_view_test.go +++ b/pkg/provider/acceptance_materialized_view_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -143,7 +144,7 @@ func testAccCheckMaterializedViewExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("Materialized View not found: %s", name) } - _, err := materialize.ScanMaterializedView(db, r.Primary.ID) + _, err := materialize.ScanMaterializedView(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -156,9 +157,9 @@ func testAccCheckAllMaterializedViewsDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanMaterializedView(db, r.Primary.ID) + _, err := materialize.ScanMaterializedView(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Materialized View %v still exists", r.Primary.ID) + return fmt.Errorf("Materialized View %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_role_test.go b/pkg/provider/acceptance_role_test.go index 61d6a35c..e24939b1 100644 --- a/pkg/provider/acceptance_role_test.go +++ b/pkg/provider/acceptance_role_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -110,7 +111,7 @@ func testAccCheckRoleExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("role not found: %s", name) } - _, err := materialize.ScanRole(db, r.Primary.ID) + _, err := materialize.ScanRole(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -123,9 +124,9 @@ func testAccCheckAllRolesDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanRole(db, r.Primary.ID) + _, err := materialize.ScanRole(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("role %v still exists", r.Primary.ID) + return fmt.Errorf("role %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_schema_test.go b/pkg/provider/acceptance_schema_test.go index 5d29a743..5cdd1d4a 100644 --- a/pkg/provider/acceptance_schema_test.go +++ b/pkg/provider/acceptance_schema_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -132,7 +133,7 @@ func testAccCheckSchemaExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("Schema not found: %s", name) } - _, err := materialize.ScanSchema(db, r.Primary.ID) + _, err := materialize.ScanSchema(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -145,9 +146,9 @@ func testAccCheckAllSchemasDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSchema(db, r.Primary.ID) + _, err := materialize.ScanSchema(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Schema %v still exists", r.Primary.ID) + return fmt.Errorf("Schema %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_secret_test.go b/pkg/provider/acceptance_secret_test.go index 0127b9b3..3e3e0dd3 100644 --- a/pkg/provider/acceptance_secret_test.go +++ b/pkg/provider/acceptance_secret_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -140,7 +141,7 @@ func testAccCheckSecretExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("secret not found: %s", name) } - _, err := materialize.ScanSecret(db, r.Primary.ID) + _, err := materialize.ScanSecret(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -153,9 +154,9 @@ func testAccCheckAllSecretsDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSecret(db, r.Primary.ID) + _, err := materialize.ScanSecret(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("secret %v still exists", r.Primary.ID) + return fmt.Errorf("secret %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_sink_kafka_test.go b/pkg/provider/acceptance_sink_kafka_test.go index e201fd7d..1998df48 100644 --- a/pkg/provider/acceptance_sink_kafka_test.go +++ b/pkg/provider/acceptance_sink_kafka_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -200,7 +201,7 @@ func testAccCheckSinkKafkaExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("sink kafka not found: %s", name) } - _, err := materialize.ScanSink(db, r.Primary.ID) + _, err := materialize.ScanSink(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -221,9 +222,9 @@ func testAccCheckAllSinkKafkaDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSink(db, r.Primary.ID) + _, err := materialize.ScanSink(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("sink %v still exists", r.Primary.ID) + return fmt.Errorf("sink %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_source_kafka_test.go b/pkg/provider/acceptance_source_kafka_test.go index 3743106f..8ee69c75 100644 --- a/pkg/provider/acceptance_source_kafka_test.go +++ b/pkg/provider/acceptance_source_kafka_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -319,7 +320,7 @@ func testAccCheckSourceKafkaExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("source kafka not found: %s", name) } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -332,9 +333,9 @@ func testAccCheckAllSourceKafkaDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("source %v still exists", r.Primary.ID) + return fmt.Errorf("source %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_source_load_generator_test.go b/pkg/provider/acceptance_source_load_generator_test.go index f2d09660..264c97ab 100644 --- a/pkg/provider/acceptance_source_load_generator_test.go +++ b/pkg/provider/acceptance_source_load_generator_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -305,7 +306,7 @@ func testAccCheckSourceLoadGeneratorExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("SourceLoadGenerator not found: %s", name) } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -326,9 +327,9 @@ func testAccCheckAllSourceLoadGeneratorsDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("SourceLoadGenerator %v still exists", r.Primary.ID) + return fmt.Errorf("SourceLoadGenerator %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_source_postgres_test.go b/pkg/provider/acceptance_source_postgres_test.go index 9f73854d..54bbc20f 100644 --- a/pkg/provider/acceptance_source_postgres_test.go +++ b/pkg/provider/acceptance_source_postgres_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -363,7 +364,7 @@ func testAccCheckSourcePostgresExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("source postgres not found: %s", name) } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -376,9 +377,9 @@ func testAccCheckAllSourcePostgresDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("source %v still exists", r.Primary.ID) + return fmt.Errorf("source %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_source_webhook_test.go b/pkg/provider/acceptance_source_webhook_test.go index acf5e64f..5b1b275a 100644 --- a/pkg/provider/acceptance_source_webhook_test.go +++ b/pkg/provider/acceptance_source_webhook_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -336,7 +337,7 @@ func testAccCheckSourceWebhookExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("source webhook not found: %s", name) } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -349,9 +350,9 @@ func testAccCheckAllSourceWebhookDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanSource(db, r.Primary.ID) + _, err := materialize.ScanSource(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("source %v still exists", r.Primary.ID) + return fmt.Errorf("source %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_table_test.go b/pkg/provider/acceptance_table_test.go index 03e6abc3..cbda9629 100644 --- a/pkg/provider/acceptance_table_test.go +++ b/pkg/provider/acceptance_table_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -223,7 +224,7 @@ func testAccCheckTableExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("Table not found: %s", name) } - _, err := materialize.ScanTable(db, r.Primary.ID) + _, err := materialize.ScanTable(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -236,9 +237,9 @@ func testAccCheckAllTablesDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanTable(db, r.Primary.ID) + _, err := materialize.ScanTable(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Table %v still exists", r.Primary.ID) + return fmt.Errorf("Table %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_type_test.go b/pkg/provider/acceptance_type_test.go index 0a29e98d..44faee7e 100644 --- a/pkg/provider/acceptance_type_test.go +++ b/pkg/provider/acceptance_type_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -228,7 +229,7 @@ func testAccCheckTypeExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("Type not found: %s", name) } - _, err := materialize.ScanType(db, r.Primary.ID) + _, err := materialize.ScanType(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -241,9 +242,9 @@ func testAccCheckAllTypesDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanType(db, r.Primary.ID) + _, err := materialize.ScanType(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("Type %v still exists", r.Primary.ID) + return fmt.Errorf("Type %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/provider/acceptance_view_test.go b/pkg/provider/acceptance_view_test.go index 30970a6a..fc504bb5 100644 --- a/pkg/provider/acceptance_view_test.go +++ b/pkg/provider/acceptance_view_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -142,7 +143,7 @@ func testAccCheckViewExists(name string) resource.TestCheckFunc { if !ok { return fmt.Errorf("View not found: %s", name) } - _, err := materialize.ScanView(db, r.Primary.ID) + _, err := materialize.ScanView(db, utils.ExtractId(r.Primary.ID)) return err } } @@ -155,9 +156,9 @@ func testAccCheckAllViewsDestroyed(s *terraform.State) error { continue } - _, err := materialize.ScanView(db, r.Primary.ID) + _, err := materialize.ScanView(db, utils.ExtractId(r.Primary.ID)) if err == nil { - return fmt.Errorf("View %v still exists", r.Primary.ID) + return fmt.Errorf("View %v still exists", utils.ExtractId(r.Primary.ID)) } else if err != sql.ErrNoRows { return err } diff --git a/pkg/resources/resource_cluster.go b/pkg/resources/resource_cluster.go index b586ee92..7166b006 100644 --- a/pkg/resources/resource_cluster.go +++ b/pkg/resources/resource_cluster.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -56,7 +57,7 @@ func Cluster() *schema.Resource { func clusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanCluster(meta.(*sqlx.DB), i) + s, err := materialize.ScanCluster(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -64,7 +65,7 @@ func clusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ClusterName.String); err != nil { return diag.FromErr(err) @@ -163,7 +164,7 @@ func clusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{} if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return clusterRead(ctx, d, meta) } diff --git a/pkg/resources/resource_cluster_replica.go b/pkg/resources/resource_cluster_replica.go index 76a4f53e..227e3026 100644 --- a/pkg/resources/resource_cluster_replica.go +++ b/pkg/resources/resource_cluster_replica.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -52,7 +53,7 @@ func ClusterReplica() *schema.Resource { func clusterReplicaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanClusterReplica(meta.(*sqlx.DB), i) + s, err := materialize.ScanClusterReplica(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -60,7 +61,7 @@ func clusterReplicaRead(ctx context.Context, d *schema.ResourceData, meta interf return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ReplicaName.String); err != nil { return diag.FromErr(err) @@ -145,7 +146,7 @@ func clusterReplicaCreate(ctx context.Context, d *schema.ResourceData, meta inte if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return clusterReplicaRead(ctx, d, meta) } diff --git a/pkg/resources/resource_connection.go b/pkg/resources/resource_connection.go index fa69a62b..99e631ed 100644 --- a/pkg/resources/resource_connection.go +++ b/pkg/resources/resource_connection.go @@ -5,6 +5,7 @@ import ( "database/sql" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -14,7 +15,7 @@ import ( func connectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanConnection(meta.(*sqlx.DB), i) + s, err := materialize.ScanConnection(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -22,7 +23,7 @@ func connectionRead(ctx context.Context, d *schema.ResourceData, meta interface{ return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ConnectionName.String); err != nil { return diag.FromErr(err) diff --git a/pkg/resources/resource_connection_aws_privatelink.go b/pkg/resources/resource_connection_aws_privatelink.go index bf4bd8fe..48ce18d8 100644 --- a/pkg/resources/resource_connection_aws_privatelink.go +++ b/pkg/resources/resource_connection_aws_privatelink.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -67,7 +68,7 @@ type ConnectionAwsPrivatelinkParams struct { func connectionAwsPrivatelinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanConnectionAwsPrivatelink(meta.(*sqlx.DB), i) + s, err := materialize.ScanConnectionAwsPrivatelink(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -75,7 +76,7 @@ func connectionAwsPrivatelinkRead(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ConnectionName.String); err != nil { return diag.FromErr(err) @@ -158,7 +159,7 @@ func connectionAwsPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return connectionAwsPrivatelinkRead(ctx, d, meta) } diff --git a/pkg/resources/resource_connection_confluent_schema_registry.go b/pkg/resources/resource_connection_confluent_schema_registry.go index f2cace1c..9c9039f0 100644 --- a/pkg/resources/resource_connection_confluent_schema_registry.go +++ b/pkg/resources/resource_connection_confluent_schema_registry.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -133,7 +134,7 @@ func connectionConfluentSchemaRegistryCreate(ctx context.Context, d *schema.Reso if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return connectionRead(ctx, d, meta) } diff --git a/pkg/resources/resource_connection_kafka.go b/pkg/resources/resource_connection_kafka.go index c4e163fe..ea33e9da 100644 --- a/pkg/resources/resource_connection_kafka.go +++ b/pkg/resources/resource_connection_kafka.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -192,7 +193,7 @@ func connectionKafkaCreate(ctx context.Context, d *schema.ResourceData, meta int if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return connectionRead(ctx, d, meta) } diff --git a/pkg/resources/resource_connection_postgres.go b/pkg/resources/resource_connection_postgres.go index eb1923aa..44acbd79 100644 --- a/pkg/resources/resource_connection_postgres.go +++ b/pkg/resources/resource_connection_postgres.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -169,7 +170,7 @@ func connectionPostgresCreate(ctx context.Context, d *schema.ResourceData, meta if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return connectionRead(ctx, d, meta) } diff --git a/pkg/resources/resource_connection_ssh_tunnel.go b/pkg/resources/resource_connection_ssh_tunnel.go index a9551818..93ec6e54 100644 --- a/pkg/resources/resource_connection_ssh_tunnel.go +++ b/pkg/resources/resource_connection_ssh_tunnel.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -69,7 +70,7 @@ func ConnectionSshTunnel() *schema.Resource { func connectionSshTunnelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanConnectionSshTunnel(meta.(*sqlx.DB), i) + s, err := materialize.ScanConnectionSshTunnel(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -77,7 +78,7 @@ func connectionSshTunnelRead(ctx context.Context, d *schema.ResourceData, meta i return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ConnectionName.String); err != nil { return diag.FromErr(err) @@ -159,7 +160,7 @@ func connectionSshTunnelCreate(ctx context.Context, d *schema.ResourceData, meta if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return connectionSshTunnelRead(ctx, d, meta) } diff --git a/pkg/resources/resource_database.go b/pkg/resources/resource_database.go index 3bcfb980..872d60c0 100644 --- a/pkg/resources/resource_database.go +++ b/pkg/resources/resource_database.go @@ -19,13 +19,6 @@ var databaseSchema = map[string]*schema.Schema{ "ownership_role": OwnershipRoleSchema(), } -// Define the V0 schema function -func databaseSchemaV0() *schema.Resource { - return &schema.Resource{ - Schema: databaseSchema, - } -} - func Database() *schema.Resource { return &schema.Resource{ Description: "The highest level namespace hierarchy in Materialize.", @@ -39,15 +32,7 @@ func Database() *schema.Resource { StateContext: schema.ImportStatePassthroughContext, }, - Schema: databaseSchema, - SchemaVersion: 1, - StateUpgraders: []schema.StateUpgrader{ - { - Type: databaseSchemaV0().CoreConfigSchema().ImpliedType(), - Upgrade: utils.IdStateUpgradeV0, - Version: 0, - }, - }, + Schema: databaseSchema, } } @@ -117,7 +102,6 @@ func databaseCreate(ctx context.Context, d *schema.ResourceData, meta interface{ if err != nil { return diag.FromErr(err) } - d.SetId(utils.TransformIdWithRegion(i)) return databaseRead(ctx, d, meta) diff --git a/pkg/resources/resource_index.go b/pkg/resources/resource_index.go index 73478097..93352478 100644 --- a/pkg/resources/resource_index.go +++ b/pkg/resources/resource_index.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -91,7 +92,7 @@ func Index() *schema.Resource { func indexRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanIndex(meta.(*sqlx.DB), i) + s, err := materialize.ScanIndex(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -99,7 +100,7 @@ func indexRead(ctx context.Context, d *schema.ResourceData, meta interface{}) di return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.IndexName.String); err != nil { return diag.FromErr(err) @@ -123,7 +124,7 @@ func indexRead(ctx context.Context, d *schema.ResourceData, meta interface{}) di } // Index columns - indexColumns, err := materialize.ListIndexColumns(meta.(*sqlx.DB), i) + indexColumns, err := materialize.ListIndexColumns(meta.(*sqlx.DB), utils.ExtractId(i)) if err != nil { return diag.FromErr(err) } @@ -192,7 +193,7 @@ func indexCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return indexRead(ctx, d, meta) } diff --git a/pkg/resources/resource_materialized_view.go b/pkg/resources/resource_materialized_view.go index 19a7204e..42f5d3c7 100644 --- a/pkg/resources/resource_materialized_view.go +++ b/pkg/resources/resource_materialized_view.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -63,7 +64,7 @@ func MaterializedView() *schema.Resource { func materializedViewRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanMaterializedView(meta.(*sqlx.DB), i) + s, err := materialize.ScanMaterializedView(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -71,7 +72,7 @@ func materializedViewRead(ctx context.Context, d *schema.ResourceData, meta inte return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.MaterializedViewName.String); err != nil { return diag.FromErr(err) @@ -158,7 +159,7 @@ func materializedViewCreate(ctx context.Context, d *schema.ResourceData, meta in if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return materializedViewRead(ctx, d, meta) } diff --git a/pkg/resources/resource_role.go b/pkg/resources/resource_role.go index 7118cd68..b1b0ee96 100644 --- a/pkg/resources/resource_role.go +++ b/pkg/resources/resource_role.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -42,7 +43,7 @@ func Role() *schema.Resource { func roleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanRole(meta.(*sqlx.DB), i) + s, err := materialize.ScanRole(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -50,7 +51,7 @@ func roleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.RoleName.String); err != nil { return diag.FromErr(err) @@ -103,7 +104,7 @@ func roleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return roleRead(ctx, d, meta) } diff --git a/pkg/resources/resource_schema.go b/pkg/resources/resource_schema.go index 7fdf74f7..46bd936a 100644 --- a/pkg/resources/resource_schema.go +++ b/pkg/resources/resource_schema.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -39,7 +40,7 @@ func Schema() *schema.Resource { func schemaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanSchema(meta.(*sqlx.DB), i) + s, err := materialize.ScanSchema(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -47,7 +48,7 @@ func schemaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.SchemaName.String); err != nil { return diag.FromErr(err) @@ -112,7 +113,7 @@ func schemaCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return schemaRead(ctx, d, meta) } diff --git a/pkg/resources/resource_secret.go b/pkg/resources/resource_secret.go index f199e6de..aafa3d0c 100644 --- a/pkg/resources/resource_secret.go +++ b/pkg/resources/resource_secret.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -47,7 +48,7 @@ func Secret() *schema.Resource { func secretRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanSecret(meta.(*sqlx.DB), i) + s, err := materialize.ScanSecret(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -55,7 +56,7 @@ func secretRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.SecretName.String); err != nil { return diag.FromErr(err) @@ -129,7 +130,7 @@ func secretCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return secretRead(ctx, d, meta) } diff --git a/pkg/resources/resource_sink.go b/pkg/resources/resource_sink.go index f3a797cd..29716992 100644 --- a/pkg/resources/resource_sink.go +++ b/pkg/resources/resource_sink.go @@ -5,6 +5,7 @@ import ( "database/sql" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -14,7 +15,7 @@ import ( func sinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanSink(meta.(*sqlx.DB), i) + s, err := materialize.ScanSink(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -22,7 +23,7 @@ func sinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.SinkName.String); err != nil { return diag.FromErr(err) diff --git a/pkg/resources/resource_sink_kafka.go b/pkg/resources/resource_sink_kafka.go index 4d4a458a..7b4e737f 100644 --- a/pkg/resources/resource_sink_kafka.go +++ b/pkg/resources/resource_sink_kafka.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -179,7 +180,7 @@ func sinkKafkaCreate(ctx context.Context, d *schema.ResourceData, meta any) diag if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return sinkRead(ctx, d, meta) } diff --git a/pkg/resources/resource_source.go b/pkg/resources/resource_source.go index c42a7c01..12a115ad 100644 --- a/pkg/resources/resource_source.go +++ b/pkg/resources/resource_source.go @@ -5,6 +5,7 @@ import ( "database/sql" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -14,7 +15,7 @@ import ( func sourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanSource(meta.(*sqlx.DB), i) + s, err := materialize.ScanSource(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -22,7 +23,7 @@ func sourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.SourceName.String); err != nil { return diag.FromErr(err) @@ -58,7 +59,7 @@ func sourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d } // Subsources - deps, err := materialize.ListDependencies(meta.(*sqlx.DB), i, "source") + deps, err := materialize.ListDependencies(meta.(*sqlx.DB), utils.ExtractId(i), "source") if err != nil { return diag.FromErr(err) } diff --git a/pkg/resources/resource_source_kafka.go b/pkg/resources/resource_source_kafka.go index 3c954e59..ebf77526 100644 --- a/pkg/resources/resource_source_kafka.go +++ b/pkg/resources/resource_source_kafka.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -290,7 +291,7 @@ func sourceKafkaCreate(ctx context.Context, d *schema.ResourceData, meta any) di if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return sourceRead(ctx, d, meta) } diff --git a/pkg/resources/resource_source_load_generator.go b/pkg/resources/resource_source_load_generator.go index 34589543..216661bf 100644 --- a/pkg/resources/resource_source_load_generator.go +++ b/pkg/resources/resource_source_load_generator.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -208,7 +209,7 @@ func sourceLoadgenCreate(ctx context.Context, d *schema.ResourceData, meta any) if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return sourceRead(ctx, d, meta) } diff --git a/pkg/resources/resource_source_postgres.go b/pkg/resources/resource_source_postgres.go index 435bc629..6fba1493 100644 --- a/pkg/resources/resource_source_postgres.go +++ b/pkg/resources/resource_source_postgres.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -161,7 +162,7 @@ func sourcePostgresCreate(ctx context.Context, d *schema.ResourceData, meta any) if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return sourceRead(ctx, d, meta) } diff --git a/pkg/resources/resource_source_webhook.go b/pkg/resources/resource_source_webhook.go index 9d153625..d3c7a0e2 100644 --- a/pkg/resources/resource_source_webhook.go +++ b/pkg/resources/resource_source_webhook.go @@ -5,6 +5,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -272,7 +273,7 @@ func sourceWebhookCreate(ctx context.Context, d *schema.ResourceData, meta inter if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return sourceRead(ctx, d, meta) } diff --git a/pkg/resources/resource_table.go b/pkg/resources/resource_table.go index 0beafc71..4f51df72 100644 --- a/pkg/resources/resource_table.go +++ b/pkg/resources/resource_table.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -86,7 +87,7 @@ func Table() *schema.Resource { func tableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanTable(meta.(*sqlx.DB), i) + s, err := materialize.ScanTable(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -94,7 +95,7 @@ func tableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) di return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.TableName.String); err != nil { return diag.FromErr(err) @@ -122,7 +123,7 @@ func tableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) di } // Table columns - tableColumns, err := materialize.ListTableColumns(meta.(*sqlx.DB), i) + tableColumns, err := materialize.ListTableColumns(meta.(*sqlx.DB), utils.ExtractId(i)) if err != nil { log.Print("[DEBUG] cannot query list tables") return diag.FromErr(err) @@ -208,7 +209,7 @@ func tableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return tableRead(ctx, d, meta) } diff --git a/pkg/resources/resource_type.go b/pkg/resources/resource_type.go index 257d674c..a7f1173d 100644 --- a/pkg/resources/resource_type.go +++ b/pkg/resources/resource_type.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -109,7 +110,7 @@ func Type() *schema.Resource { func typeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanType(meta.(*sqlx.DB), i) + s, err := materialize.ScanType(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -117,7 +118,7 @@ func typeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.TypeName.String); err != nil { return diag.FromErr(err) @@ -206,7 +207,7 @@ func typeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return typeRead(ctx, d, meta) } diff --git a/pkg/resources/resource_view.go b/pkg/resources/resource_view.go index d25730ed..30e442fb 100644 --- a/pkg/resources/resource_view.go +++ b/pkg/resources/resource_view.go @@ -6,6 +6,7 @@ import ( "log" "github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize" + "github.com/MaterializeInc/terraform-provider-materialize/pkg/utils" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -47,7 +48,7 @@ func View() *schema.Resource { func viewRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { i := d.Id() - s, err := materialize.ScanView(meta.(*sqlx.DB), i) + s, err := materialize.ScanView(meta.(*sqlx.DB), utils.ExtractId(i)) if err == sql.ErrNoRows { d.SetId("") return nil @@ -55,7 +56,7 @@ func viewRead(ctx context.Context, d *schema.ResourceData, meta interface{}) dia return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) if err := d.Set("name", s.ViewName.String); err != nil { return diag.FromErr(err) @@ -129,7 +130,7 @@ func viewCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d if err != nil { return diag.FromErr(err) } - d.SetId(i) + d.SetId(utils.TransformIdWithRegion(i)) return viewRead(ctx, d, meta) }