This module sets IAM policy to support exporting data from Worklytics to a pre-existing GCS bucket and provisions instructions for doing so.
It is published in the Terraform Registry.
It is arguably too minimal to be its own module, but we did so to make it analogous to AWS case and provide for potential future provisioning of the connection from the Worklytics side.
from Terraform registry:
resource "google_storage_bucket" "worklytics_export" {
name = "worklytics-export"
# customize as needed; see https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket#argument-reference
}
module "worklytics-export" {
source = "Worklytics/worklytics-export/gcp"
version = "~> 1.0.0"
# email address of your Worklytics Tenant's Service Account (obtain from Worklytics)
worklytics_tenant_sa_email = "YOUR_SA_EMAIL@YOUR_PROJECT_ID.iam.gserviceaccount.com"
bucket_name = google_storage_bucket.worklytics_export.name
}via GitHub:
module "worklytics-export" {
source = "git::https://github.com/worklytics/terraform-gcp-worklytics-export/?ref=v1.0.0"
# email address of your Worklytics Tenant's Service Account (obtain from Worklytics)
worklytics_tenant_sa_email = "YOUR_SA_EMAIL@YOUR_PROJECT_ID.iam.gserviceaccount.com"
bucket_name = google_storage_bucket.worklytics_export.name
}If todo_as_outputs is set to true, this will be a markdown-formatted string of TODOs for you to
complete outside of Terraform.
This module requires Terraform >= 1.3. It is tested against Terraform 1.6 through the latest released version.
The module requires the hashicorp/google provider >= 6.0 (tested against 6.x and 7.x).
Google provider 5.x is no longer maintained, so 1.0 drops it. If you find incompatibilities,
please open an issue.
1.0 is the first stable release. From 0.x:
- Require
hashicorp/google>= 6.0(5.x is unmaintained). - Require Terraform
>= 1.3. - Optional
bucket_write_iam_roleif you want a custom role instead ofroles/storage.objectAdmin(default is unchanged).
Pin the module with version = "~> 1.0.0".
If you wish to export Worklytics data to an existing bucket, use a Terraform import as follows:
terraform import module.worklytics_export.google_storage_bucket.worklytics_export <bucket_name>By default this module grants roles/storage.objectAdmin to the Worklytics tenant service account
on your bucket, which is the role specified in the
Worklytics data export documentation.
Why not a narrower role? GCS implements object overwrite as delete + create internally, so
storage.objects.delete is required alongside storage.objects.create. The narrower
roles/storage.objectCreator omits delete permission and will fail on re-exports.
Minimum required permissions (PoLP):
| Permission | Purpose |
|---|---|
storage.objects.create |
Upload/write export files |
storage.objects.delete |
Required for overwrite (GCS delete+create model) |
storage.objects.list |
Enumerate objects in the bucket |
roles/storage.objectAdmin includes these three plus storage.objects.get,
storage.objects.update, storage.objects.getIamPolicy, and storage.objects.setIamPolicy,
none of which are needed by Worklytics.
Using a custom role instead:
If your security posture requires PoLP, create a custom role and pass its ID via the
bucket_write_iam_role variable:
resource "google_project_iam_custom_role" "worklytics_export_writer" {
role_id = "worklyticsExportWriter"
title = "Worklytics Export Writer"
description = "Minimum permissions for Worklytics to write data exports to GCS."
permissions = [
"storage.objects.create",
"storage.objects.delete",
"storage.objects.list",
]
}
module "worklytics-export" {
source = "Worklytics/worklytics-export/gcp"
version = "~> 1.0.0"
worklytics_tenant_sa_email = "YOUR_SA_EMAIL@YOUR_PROJECT_ID.iam.gserviceaccount.com"
bucket_name = google_storage_bucket.worklytics_export.name
bucket_write_iam_role = google_project_iam_custom_role.worklytics_export_writer.id
}This module is written and maintained by Worklytics, Co. and intended to guide our customers in setting up their own infra to export data from Worklytics to GCS.
As this is published as a Terraform module, we will strive to follow standard Terraform module structure and style conventions.
See examples/basic/ for a simple example of how to use this module.
Developing:
- branch from
main; open a PR tomainwhen ready for review. - releases will be periodically cut from
mainby tagging with semantic version (v{MAJOR}.{MINOR}.{PATCH}), push to origin (GitHub), and create a release (hopefully automatic via GitHub Actions; via GitHub UI if not). - releases should be automatically picked up by Terraform Registry (some lag here)
If you don't wish to use Terraform to prepare your infrastructure for receiving exports from Worklytics, you can do the following.
- Create a GCS bucket or choose a preexisting one that you wish to export to. (GCP Console or CLI)
- Grant the
roles/storage.objectAdminIAM role to your Worklytics Tenant's Service Account (obtain from Worklytics) on the bucket. - Create an Export connection via the Worklytics web app.