This page provides advanced examples that demonstrate more complex scenarios and configurations that go beyond basic resource creation.

Example 1: Creating a Materialized View with a source Data Pool with an access policy

This example shows how to create a Materialized View with a source Data Pool that has an access policy.

1

Create the source Data Pool

First, we create the source Data Pool with access control enabled. This is done using the propel_data_pool resource.

resource "propel_data_pool" "my_data_pool" {
  unique_name = "My Data Pool"
  description = "This is an example of a Data Pool"
  timestamp   = "date"

  access_control_enabled = true

  column {
    name     = "date"
    type     = "TIMESTAMP"
    nullable = false
  }
  column {
    name     = "account_id"
    type     = "STRING"
    nullable = false
  }
}
2

Create the access policy

Next, we create the access policy for the source Data Pool. This policy gives access to the Terraform application and any other Applications that you specify. We use the propel_data_pool_access_policy resource for this.

resource "propel_data_pool_access_policy" "my_terraform_policy" {
  unique_name = "Data Pool Access Policy"
  data_pool = propel_data_pool.my_data_pool.id

  columns = ["*"]
  applications = [ var.terraform_application_id ]
}
3

Create the Materialized View

Finally, we create the Materialized View. The challenge here is that the policy needs to be created before the Materialized View queries, otherwise it will not have access to the data. To avoid this, we use the Data Pool ID from the Data Pool Access Policy ${propel_data_pool_access_policy.my_terraform_policy.data_pool} so that Terraform will wait for the policy to be created before the Materialized View is created.

resource "propel_materialized_view" "my_materialized_view" {
  unique_name = "My Materialized View"
  sql = <<-SQL
    SELECT
      *
    FROM ${propel_data_pool_access_policy.my_terraform_policy.data_pool}
  SQL
}