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

Disallow creating GW policy of Read-Only category #860

Merged
merged 1 commit into from
Apr 6, 2023
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
2 changes: 2 additions & 0 deletions nsxt/data_source_nsxt_policy_gateway_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
)

var gatewayPolicyCategoryValues = []string{"Emergency", "SystemRules", "SharedPreRules", "LocalGatewayRules", "AutoServiceRules", "Default"}

func dataSourceNsxtPolicyGatewayPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyGatewayPolicyRead,
Expand Down
4 changes: 2 additions & 2 deletions nsxt/policy_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var securityPolicyIPProtocolValues = []string{"NONE", model.Rule_IP_PROTOCOL_IPV

// TODO: change last string to sdk constant when available
var securityPolicyActionValues = []string{model.Rule_ACTION_ALLOW, model.Rule_ACTION_DROP, model.Rule_ACTION_REJECT, "JUMP_TO_APPLICATION"}
var gatewayPolicyCategoryValues = []string{"Emergency", "SystemRules", "SharedPreRules", "LocalGatewayRules", "AutoServiceRules", "Default"}
var gatewayPolicyCategoryWritableValues = []string{"Emergency", "SharedPreRules", "LocalGatewayRules", "Default"}
var policyFailOverModeValues = []string{model.Tier1_FAILOVER_MODE_PREEMPTIVE, model.Tier1_FAILOVER_MODE_NON_PREEMPTIVE}
var failOverModeDefaultPolicyT0Value = model.Tier0_FAILOVER_MODE_NON_PREEMPTIVE
var defaultPolicyLocaleServiceID = "default"
Expand Down Expand Up @@ -288,7 +288,7 @@ func getPolicyGatewayPolicySchema() map[string]*schema.Schema {
secPolicy := getPolicySecurityPolicySchema(false)
// GW Policies don't support scope
delete(secPolicy, "scope")
secPolicy["category"].ValidateFunc = validation.StringInSlice(gatewayPolicyCategoryValues, false)
secPolicy["category"].ValidateFunc = validation.StringInSlice(gatewayPolicyCategoryWritableValues, false)
// GW Policy rules require scope to be set
secPolicy["rule"] = getSecurityPolicyAndGatewayRulesSchema(true, false, true)
return secPolicy
Expand Down
4 changes: 4 additions & 0 deletions nsxt/resource_nsxt_policy_predefined_gateway_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func updatePolicyPredefinedGatewayPolicy(id string, d *schema.ResourceData, m in
return err
}

if predefinedPolicy.Category != nil && *predefinedPolicy.Category == "SystemRules" {
return fmt.Errorf("System policy can not be modified")
}

if d.HasChange("description") {
description := d.Get("description").(string)
predefinedPolicy.Description = &description
Expand Down