Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route_rules to RegionUrlMap #5130

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions google/resource_compute_url_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,16 @@ HttpRouteAction.`,
Description: `The default BackendService resource. Before
forwarding the request to backendService, the loadbalancer applies any relevant
headerActions specified as part of this backendServiceWeight.`,
},
"weight": {
Type: schema.TypeInt,
Required: true,
Description: `Specifies the fraction of traffic sent to backendService, computed as weight /
(sum of all weightedBackendService weights in routeAction) . The selection of a
backend service is determined only for new traffic. Once a user's request has
been directed to a backendService, subsequent requests will be sent to the same
backendService as determined by the BackendService's session affinity policy.
The value must be between 0 and 1000`,
},
"header_action": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1527,22 +1537,24 @@ prior to sending the response back to the client.`,
},
},
},
"weight": {
Type: schema.TypeInt,
Optional: true,
Description: `Specifies the fraction of traffic sent to backendService, computed as weight /
(sum of all weightedBackendService weights in routeAction) . The selection of a
backend service is determined only for new traffic. Once a user's request has
been directed to a backendService, subsequent requests will be sent to the same
backendService as determined by the BackendService's session affinity policy.
The value must be between 0 and 1000`,
},
},
},
},
},
},
},
"service": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `The backend service resource to which traffic is
directed if this rule is matched. If routeAction is additionally specified,
advanced routing actions like URL Rewrites, etc. take effect prior to sending
the request to the backend. However, if service is specified, routeAction cannot
contain any weightedBackendService s. Conversely, if routeAction specifies any
weightedBackendServices, service must not be specified. Only one of urlRedirect,
service or routeAction.weightedBackendService must be set.`,
},
"url_redirect": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -2808,6 +2820,7 @@ func flattenComputeUrlMapPathMatcherRouteRules(v interface{}, d *schema.Resource
}
transformed = append(transformed, map[string]interface{}{
"priority": flattenComputeUrlMapPathMatcherRouteRulesPriority(original["priority"], d),
"service": flattenComputeUrlMapPathMatcherRouteRulesService(original["service"], d),
"header_action": flattenComputeUrlMapPathMatcherRouteRulesHeaderAction(original["headerAction"], d),
"match_rules": flattenComputeUrlMapPathMatcherRouteRulesMatchRules(original["matchRules"], d),
"route_action": flattenComputeUrlMapPathMatcherRouteRulesRouteAction(original["routeAction"], d),
Expand All @@ -2826,6 +2839,13 @@ func flattenComputeUrlMapPathMatcherRouteRulesPriority(v interface{}, d *schema.
return v
}

func flattenComputeUrlMapPathMatcherRouteRulesService(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return v
}
return ConvertSelfLinkToV1(v.(string))
}

func flattenComputeUrlMapPathMatcherRouteRulesHeaderAction(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -4878,6 +4898,13 @@ func expandComputeUrlMapPathMatcherRouteRules(v interface{}, d TerraformResource
transformed["priority"] = transformedPriority
}

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

transformedHeaderAction, err := expandComputeUrlMapPathMatcherRouteRulesHeaderAction(original["header_action"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -4915,6 +4942,14 @@ func expandComputeUrlMapPathMatcherRouteRulesPriority(v interface{}, d Terraform
return v, nil
}

func expandComputeUrlMapPathMatcherRouteRulesService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("backendServices", v.(string), "project", d, config, true)
if err != nil {
return nil, fmt.Errorf("Invalid value for service: %s", err)
}
return f.RelativeLink(), nil
}

func expandComputeUrlMapPathMatcherRouteRulesHeaderAction(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
12 changes: 11 additions & 1 deletion website/docs/r/compute_url_map.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,16 @@ The `route_rules` block supports:
you could add rules numbered from 6 to 8, 10 to 11, and 13 to 15 in the
future without any impact on existing rules.

* `service` -
(Optional)
The backend service resource to which traffic is
directed if this rule is matched. If routeAction is additionally specified,
advanced routing actions like URL Rewrites, etc. take effect prior to sending
the request to the backend. However, if service is specified, routeAction cannot
contain any weightedBackendService s. Conversely, if routeAction specifies any
weightedBackendServices, service must not be specified. Only one of urlRedirect,
service or routeAction.weightedBackendService must be set.

* `header_action` -
(Optional)
Specifies changes to request and response headers that need to take effect for
Expand Down Expand Up @@ -1578,7 +1588,7 @@ The `weighted_backend_services` block supports:
headerAction in the enclosing HttpRouteRule, PathMatcher and UrlMap. Structure is documented below.

* `weight` -
(Optional)
(Required)
Specifies the fraction of traffic sent to backendService, computed as weight /
(sum of all weightedBackendService weights in routeAction) . The selection of a
backend service is determined only for new traffic. Once a user's request has
Expand Down