Skip to content

Commit 2fbc0a9

Browse files
Add headers, expectedOutputUrl, and expectedRedirectResponseCode fields to URL map (#14118) (#23199)
[upstream:7ab204c263691cd7a96daedcde947e3b904b7e5f] Signed-off-by: Modular Magician <[email protected]>
1 parent 692424b commit 2fbc0a9

File tree

5 files changed

+690
-11
lines changed

5 files changed

+690
-11
lines changed

.changelog/14118.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `headers`, `expected_output_url`, and `expected_redirect_response_code` fields to `test[]` in `google_compute_url_map` resource and made `service` field optional
3+
```

google/services/compute/resource_compute_url_map.go

Lines changed: 164 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,17 +2838,54 @@ tests per UrlMap.`,
28382838
Required: true,
28392839
Description: `Path portion of the URL.`,
28402840
},
2841-
"service": {
2842-
Type: schema.TypeString,
2843-
Required: true,
2844-
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
2845-
Description: `The backend service or backend bucket link that should be matched by this test.`,
2846-
},
28472841
"description": {
28482842
Type: schema.TypeString,
28492843
Optional: true,
28502844
Description: `Description of this test case.`,
28512845
},
2846+
"expected_output_url": {
2847+
Type: schema.TypeString,
2848+
Optional: true,
2849+
Description: `The expected output URL evaluated by the load balancer containing the scheme, host, path and query parameters.
2850+
2851+
For rules that forward requests to backends, the test passes only when expectedOutputUrl matches the request forwarded by the load balancer to backends. For rules with urlRewrite, the test verifies that the forwarded request matches hostRewrite and pathPrefixRewrite in the urlRewrite action. When service is specified, expectedOutputUrl's scheme is ignored.
2852+
2853+
For rules with urlRedirect, the test passes only if expectedOutputUrl matches the URL in the load balancer's redirect response. If urlRedirect specifies httpsRedirect, the test passes only if the scheme in expectedOutputUrl is also set to HTTPS. If urlRedirect specifies stripQuery, the test passes only if expectedOutputUrl does not contain any query parameters.
2854+
2855+
expectedOutputUrl is optional when service is specified.`,
2856+
},
2857+
"expected_redirect_response_code": {
2858+
Type: schema.TypeInt,
2859+
Optional: true,
2860+
Description: `For rules with urlRedirect, the test passes only if expectedRedirectResponseCode matches the HTTP status code in load balancer's redirect response.
2861+
2862+
expectedRedirectResponseCode cannot be set when service is set.`,
2863+
},
2864+
"headers": {
2865+
Type: schema.TypeList,
2866+
Optional: true,
2867+
Description: `HTTP headers for this request.`,
2868+
Elem: &schema.Resource{
2869+
Schema: map[string]*schema.Schema{
2870+
"name": {
2871+
Type: schema.TypeString,
2872+
Required: true,
2873+
Description: `Header name.`,
2874+
},
2875+
"value": {
2876+
Type: schema.TypeString,
2877+
Required: true,
2878+
Description: `Header value.`,
2879+
},
2880+
},
2881+
},
2882+
},
2883+
"service": {
2884+
Type: schema.TypeString,
2885+
Optional: true,
2886+
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
2887+
Description: `The backend service or backend bucket link that should be matched by this test.`,
2888+
},
28522889
},
28532890
},
28542891
},
@@ -5768,10 +5805,13 @@ func flattenComputeUrlMapTest(v interface{}, d *schema.ResourceData, config *tra
57685805
continue
57695806
}
57705807
transformed = append(transformed, map[string]interface{}{
5771-
"description": flattenComputeUrlMapTestDescription(original["description"], d, config),
5772-
"host": flattenComputeUrlMapTestHost(original["host"], d, config),
5773-
"path": flattenComputeUrlMapTestPath(original["path"], d, config),
5774-
"service": flattenComputeUrlMapTestService(original["service"], d, config),
5808+
"description": flattenComputeUrlMapTestDescription(original["description"], d, config),
5809+
"host": flattenComputeUrlMapTestHost(original["host"], d, config),
5810+
"path": flattenComputeUrlMapTestPath(original["path"], d, config),
5811+
"headers": flattenComputeUrlMapTestHeaders(original["headers"], d, config),
5812+
"service": flattenComputeUrlMapTestService(original["service"], d, config),
5813+
"expected_output_url": flattenComputeUrlMapTestExpectedOutputUrl(original["expectedOutputUrl"], d, config),
5814+
"expected_redirect_response_code": flattenComputeUrlMapTestExpectedRedirectResponseCode(original["expectedRedirectResponseCode"], d, config),
57755815
})
57765816
}
57775817
return transformed
@@ -5788,13 +5828,61 @@ func flattenComputeUrlMapTestPath(v interface{}, d *schema.ResourceData, config
57885828
return v
57895829
}
57905830

5831+
func flattenComputeUrlMapTestHeaders(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
5832+
if v == nil {
5833+
return v
5834+
}
5835+
l := v.([]interface{})
5836+
transformed := make([]interface{}, 0, len(l))
5837+
for _, raw := range l {
5838+
original := raw.(map[string]interface{})
5839+
if len(original) < 1 {
5840+
// Do not include empty json objects coming back from the api
5841+
continue
5842+
}
5843+
transformed = append(transformed, map[string]interface{}{
5844+
"name": flattenComputeUrlMapTestHeadersName(original["name"], d, config),
5845+
"value": flattenComputeUrlMapTestHeadersValue(original["value"], d, config),
5846+
})
5847+
}
5848+
return transformed
5849+
}
5850+
func flattenComputeUrlMapTestHeadersName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
5851+
return v
5852+
}
5853+
5854+
func flattenComputeUrlMapTestHeadersValue(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
5855+
return v
5856+
}
5857+
57915858
func flattenComputeUrlMapTestService(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
57925859
if v == nil {
57935860
return v
57945861
}
57955862
return tpgresource.ConvertSelfLinkToV1(v.(string))
57965863
}
57975864

5865+
func flattenComputeUrlMapTestExpectedOutputUrl(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
5866+
return v
5867+
}
5868+
5869+
func flattenComputeUrlMapTestExpectedRedirectResponseCode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
5870+
// Handles the string fixed64 format
5871+
if strVal, ok := v.(string); ok {
5872+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
5873+
return intVal
5874+
}
5875+
}
5876+
5877+
// number values are represented as float64
5878+
if floatVal, ok := v.(float64); ok {
5879+
intVal := int(floatVal)
5880+
return intVal
5881+
}
5882+
5883+
return v // let terraform core handle it otherwise
5884+
}
5885+
57985886
func flattenComputeUrlMapDefaultUrlRedirect(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
57995887
if v == nil {
58005888
return nil
@@ -10018,13 +10106,34 @@ func expandComputeUrlMapTest(v interface{}, d tpgresource.TerraformResourceData,
1001810106
transformed["path"] = transformedPath
1001910107
}
1002010108

10109+
transformedHeaders, err := expandComputeUrlMapTestHeaders(original["headers"], d, config)
10110+
if err != nil {
10111+
return nil, err
10112+
} else if val := reflect.ValueOf(transformedHeaders); val.IsValid() && !tpgresource.IsEmptyValue(val) {
10113+
transformed["headers"] = transformedHeaders
10114+
}
10115+
1002110116
transformedService, err := expandComputeUrlMapTestService(original["service"], d, config)
1002210117
if err != nil {
1002310118
return nil, err
1002410119
} else if val := reflect.ValueOf(transformedService); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1002510120
transformed["service"] = transformedService
1002610121
}
1002710122

10123+
transformedExpectedOutputUrl, err := expandComputeUrlMapTestExpectedOutputUrl(original["expected_output_url"], d, config)
10124+
if err != nil {
10125+
return nil, err
10126+
} else if val := reflect.ValueOf(transformedExpectedOutputUrl); val.IsValid() && !tpgresource.IsEmptyValue(val) {
10127+
transformed["expectedOutputUrl"] = transformedExpectedOutputUrl
10128+
}
10129+
10130+
transformedExpectedRedirectResponseCode, err := expandComputeUrlMapTestExpectedRedirectResponseCode(original["expected_redirect_response_code"], d, config)
10131+
if err != nil {
10132+
return nil, err
10133+
} else if val := reflect.ValueOf(transformedExpectedRedirectResponseCode); val.IsValid() && !tpgresource.IsEmptyValue(val) {
10134+
transformed["expectedRedirectResponseCode"] = transformedExpectedRedirectResponseCode
10135+
}
10136+
1002810137
req = append(req, transformed)
1002910138
}
1003010139
return req, nil
@@ -10042,6 +10151,43 @@ func expandComputeUrlMapTestPath(v interface{}, d tpgresource.TerraformResourceD
1004210151
return v, nil
1004310152
}
1004410153

10154+
func expandComputeUrlMapTestHeaders(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10155+
l := v.([]interface{})
10156+
req := make([]interface{}, 0, len(l))
10157+
for _, raw := range l {
10158+
if raw == nil {
10159+
continue
10160+
}
10161+
original := raw.(map[string]interface{})
10162+
transformed := make(map[string]interface{})
10163+
10164+
transformedName, err := expandComputeUrlMapTestHeadersName(original["name"], d, config)
10165+
if err != nil {
10166+
return nil, err
10167+
} else if val := reflect.ValueOf(transformedName); val.IsValid() && !tpgresource.IsEmptyValue(val) {
10168+
transformed["name"] = transformedName
10169+
}
10170+
10171+
transformedValue, err := expandComputeUrlMapTestHeadersValue(original["value"], d, config)
10172+
if err != nil {
10173+
return nil, err
10174+
} else if val := reflect.ValueOf(transformedValue); val.IsValid() && !tpgresource.IsEmptyValue(val) {
10175+
transformed["value"] = transformedValue
10176+
}
10177+
10178+
req = append(req, transformed)
10179+
}
10180+
return req, nil
10181+
}
10182+
10183+
func expandComputeUrlMapTestHeadersName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10184+
return v, nil
10185+
}
10186+
10187+
func expandComputeUrlMapTestHeadersValue(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10188+
return v, nil
10189+
}
10190+
1004510191
func expandComputeUrlMapTestService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1004610192
// This method returns a full self link from whatever the input is.
1004710193
if v == nil || v.(string) == "" {
@@ -10074,6 +10220,14 @@ func expandComputeUrlMapTestService(v interface{}, d tpgresource.TerraformResour
1007410220
return f.RelativeLink(), nil
1007510221
}
1007610222

10223+
func expandComputeUrlMapTestExpectedOutputUrl(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10224+
return v, nil
10225+
}
10226+
10227+
func expandComputeUrlMapTestExpectedRedirectResponseCode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10228+
return v, nil
10229+
}
10230+
1007710231
func expandComputeUrlMapDefaultUrlRedirect(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1007810232
l := v.([]interface{})
1007910233
if len(l) == 0 || l[0] == nil {

google/services/compute/resource_compute_url_map_generated_meta.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ fields:
398398
api_field: 'path_matchers.route_rules.url_redirect.strip_query'
399399
- field: 'test.description'
400400
api_field: 'tests.description'
401+
- field: 'test.expected_output_url'
402+
api_field: 'tests.expected_output_url'
403+
- field: 'test.expected_redirect_response_code'
404+
api_field: 'tests.expected_redirect_response_code'
405+
- field: 'test.headers.name'
406+
api_field: 'tests.headers.name'
407+
- field: 'test.headers.value'
408+
api_field: 'tests.headers.value'
401409
- field: 'test.host'
402410
api_field: 'tests.host'
403411
- field: 'test.path'

0 commit comments

Comments
 (0)