Skip to content

Commit

Permalink
fix: use null as default for lookup (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyuanli authored Sep 4, 2024
1 parent c86102c commit 6c14d5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions examples/multiple_buckets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ module "cloud_storage" {
]
}

retention_policy = {
"two" = {
is_locked = false
retention_period = 1
}
}

default_event_based_hold = {
"one" = true
}
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ resource "google_storage_bucket" "buckets" {
}

dynamic "retention_policy" {
for_each = lookup(var.retention_policy, each.value, {}) != {} ? [var.retention_policy[each.value]] : []
for_each = lookup(var.retention_policy, each.value, null) != null ? [var.retention_policy[each.value]] : []
content {
is_locked = lookup(retention_policy.value, "is_locked", null)
retention_period = lookup(retention_policy.value, "retention_period", null)
}
}

dynamic "custom_placement_config" {
for_each = lookup(var.custom_placement_config, each.value, {}) != {} ? [var.custom_placement_config[each.value]] : []
for_each = lookup(var.custom_placement_config, each.value, null) != null ? [var.custom_placement_config[each.value]] : []
content {
data_locations = lookup(custom_placement_config.value, "data_locations", null)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ resource "google_storage_bucket" "buckets" {
}

dynamic "logging" {
for_each = lookup(var.logging, each.value, {}) != {} ? { v = lookup(var.logging, each.value) } : {}
for_each = lookup(var.logging, each.value, null) != null ? { v = lookup(var.logging, each.value) } : {}
content {
log_bucket = lookup(logging.value, "log_bucket", null)
log_object_prefix = lookup(logging.value, "log_object_prefix", null)
Expand Down
1 change: 1 addition & 0 deletions test/integration/multiple_buckets/multiple_buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestMultipleBuckets(t *testing.T) {
gcloud.Run(t, fmt.Sprintf("alpha storage ls --buckets gs://%s/prod/", fullBucketName), gcloudArgs)
bucket_lifecycles := op.Get("metadata.lifecycle.rule").Array()
assert.Equal(1, len(bucket_lifecycles), "Bucket 'two' has 1 lifecycle rule")
assert.Equal("1", op.Get("metadata.retentionPolicy.retentionPeriod").String(), "bucket retention policy retention period is 1")
default:
// fail test if unknown suffix
t.Fatalf("Only expected two buckets with suffixes one and two. Found: %s", fullBucketName)
Expand Down

0 comments on commit 6c14d5e

Please sign in to comment.