Skip to content

Commit

Permalink
add: test
Browse files Browse the repository at this point in the history
  • Loading branch information
a5chin committed Nov 20, 2024
1 parent 30d2ac2 commit 2d47f7f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"editor.formatOnSaveMode": "file",
"editor.tabSize": 2
},
"[terraform-test]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.tabSize": 2
},
"[terraform-vars]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
Expand Down
6 changes: 3 additions & 3 deletions modules/gcs2spanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

| Name | Version |
|------|---------|
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.6.0 |
| <a name="provider_google"></a> [google](#provider\_google) | 6.12.0 |
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | 6.12.0 |
| <a name="provider_archive"></a> [archive](#provider\_archive) | >=2.4.0 |
| <a name="provider_google"></a> [google](#provider\_google) | >= 5.22.0 |
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 5.22.0 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion modules/gcs2spanner/dataflow.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "google_project_iam_member" "dataflow" {
for_each = local.dataflow_roles
member = "serviceAccount:${google_service_account.dataflow.email}"

project = data.google_project.main.project_id
project = var.project_id
role = each.value

depends_on = [google_project_service.main]
Expand Down
2 changes: 1 addition & 1 deletion modules/gcs2spanner/functoins.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ resource "google_project_iam_member" "functions" {
for_each = local.functions_roles
member = "serviceAccount:${google_service_account.functions.email}"

project = data.google_project.main.project_id
project = var.project_id
role = each.value

depends_on = [google_project_service.main]
Expand Down
64 changes: 64 additions & 0 deletions modules/gcs2spanner/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
mock_provider "archive" {}
mock_provider "google" {}
mock_provider "google-beta" {}

run "valid_roles" {
module {
source = "./"
}

variables {
project_id = "project_id"
location = "location"

dataflow = {
name = "name"
temp_gcs_location = "temp_gcs_location"
parameters = {
instanceId = "instanceId"
databaseId = "databaseId"
subnetwork = "subnetwork"
}
sa = {
id = "account-id"
}
}

functions = {
name = "name"
bucket = "bucket"
sa = {
id = "account-id"
}
event = {
sa = {
id = "account-id"
}
}
}

gcs = {
name = "name"
allows = [
"serviceAccount:mail", "group:adress"
]
}

vpc = {
network = {
name = "name"
}
subnetwork = {
name = "name"
ip_cidr_range = "0.0.0.0/0"
}
}
}

command = plan

assert {
condition = length(google_storage_bucket_iam_member.data) == 4
error_message = "Service accounts is not properly tied to roles"
}
}
6 changes: 3 additions & 3 deletions modules/gcs2spanner/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "google_project_iam_member" "event" {
for_each = local.event_roles
member = "serviceAccount:${google_service_account.event.email}"

project = data.google_project.main.project_id
project = var.project_id
role = each.value

depends_on = [google_project_service.main]
Expand All @@ -35,14 +35,14 @@ resource "google_cloud_run_v2_service_iam_member" "event" {

resource "google_project_service_identity" "storage" {
provider = google-beta
project = data.google_project.main.project_id
project = var.project_id
service = "storage.googleapis.com"

depends_on = [google_project_service.main]
}

resource "google_project_iam_member" "gcs" {
project = data.google_project.main.project_id
project = var.project_id
role = "roles/pubsub.publisher"
member = "serviceAccount:service-${data.google_project.main.number}@gs-project-accounts.iam.gserviceaccount.com"

Expand Down

0 comments on commit 2d47f7f

Please sign in to comment.