From 12a8ddbf9538bb99d92aa49e044d93af41e7c506 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 29 Jan 2020 10:16:36 -0800 Subject: [PATCH] Move expr to GA (#3028) (#5532) Signed-off-by: Modular Magician --- .changelog/3028.txt | 3 ++ .changelog/3034.txt | 3 -- google/resource_compute_security_policy.go | 60 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .changelog/3028.txt delete mode 100644 .changelog/3034.txt diff --git a/.changelog/3028.txt b/.changelog/3028.txt new file mode 100644 index 00000000000..56491289651 --- /dev/null +++ b/.changelog/3028.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: `google_compute_security_policy` `rule.match.expr` field is now GA +``` diff --git a/.changelog/3034.txt b/.changelog/3034.txt deleted file mode 100644 index 6ab04617859..00000000000 --- a/.changelog/3034.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:bug -sql: undeprecated `settings.ip_configuration.authorized_networks.expiration_time` -``` diff --git a/google/resource_compute_security_policy.go b/google/resource_compute_security_policy.go index 9390103dab9..e198374c125 100644 --- a/google/resource_compute_security_policy.go +++ b/google/resource_compute_security_policy.go @@ -93,6 +93,33 @@ func resourceComputeSecurityPolicy() *schema.Resource { Optional: true, ValidateFunc: validation.StringInSlice([]string{"SRC_IPS_V1"}, false), }, + + "expr": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "expression": { + Type: schema.TypeString, + Required: true, + }, + // These fields are not yet supported (Issue terraform-providers/terraform-provider-google#4497: mbang) + // "title": { + // Type: schema.TypeString, + // Optional: true, + // }, + // "description": { + // Type: schema.TypeString, + // Optional: true, + // }, + // "location": { + // Type: schema.TypeString, + // Optional: true, + // }, + }, + }, + }, }, }, }, @@ -330,6 +357,7 @@ func expandSecurityPolicyMatch(configured []interface{}) *compute.SecurityPolicy return &compute.SecurityPolicyRuleMatcher{ VersionedExpr: data["versioned_expr"].(string), Config: expandSecurityPolicyMatchConfig(data["config"].([]interface{})), + Expr: expandSecurityPolicyMatchExpr(data["expr"].([]interface{})), } } @@ -344,6 +372,21 @@ func expandSecurityPolicyMatchConfig(configured []interface{}) *compute.Security } } +func expandSecurityPolicyMatchExpr(expr []interface{}) *compute.Expr { + if len(expr) == 0 || expr[0] == nil { + return nil + } + + data := expr[0].(map[string]interface{}) + return &compute.Expr{ + Expression: data["expression"].(string), + // These fields are not yet supported (Issue terraform-providers/terraform-provider-google#4497: mbang) + // Title: data["title"].(string), + // Description: data["description"].(string), + // Location: data["location"].(string), + } +} + func flattenSecurityPolicyRules(rules []*compute.SecurityPolicyRule) []map[string]interface{} { rulesSchema := make([]map[string]interface{}, 0, len(rules)) for _, rule := range rules { @@ -368,6 +411,7 @@ func flattenMatch(match *compute.SecurityPolicyRuleMatcher) []map[string]interfa data := map[string]interface{}{ "versioned_expr": match.VersionedExpr, "config": flattenMatchConfig(match.Config), + "expr": flattenMatchExpr(match), } return []map[string]interface{}{data} @@ -385,6 +429,22 @@ func flattenMatchConfig(conf *compute.SecurityPolicyRuleMatcherConfig) []map[str return []map[string]interface{}{data} } +func flattenMatchExpr(match *compute.SecurityPolicyRuleMatcher) []map[string]interface{} { + if match.Expr == nil { + return nil + } + + data := map[string]interface{}{ + "expression": match.Expr.Expression, + // These fields are not yet supported (Issue terraform-providers/terraform-provider-google#4497: mbang) + // "title": match.Expr.Title, + // "description": match.Expr.Description, + // "location": match.Expr.Location, + } + + return []map[string]interface{}{data} +} + func resourceSecurityPolicyStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { config := meta.(*Config) if err := parseImportId([]string{"projects/(?P[^/]+)/global/securityPolicies/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config); err != nil {