Model sync (Reverse ETL) from BigQuery to LinkedIn Ads

Prerequisites:

To create a Model Sync from BigQuery to LinkedIn Ads using Terraform, follow these steps:

1. Configure the Polytomic provider

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"
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 LinkedIn Ads connection

In order to activate the required LinkedIn Ads API permissions, it’s best to create a LinkedIn Ads connection using Polytomic’s OAuth flow. This can be done in the admin console or using the Polytomic embedded authentication.

After establishing the connection, it can be referenced using the Terraform datasource.

4. Create a Polytomic source data model for a LinkedIn Ads audience

Define a resource for the data model that queries BigQuery:

1resource "polytomic_model" "audience_source" {
2 name = "LinkedIn Audience Source"
3 connection_id = polytomic_bigquery_connection.user_data.id
4
5 configuration = jsonencode({
6 query = "SELECT first_name, last_name, email FROM acme_inc.publicusers"
7 })
8
9 fields = ["email", first_name", "last_name"]
10}

5. Create a Model Sync from BigQuery to LinkedIn Ads

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

1resource "polytomic_sync" "bigquery_to_linkedin_ads_audience" {
2 name = "Audience to LinkedIn Ads Sync"
3 mode = "create"
4 active = true
5
6 schedule = {
7 frequency = "daily"
8 hour = "0"
9 minute = "0"
10 }
11
12 target = {
13 connection_id = data.polytomic_linkedinads_connection.destination.id
14 create = {
15 "name" : var.linkedin_audience_name,
16 "type" : "my_user_audience",
17 "account" : var.linkedin_ad_account
18 }
19 }
20
21 fields = [
22 {
23 source = {
24 model_id = polytomic_model.audience_source.id
25 field = "email"
26 }
27 target = "user_email"
28 },
29 {
30 source = {
31 model_id = polytomic_model.audience_source.id
32 field = "first_name"
33 }
34 target = "firstName"
35 },
36 {
37 source = {
38 model_id = polytomic_model.audience_source.id
39 field = "last_name"
40 }
41 target = "lastName"
42 },
43 ]
44}

6. Apply the Terraform Configuration

Initialize Terraform and apply the configuration:

$ terraform init
$ terraform apply

Review the changes and confirm to proceed.

For more details, refer to the Polytomic Terraform provider documentation.