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

Move expr to GA #5532

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
3 changes: 3 additions & 0 deletions .changelog/3028.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: `google_compute_security_policy` `rule.match.expr` field is now GA
```
3 changes: 0 additions & 3 deletions .changelog/3034.txt

This file was deleted.

60 changes: 60 additions & 0 deletions google/resource_compute_security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
// },
},
},
},
},
},
},
Expand Down Expand Up @@ -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{})),
}
}

Expand All @@ -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 {
Expand All @@ -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}
Expand All @@ -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<project>[^/]+)/global/securityPolicies/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config); err != nil {
Expand Down