Skip to content

Commit

Permalink
Add fields to support configuring new Media CDN features via Terrafor…
Browse files Browse the repository at this point in the history
…m. (#12902)

[upstream:e108fe965dd81ce114643aa917834594eb5c2828]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 31, 2025
1 parent b8e279c commit c50a18c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12902.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
networkservices: added `compression_mode` and `allowed_methods` fields to `edge_cache_service` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ Defaults to 'edge-cache-token'.`,
},
},
},
"compression_mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"DISABLED", "AUTOMATIC", ""}),
Description: `Setting the compression mode to automatic enables dynamic compression for every eligible response.
When dynamic compression is enabled, it is recommended to also set a cache policy to maximize efficiency. Possible values: ["DISABLED", "AUTOMATIC"]`,
},
"cors_policy": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -826,6 +834,30 @@ specified.`,
},
},
},
"route_methods": {
Type: schema.TypeList,
Optional: true,
Description: `Allow overriding the set of methods that are allowed for this route.
When not set, Media CDN allows only "GET", "HEAD", and "OPTIONS".`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allowed_methods": {
Type: schema.TypeList,
Optional: true,
Description: `The non-empty set of HTTP methods that are allowed for this route.
Any combination of "GET", "HEAD", "OPTIONS", "PUT", "POST", "DELETE", and "PATCH".`,
MinItems: 1,
MaxItems: 7,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: verify.ValidateRegexp(`^(?:GET|HEAD|OPTIONS|PUT|POST|DELETE|PATCH)$`),
},
},
},
},
},
"url_redirect": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1619,6 +1651,7 @@ func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRule(v interfa
"priority": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRulePriority(original["priority"], d, config),
"description": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleDescription(original["description"], d, config),
"match_rule": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleMatchRule(original["matchRules"], d, config),
"route_methods": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethods(original["routeMethods"], d, config),
"header_action": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleHeaderAction(original["headerAction"], d, config),
"route_action": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteAction(original["routeAction"], d, config),
"origin": flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleOrigin(original["origin"], d, config),
Expand Down Expand Up @@ -1753,6 +1786,23 @@ func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleMatchRuleF
return v
}

func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethods(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["allowed_methods"] =
flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethodsAllowedMethods(original["allowedMethods"], d, config)
return []interface{}{transformed}
}
func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethodsAllowedMethods(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleHeaderAction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1895,6 +1945,8 @@ func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActio
flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionUrlRewrite(original["urlRewrite"], d, config)
transformed["cors_policy"] =
flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCorsPolicy(original["corsPolicy"], d, config)
transformed["compression_mode"] =
flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCompressionMode(original["compressionMode"], d, config)
return []interface{}{transformed}
}
func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCdnPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -2167,6 +2219,10 @@ func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActio
return v
}

func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCompressionMode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleOrigin(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -2437,6 +2493,13 @@ func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRule(v interfac
transformed["matchRules"] = transformedMatchRule
}

transformedRouteMethods, err := expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethods(original["route_methods"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedRouteMethods); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["routeMethods"] = transformedRouteMethods
}

transformedHeaderAction, err := expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleHeaderAction(original["header_action"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2680,6 +2743,29 @@ func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleMatchRuleFu
return v, nil
}

func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethods(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedAllowedMethods, err := expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethodsAllowedMethods(original["allowed_methods"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAllowedMethods); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["allowedMethods"] = transformedAllowedMethods
}

return transformed, nil
}

func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteMethodsAllowedMethods(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleHeaderAction(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -2898,6 +2984,13 @@ func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteAction
transformed["corsPolicy"] = transformedCorsPolicy
}

transformedCompressionMode, err := expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCompressionMode(original["compression_mode"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCompressionMode); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["compressionMode"] = transformedCompressionMode
}

return transformed, nil
}

Expand Down Expand Up @@ -3364,6 +3457,10 @@ func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteAction
return v, nil
}

func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleRouteActionCompressionMode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetworkServicesEdgeCacheServiceRoutingPathMatcherRouteRuleOrigin(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fields:
api_field: 'routing.path_matchers.route_rules.route_action.cdn_policy.signed_token_options.allowed_signature_algorithms'
- field: 'routing.path_matcher.route_rule.route_action.cdn_policy.signed_token_options.token_query_parameter'
api_field: 'routing.path_matchers.route_rules.route_action.cdn_policy.signed_token_options.token_query_parameter'
- field: 'routing.path_matcher.route_rule.route_action.compression_mode'
api_field: 'routing.path_matchers.route_rules.route_action.compression_mode'
- field: 'routing.path_matcher.route_rule.route_action.cors_policy.allow_credentials'
api_field: 'routing.path_matchers.route_rules.route_action.cors_policy.allow_credentials'
- field: 'routing.path_matcher.route_rule.route_action.cors_policy.allow_headers'
Expand All @@ -143,6 +145,8 @@ fields:
api_field: 'routing.path_matchers.route_rules.route_action.url_rewrite.path_prefix_rewrite'
- field: 'routing.path_matcher.route_rule.route_action.url_rewrite.path_template_rewrite'
api_field: 'routing.path_matchers.route_rules.route_action.url_rewrite.path_template_rewrite'
- field: 'routing.path_matcher.route_rule.route_methods.allowed_methods'
api_field: 'routing.path_matchers.route_rules.route_methods.allowed_methods'
- field: 'routing.path_matcher.route_rule.url_redirect.host_redirect'
api_field: 'routing.path_matchers.route_rules.url_redirect.host_redirect'
- field: 'routing.path_matcher.route_rule.url_redirect.https_redirect'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ resource "google_network_services_edge_cache_service" "served" {
cache_mode = "CACHE_ALL_STATIC"
default_ttl = "3600s"
}
compression_mode = "AUTOMATIC"
}
header_action {
response_header_to_add {
Expand Down Expand Up @@ -133,6 +134,9 @@ resource "google_network_services_edge_cache_service" "served" {
default_ttl = "3600s"
}
}
route_methods {
allowed_methods = ["GET", "HEAD", "OPTIONS", "PUT", "POST", "DELETE", "PATCH"]
}
header_action {
response_header_to_add {
header_name = "x-cache-status"
Expand Down
19 changes: 19 additions & 0 deletions website/docs/r/network_services_edge_cache_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ The following arguments are supported:
within a given matchRule have AND semantics. All predicates within a matchRule must match for the request to match the rule.
Structure is [documented below](#nested_routing_path_matcher_path_matcher_route_rule_route_rule_match_rule).

* `route_methods` -
(Optional)
Allow overriding the set of methods that are allowed for this route.
When not set, Media CDN allows only "GET", "HEAD", and "OPTIONS".
Structure is [documented below](#nested_routing_path_matcher_path_matcher_route_rule_route_rule_route_methods).

* `header_action` -
(Optional)
The header actions, including adding & removing headers, for requests that match this route.
Expand Down Expand Up @@ -592,6 +598,13 @@ The following arguments are supported:
(Optional)
The queryParameterMatch matches if the value of the parameter exactly matches the contents of exactMatch.

<a name="nested_routing_path_matcher_path_matcher_route_rule_route_rule_route_methods"></a>The `route_methods` block supports:

* `allowed_methods` -
(Optional)
The non-empty set of HTTP methods that are allowed for this route.
Any combination of "GET", "HEAD", "OPTIONS", "PUT", "POST", "DELETE", and "PATCH".

<a name="nested_routing_path_matcher_path_matcher_route_rule_route_rule_header_action"></a>The `header_action` block supports:

* `request_header_to_add` -
Expand Down Expand Up @@ -674,6 +687,12 @@ The following arguments are supported:
CORSPolicy defines Cross-Origin-Resource-Sharing configuration, including which CORS response headers will be set.
Structure is [documented below](#nested_routing_path_matcher_path_matcher_route_rule_route_rule_route_action_cors_policy).

* `compression_mode` -
(Optional)
Setting the compression mode to automatic enables dynamic compression for every eligible response.
When dynamic compression is enabled, it is recommended to also set a cache policy to maximize efficiency.
Possible values are: `DISABLED`, `AUTOMATIC`.


<a name="nested_routing_path_matcher_path_matcher_route_rule_route_rule_route_action_cdn_policy"></a>The `cdn_policy` block supports:

Expand Down

0 comments on commit c50a18c

Please sign in to comment.