Skip to content

Commit fd276c3

Browse files
authored
feat: add lock in logging bucket (#189)
1 parent 8e1b175 commit fd276c3

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

examples/logbucket/project/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
resource "random_string" "suffix" {
18-
length = 4
18+
length = 6
1919
upper = false
2020
special = false
2121
}
@@ -33,7 +33,7 @@ module "log_export" {
3333
module "destination" {
3434
source = "../../..//modules/logbucket"
3535
project_id = var.project_destination_logbkt_id
36-
name = "logbucket_from_other_project_${random_string.suffix.result}"
36+
name = "logbucket_from_other_prj_${random_string.suffix.result}"
3737
location = "global"
3838
enable_analytics = true
3939
linked_dataset_id = "log_analytics_dataset"

modules/bigquery/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ locals {
3030
# API activation #
3131
#----------------#
3232
resource "google_project_service" "enable_destination_api" {
33-
project = var.project_id
34-
service = "bigquery.googleapis.com"
35-
disable_on_destroy = false
33+
project = var.project_id
34+
service = "bigquery.googleapis.com"
35+
disable_on_destroy = false
36+
disable_dependent_services = false
3637
}
3738

3839
#------------------#

modules/logbucket/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module "destination" {
4242
| linked\_dataset\_description | A use-friendly description of the linked BigQuery dataset. The maximum length of the description is 8000 characters. | `string` | `null` | no |
4343
| linked\_dataset\_id | The ID of the linked BigQuery dataset. A valid link dataset ID must only have alphanumeric characters and underscores within it and have up to 100 characters. | `string` | `null` | no |
4444
| location | The location of the log bucket. | `string` | `"global"` | no |
45+
| locked | (Optional) Whether the bucket is locked. The retention period on a locked bucket cannot be changed. Locked buckets may only be deleted if they are empty | `bool` | `null` | no |
4546
| log\_sink\_writer\_identity | The service account that logging uses to write log entries to the destination. (This is available as an output coming from the root module). | `string` | n/a | yes |
4647
| name | The name of the log bucket to be created and used for log entries matching the filter. | `string` | n/a | yes |
4748
| project\_id | The ID of the project in which the log bucket will be created. | `string` | n/a | yes |

modules/logbucket/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ locals {
2323
# API activation #
2424
#----------------#
2525
resource "google_project_service" "enable_destination_api" {
26-
project = var.project_id
27-
service = "logging.googleapis.com"
28-
disable_on_destroy = false
26+
project = var.project_id
27+
service = "logging.googleapis.com"
28+
disable_on_destroy = false
29+
disable_dependent_services = false
2930
}
3031

3132
#------------#
@@ -38,6 +39,7 @@ resource "google_logging_project_bucket_config" "bucket" {
3839
retention_days = var.retention_days
3940
enable_analytics = var.enable_analytics
4041
bucket_id = var.name
42+
locked = var.locked
4143
}
4244

4345
#-------------------------#

modules/logbucket/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ variable "linked_dataset_description" {
6464
type = string
6565
default = null
6666
}
67+
68+
variable "locked" {
69+
description = "(Optional) Whether the bucket is locked. The retention period on a locked bucket cannot be changed. Locked buckets may only be deleted if they are empty"
70+
default = null
71+
type = bool
72+
}

modules/pubsub/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ locals {
3939
# API activation #
4040
#----------------#
4141
resource "google_project_service" "enable_destination_api" {
42-
project = var.project_id
43-
service = "pubsub.googleapis.com"
44-
disable_on_destroy = false
42+
project = var.project_id
43+
service = "pubsub.googleapis.com"
44+
disable_on_destroy = false
45+
disable_dependent_services = false
4546
}
4647

4748
#--------------#

modules/storage/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ locals {
2323
# API activation #
2424
#----------------#
2525
resource "google_project_service" "enable_destination_api" {
26-
project = var.project_id
27-
service = "storage-component.googleapis.com"
28-
disable_on_destroy = false
26+
project = var.project_id
27+
service = "storage-component.googleapis.com"
28+
disable_on_destroy = false
29+
disable_dependent_services = false
2930
}
3031

3132
#----------------#

0 commit comments

Comments
 (0)