forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Pub/Sub Subscription support for specifying a service accou…
- Loading branch information
1 parent
21e7cf2
commit 2efa7e7
Showing
4 changed files
with
286 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
mmv1/templates/terraform/examples/pubsub_subscription_push_bq_service_account.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['topic_name'] %>" | ||
} | ||
|
||
resource "google_pubsub_subscription" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['subscription_name'] %>" | ||
topic = google_pubsub_topic.<%= ctx[:primary_resource_id] %>.id | ||
|
||
bigquery_config { | ||
table = "${google_bigquery_table.test.project}.${google_bigquery_table.test.dataset_id}.${google_bigquery_table.test.table_id}" | ||
service_account_email = google_service_account.bq_write_service_account.email | ||
} | ||
|
||
depends_on = [google_service_account.bq_write_service_account, google_project_iam_member.viewer, google_project_iam_member.editor] | ||
} | ||
|
||
data "google_project" "project" { | ||
} | ||
|
||
resource "google_service_account" "bq_write_service_account" { | ||
account_id = "<%= ctx[:vars]['service_account_id'] %>" | ||
display_name = "BQ Write Service Account" | ||
} | ||
|
||
resource "google_project_iam_member" "viewer" { | ||
project = data.google_project.project.project_id | ||
role = "roles/bigquery.metadataViewer" | ||
member = "serviceAccount:${google_service_account.bq_write_service_account.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "editor" { | ||
project = data.google_project.project.project_id | ||
role = "roles/bigquery.dataEditor" | ||
member = "serviceAccount:${google_service_account.bq_write_service_account.email}" | ||
} | ||
|
||
resource "google_bigquery_dataset" "test" { | ||
dataset_id = "<%= ctx[:vars]['dataset_id'] %>" | ||
} | ||
|
||
resource "google_bigquery_table" "test" { | ||
deletion_protection = false | ||
table_id = "<%= ctx[:vars]['table_id'] %>" | ||
dataset_id = google_bigquery_dataset.test.dataset_id | ||
|
||
schema = <<EOF | ||
[ | ||
{ | ||
"name": "data", | ||
"type": "STRING", | ||
"mode": "NULLABLE", | ||
"description": "The data" | ||
} | ||
] | ||
EOF | ||
} |
46 changes: 46 additions & 0 deletions
46
...templates/terraform/examples/pubsub_subscription_push_cloudstorage_service_account.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
resource "google_storage_bucket" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['bucket_name'] %>" | ||
location = "US" | ||
uniform_bucket_level_access = true | ||
} | ||
|
||
resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['topic_name'] %>" | ||
} | ||
|
||
resource "google_pubsub_subscription" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['subscription_name'] %>" | ||
topic = google_pubsub_topic.<%= ctx[:primary_resource_id] %>.id | ||
|
||
cloud_storage_config { | ||
bucket = google_storage_bucket.<%= ctx[:primary_resource_id] %>.name | ||
|
||
filename_prefix = "pre-" | ||
filename_suffix = "-%{random_suffix}" | ||
filename_datetime_format = "YYYY-MM-DD/hh_mm_ssZ" | ||
|
||
max_bytes = 1000 | ||
max_duration = "300s" | ||
|
||
service_account_email = google_service_account.storage_write_service_account.email | ||
} | ||
depends_on = [ | ||
google_service_account.storage_write_service_account, | ||
google_storage_bucket.<%= ctx[:primary_resource_id] %>, | ||
google_storage_bucket_iam_member.admin, | ||
] | ||
} | ||
|
||
data "google_project" "project" { | ||
} | ||
|
||
resource "google_service_account" "storage_write_service_account" { | ||
account_id = "<%= ctx[:vars]['service_account_id'] %>" | ||
display_name = "Storage Write Service Account" | ||
} | ||
|
||
resource "google_storage_bucket_iam_member" "admin" { | ||
bucket = google_storage_bucket.<%= ctx[:primary_resource_id] %>.name | ||
role = "roles/storage.admin" | ||
member = "serviceAccount:${google_service_account.storage_write_service_account.email}" | ||
} |
Oops, something went wrong.