-
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.
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Let's retrieve the default GCS Service account | ||
data "google_storage_project_service_account" "gcs_account" { | ||
project = var.project_id | ||
depends_on = [module.project-services] | ||
} | ||
|
||
# The gcs default service account must be given access to the KMS Key. | ||
resource "google_kms_crypto_key_iam_member" "gcs_default_sa" { | ||
crypto_key_id = var.kms_key_path | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
|
||
member = "serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}" | ||
depends_on = [module.project-services] | ||
} | ||
|
||
resource "google_storage_bucket" "main" { | ||
name = var.name | ||
project = var.project_id | ||
location = var.region | ||
|
||
uniform_bucket_level_access = true | ||
|
||
encryption { | ||
default_kms_key_name = var.kms_key_path | ||
} | ||
|
||
# Ensure the KMS crypto-key IAM binding for the service account exists prior to the | ||
# bucket attempting to utilise the crypto-key. | ||
depends_on = [google_kms_crypto_key_iam_member.gcs_default_sa, module.project-services] | ||
} |
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,7 @@ | ||
output "id" { | ||
value = google_storage_bucket.main.id | ||
} | ||
|
||
output "name" { | ||
value = google_storage_bucket.main.name | ||
} |
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,10 @@ | ||
terraform { | ||
required_version = "1.3.7" | ||
|
||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">=5.11.0" | ||
} | ||
} | ||
} |
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,20 @@ | ||
variable "name" { | ||
type = string | ||
description = "Name of storage bucket" | ||
} | ||
|
||
variable "project_id" { | ||
description = "Id of the project" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "Region where to deploy the bucket. Default to Frankfurt." | ||
default = "europe-west3" | ||
type = string | ||
} | ||
|
||
variable "kms_key_path" { | ||
description = "The Customer Managed Encryption Key used to encrypt the data. This should be of the form projects/[KEY_PROJECT_ID]/locations/[LOCATION]/keyRings/[RING_NAME]/cryptoKeys/[KEY_NAME]" | ||
type = string | ||
} |