Model sync from BigQuery to Salesforce

To create a model sync from BigQuery to Salesforce using Terraform with the Polytomic provider, follow these steps:

Prerequisites: • Ensure you have the Polytomic Terraform provider installed. • Obtain your Polytomic API key and set it as an environment variable:

1. Configure the Polytomic Provider

🚧 Prerelease

The Polytomic Terraform provider is currently available as pre-release software. Until we reach version 1.0, the beta version must be set explicitly.

Begin by configuring the Polytomic provider in your Terraform script:

1terraform {
2 required_providers {
3 polytomic = {
4 source = "polytomic/polytomic"
5 version = "1.0.0-beta1"
6 }
7 }
8}
9
10provider "polytomic" {
11 api_key = var.polytomic_api_key
12}

Ensure that var.polytomic_api_key is defined in your variables or passed appropriately.

🤝 Partner keys

If you are using a Partner Key, specify the key, along with an organization user email. A user with that email will be used when operating on an organization. The user will be created if it does not exist.

1provider "polytomic" {
2 partner_key = "<value from settings page>"
3 organization_user = "terraform@polytomic.com"
4}

2. Create a BigQuery Connection

Define a resource for the BigQuery connection:

1resource "polytomic_bigquery_connection" "user_data" {
2 name = "BigQuery Users"
3
4 configuration = {
5 project_id = "polytomic-integration-test"
6 service_account = file("bq.json")
7 }
8}

Note that the service account key is loaded using the file function here; any string value or variable is acceptable.

3. Create a Salesforce Connection

Polytomic supports a few different authorization mechanisms for Salesforce connections. In order to manage a Salesforce connection via Terraform, the client ID & secret must be provided. If you want to use Polytomic’s OAuth flow for Salesforce connections, those must be created in the application; after that they may be referenced using the Terraform datasource.

Define a resource for the Salesforce connection:

1resource "polytomic_salesforce_connection" "sfdc" {
2 name = "Salesforce Connection (TF)"
3 configuration = {
4 connect_mode = "api"
5 domain = "my--sandbox.sandbox.my.salesforce.com"
6 client_id = var.sfdc_client_id
7 client_secret = var.sfdc_client_secret
8 oauth_refresh_token = var.oauth_token
9 }
10}

🤝 Parter keys

When using a partner key, the Organization ID must also be specified as a property for each resource.

4. Create a Model for user data

Define a resource for the data model that queries BigQuery:

1resource "polytomic_model" "users" {
2 name = "Users"
3 connection_id = polytomic_bigquery_connection.user_data.id
4 configuration = jsonencode({
5 dataset = "application"
6 table = "users"
7 })
8}

5. Create a Sync from Snowflake to Salesforce

Define a resource to sync the data model to Salesforce; in this example we’re creating an update-only sync to Salesforce Contacts which uses the email address to match records.

1resource "polytomic_sync" "update_contacts" {
2 name = "Update Contact Names"
3 mode = "update"
4 target = {
5 connection_id = polytomic_salesforce_connection.sfdc.id
6 object = "Contact"
7 }
8 identity = {
9 source = {
10 model_id = polytomic_model.users.id
11 field = "email"
12 }
13 function = "Equality"
14 target = "Email"
15 }
16 active = false
17 schedule = {
18 frequency = "manual"
19 }
20 fields = [
21 {
22 source = {
23 model_id = polytomic_model.users.id
24 field = "name"
25 }
26 target = "FirstName"
27 },
28 ]
29}

6. Apply the Terraform Configuration

Initialize Terraform and apply the configuration:

$ terraform init
$ terraform apply

Review the changes and confirm to proceed.

For more detailed information, refer to the Polytomic Terraform provider documentation.

Was this page helpful?