Skip to content

Commit

Permalink
pubsub: additional test permissions fixes (#12311) (#20312)
Browse files Browse the repository at this point in the history
[upstream:8ff36d326452a6ae220d06ca5e5bfb51f839a5b5]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 12, 2024
1 parent 606d869 commit 8a4dbdd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .changelog/12311.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
Original file line number Diff line number Diff line change
Expand Up @@ -410,24 +410,27 @@ resource "google_pubsub_subscription" "example" {
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]
depends_on = [
google_service_account.bq_write_service_account,
google_project_iam_member.bigquery_metadata_viewer,
google_project_iam_member.bigquery_data_editor
]
}
data "google_project" "project" {
}
data "google_project" "project" {}
resource "google_service_account" "bq_write_service_account" {
account_id = "tf-test-example-bqw%{random_suffix}"
display_name = "BQ Write Service Account"
}
resource "google_project_iam_member" "viewer" {
resource "google_project_iam_member" "bigquery_metadata_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" {
resource "google_project_iam_member" "bigquery_data_editor" {
project = data.google_project.project.project_id
role = "roles/bigquery.dataEditor"
member = "serviceAccount:${google_service_account.bq_write_service_account.email}"
Expand Down
29 changes: 9 additions & 20 deletions google/services/pubsub/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,41 +685,32 @@ resource "google_pubsub_subscription" "foo" {
func testAccPubsubSubscriptionBigQuery_basic(dataset, table, topic, subscription string, useTableSchema bool, serviceAccountId string) string {
serviceAccountEmailField := ""
serviceAccountResource := ""
tfDependencies := ""
if serviceAccountId != "" {
serviceAccountResource = fmt.Sprintf(`
resource "google_service_account" "bq_write_service_account" {
account_id = "%s"
display_name = "BQ Write Service Account"
}
resource "google_project_iam_member" "viewer" {
resource "google_project_iam_member" "bigquery_metadata_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" {
resource "google_project_iam_member" "bigquery_data_editor" {
project = data.google_project.project.project_id
role = "roles/bigquery.dataEditor"
member = "serviceAccount:${google_service_account.bq_write_service_account.email}"
}`, serviceAccountId)
serviceAccountEmailField = "service_account_email = google_service_account.bq_write_service_account.email"
tfDependencies = ` google_project_iam_member.bigquery_metadata_viewer,
google_project_iam_member.bigquery_data_editor,
time_sleep.wait_30_seconds,`
} else {
serviceAccountResource = fmt.Sprintf(`
resource "google_project_iam_member" "viewer" {
project = data.google_project.project.project_id
role = "roles/bigquery.metadataViewer"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
}
resource "google_project_iam_member" "editor" {
project = data.google_project.project.project_id
role = "roles/bigquery.dataEditor"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-pubsub.iam.gserviceaccount.com"
}
`)
tfDependencies = " time_sleep.wait_30_seconds,"
}

return fmt.Sprintf(`
data "google_project" "project" {}
Expand Down Expand Up @@ -765,12 +756,10 @@ resource "google_pubsub_subscription" "foo" {
}
depends_on = [
google_project_iam_member.viewer,
google_project_iam_member.editor,
time_sleep.wait_30_seconds,
%s
]
}
`, serviceAccountResource, dataset, table, topic, subscription, useTableSchema, serviceAccountEmailField)
`, serviceAccountResource, dataset, table, topic, subscription, useTableSchema, serviceAccountEmailField, tfDependencies)
}

func testAccPubsubSubscriptionCloudStorage_basic(bucket, topic, subscription, filenamePrefix, filenameSuffix, filenameDatetimeFormat string, maxBytes int, maxDuration string, maxMessages int, serviceAccountId, outputFormat string) string {
Expand Down
13 changes: 8 additions & 5 deletions website/docs/r/pubsub_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,27 @@ resource "google_pubsub_subscription" "example" {
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]
depends_on = [
google_service_account.bq_write_service_account,
google_project_iam_member.bigquery_metadata_viewer,
google_project_iam_member.bigquery_data_editor
]
}
data "google_project" "project" {
}
data "google_project" "project" {}
resource "google_service_account" "bq_write_service_account" {
account_id = "example-bqw"
display_name = "BQ Write Service Account"
}
resource "google_project_iam_member" "viewer" {
resource "google_project_iam_member" "bigquery_metadata_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" {
resource "google_project_iam_member" "bigquery_data_editor" {
project = data.google_project.project.project_id
role = "roles/bigquery.dataEditor"
member = "serviceAccount:${google_service_account.bq_write_service_account.email}"
Expand Down

0 comments on commit 8a4dbdd

Please sign in to comment.