Skip to content

Commit d152a2c

Browse files
remove send_empty_value for max_ttl (#5456) (#10572)
* remove send_empty_value for max_ttl * add a test Signed-off-by: Modular Magician <[email protected]>
1 parent d92d721 commit d152a2c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.changelog/5456.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed a bug when `cache_mode` is set to FORCE_CACHE_ALL on `google_compute_backend_bucket`
3+
```

google/resource_compute_backend_bucket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func expandComputeBackendBucketCdnPolicy(v interface{}, d TerraformResourceData,
713713
transformedMaxTtl, err := expandComputeBackendBucketCdnPolicyMaxTtl(original["max_ttl"], d, config)
714714
if err != nil {
715715
return nil, err
716-
} else {
716+
} else if val := reflect.ValueOf(transformedMaxTtl); val.IsValid() && !isEmptyValue(val) {
717717
transformed["maxTtl"] = transformedMaxTtl
718718
}
719719

google/resource_compute_backend_bucket_test.go

+37-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestAccComputeBackendBucket_withCdnPolicy(t *testing.T) {
6868
ImportStateVerify: true,
6969
},
7070
{
71-
Config: testAccComputeBackendBucket_withCdnPolicy2(backendName, storageName, 0, 404, 0, 0),
71+
Config: testAccComputeBackendBucket_withCdnPolicy2(backendName, storageName, 0, 404, 86400, 0),
7272
},
7373
{
7474
ResourceName: "google_compute_backend_bucket.foobar",
@@ -83,6 +83,14 @@ func TestAccComputeBackendBucket_withCdnPolicy(t *testing.T) {
8383
ImportState: true,
8484
ImportStateVerify: true,
8585
},
86+
{
87+
Config: testAccComputeBackendBucket_withCdnPolicy3(backendName, storageName, 0, 404, 0, 0),
88+
},
89+
{
90+
ResourceName: "google_compute_backend_bucket.foobar",
91+
ImportState: true,
92+
ImportStateVerify: true,
93+
},
8694
},
8795
})
8896
}
@@ -165,3 +173,31 @@ resource "google_storage_bucket" "bucket" {
165173
}
166174
`, backendName, age, max_ttl, ttl, ttl, ttl, code, ttl, storageName)
167175
}
176+
177+
func testAccComputeBackendBucket_withCdnPolicy3(backendName, storageName string, age, code, max_ttl, ttl int) string {
178+
return fmt.Sprintf(`
179+
resource "google_compute_backend_bucket" "foobar" {
180+
name = "%s"
181+
bucket_name = google_storage_bucket.bucket.name
182+
enable_cdn = true
183+
cdn_policy {
184+
cache_mode = "FORCE_CACHE_ALL"
185+
signed_url_cache_max_age_sec = %d
186+
max_ttl = %d
187+
default_ttl = %d
188+
client_ttl = %d
189+
serve_while_stale = %d
190+
negative_caching_policy {
191+
code = %d
192+
ttl = %d
193+
}
194+
negative_caching = true
195+
}
196+
}
197+
198+
resource "google_storage_bucket" "bucket" {
199+
name = "%s"
200+
location = "EU"
201+
}
202+
`, backendName, age, max_ttl, ttl, ttl, ttl, code, ttl, storageName)
203+
}

0 commit comments

Comments
 (0)