8.1 KiB
8.1 KiB
Fleet CloudWatch Log Sharing GCP Target
This module creates the Google Cloud destination side for Fleet CloudWatch log sharing:
- Pub/Sub topic for log ingestion from the AWS bridge Lambda.
- Service account (and optional key) used by the AWS bridge Lambda to publish.
- Cloud Storage bucket destination.
- Pub/Sub subscription that streams topic data into Cloud Storage.
This is the Google Cloud equivalent of an AWS target account module that ends in S3.
Usage
provider "google" {
project = "customer-observability-prod"
region = "us-central1"
}
module "fleet_log_sharing_target_gcp" {
source = "github.com/fleetdm/fleet-terraform//addons/byo-cloudwatch-log-sharing/target-account-gcp?depth=1&ref=tf-mod-addon-byo-cloudwatch-log-sharing-v1.0.0"
# Optional. If omitted, module uses provider "google" project.
# project_id = "customer-observability-prod"
service_account = {
# Optional. If omitted, defaults to "fleet-cwl-pubsub-publisher".
account_id = "fleet-cwl-pubsub-publisher"
}
pubsub = {
topic_name = "fleet-cloudwatch-logs"
subscription_name = "fleet-cloudwatch-logs-to-gcs"
}
gcs = {
bucket_name = "customer-fleet-cloudwatch-logs"
location = "US"
}
delivery = {
filename_prefix = "fleet/logs/"
filename_suffix = ".jsonl"
max_duration = "300s"
max_bytes = 10485760
}
}
output "fleet_log_sharing_target_gcp" {
value = module.fleet_log_sharing_target_gcp
sensitive = true
}
Cross-Organization Hand-off to AWS Bridge Team
Share these values out-of-band with the team that manages the AWS pubsub-bridge module:
module.fleet_log_sharing_target_gcp.bridge.project_idmodule.fleet_log_sharing_target_gcp.bridge.topic_idmodule.fleet_log_sharing_target_gcp.publisher_credentials_json
The bridge team stores publisher_credentials_json in AWS Secrets Manager and passes the secret ARN into:
addons/byo-cloudwatch-log-sharing/pubsub-bridge
Test Publisher Script
A helper script is included to publish validation messages directly to the Pub/Sub topic:
scripts/publish_pubsub_test.sh
Example using built-in default messages:
./scripts/publish_pubsub_test.sh \
--project-id customer-observability-prod \
--topic-id fleet-cloudwatch-logs \
--service-account-key-file ./service-account.json \
--debug
Example using custom data:
./scripts/publish_pubsub_test.sh \
--project-id customer-observability-prod \
--topic-id fleet-cloudwatch-logs \
--service-account-key-file ./service-account.json \
--data-file ./messages.ndjson
messages.ndjson should contain one message per line.
Example using values directly from Terraform outputs (jq required):
terraform output -json > ./tf-output.json
jq -r '.fleet_log_sharing_target_gcp.value.publisher_credentials_json' ./tf-output.json > ./service-account.json
PROJECT_ID="$(jq -r '.fleet_log_sharing_target_gcp.value.bridge.project_id' ./tf-output.json)"
TOPIC_ID="$(jq -r '.fleet_log_sharing_target_gcp.value.bridge.topic_id' ./tf-output.json)"
./scripts/publish_pubsub_test.sh \
--project-id "${PROJECT_ID}" \
--topic-id "${TOPIC_ID}" \
--service-account-key-file ./service-account.json \
--debug
Requirements
| Name | Version |
|---|---|
| terraform | >= 1.3.7 |
| >= 6.35.0 |
Providers
| Name | Version |
|---|---|
| >= 6.35.0 |
Modules
No modules.
Resources
| Name | Type |
|---|---|
| google_pubsub_subscription.gcs_sink | resource |
| google_pubsub_topic.fleet_logs | resource |
| google_pubsub_topic_iam_member.publisher | resource |
| google_service_account.publisher | resource |
| google_service_account_key.publisher | resource |
| google_storage_bucket.fleet_logs | resource |
| google_storage_bucket_iam_member.pubsub_bucket_reader | resource |
| google_storage_bucket_iam_member.pubsub_writer | resource |
| google_client_config.current | data source |
| google_project.target | data source |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| delivery | Pub/Sub Cloud Storage subscription delivery settings. | object({ |
{} |
no |
| gcs | Google Cloud Storage destination for delivered Pub/Sub log files. | object({ |
n/a | yes |
| labels | Labels to apply to resources that support labels. | map(string) |
{} |
no |
| project_id | Optional GCP project ID where resources will be created. If omitted, the module uses the active Google provider project. | string |
"" |
no |
| pubsub | Pub/Sub topic and subscription settings for incoming Fleet log events. | object({ |
{} |
no |
| service_account | Service account used by the AWS bridge Lambda to publish to Pub/Sub. If account_id is omitted, defaults to fleet-cwl-pubsub-publisher. | object({ |
{} |
no |
Outputs
| Name | Description |
|---|---|
| bridge | Values to share with the AWS bridge module configuration. |
| publisher_credentials_json | Sensitive Google service-account credentials JSON to store in AWS Secrets Manager for the bridge Lambda. |
| publisher_service_account | Publisher service-account details used by the AWS Lambda bridge. |
| pubsub | Pub/Sub resource details for the log intake topic and GCS sink subscription. |
| storage | Google Cloud Storage destination details. |