Skip to main content

Terraform advanced examples

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.

In this example:

  1. First we create the source Data Pool with access control enabled.
  2. Then 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.
  3. 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_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
}
}

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 ]
}

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