Skip to content

Commit

Permalink
fixed a bug in update (#5336) (#10375)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 22, 2021
1 parent eae8d24 commit dba7300
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/5336.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed a bug in updating multiple `ttl` fields on `google_compute_backend_bucket`
```
10 changes: 5 additions & 5 deletions google/resource_compute_backend_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,28 +699,28 @@ func expandComputeBackendBucketCdnPolicy(v interface{}, d TerraformResourceData,
transformedSignedUrlCacheMaxAgeSec, err := expandComputeBackendBucketCdnPolicySignedUrlCacheMaxAgeSec(original["signed_url_cache_max_age_sec"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSignedUrlCacheMaxAgeSec); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["signedUrlCacheMaxAgeSec"] = transformedSignedUrlCacheMaxAgeSec
}

transformedDefaultTtl, err := expandComputeBackendBucketCdnPolicyDefaultTtl(original["default_ttl"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDefaultTtl); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["defaultTtl"] = transformedDefaultTtl
}

transformedMaxTtl, err := expandComputeBackendBucketCdnPolicyMaxTtl(original["max_ttl"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedMaxTtl); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["maxTtl"] = transformedMaxTtl
}

transformedClientTtl, err := expandComputeBackendBucketCdnPolicyClientTtl(original["client_ttl"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedClientTtl); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["clientTtl"] = transformedClientTtl
}

Expand Down Expand Up @@ -795,7 +795,7 @@ func expandComputeBackendBucketCdnPolicyNegativeCachingPolicy(v interface{}, d T
transformedTtl, err := expandComputeBackendBucketCdnPolicyNegativeCachingPolicyTtl(original["ttl"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTtl); val.IsValid() && !isEmptyValue(val) {
} else {
transformed["ttl"] = transformedTtl
}

Expand Down
56 changes: 54 additions & 2 deletions google/resource_compute_backend_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ func TestAccComputeBackendBucket_withCdnPolicy(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeBackendBucket_withCdnPolicy2(backendName, storageName, 1000, 301, 2, 1),
},
{
ResourceName: "google_compute_backend_bucket.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeBackendBucket_withCdnPolicy2(backendName, storageName, 0, 404, 0, 0),
},
{
ResourceName: "google_compute_backend_bucket.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeBackendBucket_withCdnPolicy(backendName, storageName),
},
{
ResourceName: "google_compute_backend_bucket.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -103,13 +127,41 @@ resource "google_compute_backend_bucket" "foobar" {
bucket_name = google_storage_bucket.bucket.name
enable_cdn = true
cdn_policy {
signed_url_cache_max_age_sec = 1000
signed_url_cache_max_age_sec = 1000
negative_caching = false
}
}
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "EU"
}
`, backendName, storageName)
}

func testAccComputeBackendBucket_withCdnPolicy2(backendName, storageName string, age, code, max_ttl, ttl int) string {
return fmt.Sprintf(`
resource "google_compute_backend_bucket" "foobar" {
name = "%s"
bucket_name = google_storage_bucket.bucket.name
enable_cdn = true
cdn_policy {
cache_mode = "CACHE_ALL_STATIC"
signed_url_cache_max_age_sec = %d
max_ttl = %d
default_ttl = %d
client_ttl = %d
serve_while_stale = %d
negative_caching_policy {
code = %d
ttl = %d
}
negative_caching = true
}
}
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "EU"
}
`, backendName, age, max_ttl, ttl, ttl, ttl, code, ttl, storageName)
}

0 comments on commit dba7300

Please sign in to comment.