Skip to content

Commit

Permalink
Refactor localized policy resource and data sourxe
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jul 25, 2023
1 parent 2903e19 commit dcb0fa8
Show file tree
Hide file tree
Showing 16 changed files with 546 additions and 139 deletions.
8 changes: 4 additions & 4 deletions docs/data-sources/localized_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "sdwan_localized_policy Data Source - terraform-provider-sdwan"
subcategory: "Localized Policies"
description: |-
This data source can read a localized policy.
This data source can read the Localized Policy .
---

# sdwan_localized_policy (Data Source)

This data source can read a localized policy.
This data source can read the Localized Policy .

## Example Usage

Expand All @@ -23,7 +23,7 @@ data "sdwan_localized_policy" "example" {

### Required

- `id` (String) The id of the localized policy
- `id` (String) The id of the object

### Read-Only

Expand All @@ -40,7 +40,7 @@ data "sdwan_localized_policy" "example" {
- `ipv6_visibility_cache_entries` (Number) IPv6 visibility cache entries
- `log_frequency` (Number) Log frequency
- `name` (String) The name of the localized policy
- `version` (Number) The version of the localized policy
- `version` (Number) The version of the object

<a id="nestedatt--definitions"></a>
### Nested Schema for `definitions`
Expand Down
31 changes: 20 additions & 11 deletions docs/resources/localized_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
page_title: "sdwan_localized_policy Resource - terraform-provider-sdwan"
subcategory: "Localized Policies"
description: |-
This resource can manage a localized policy.
This resource can manage a Localized Policy .
---

# sdwan_localized_policy (Resource)

This resource can manage a localized policy.
This resource can manage a Localized Policy .

## Example Usage

```terraform
resource "sdwan_localized_policy" "test" {
name = "POLICY_1"
description = "My localized policy"
resource "sdwan_localized_policy" "example" {
name = "Example"
description = "My description"
flow_visibility_ipv4 = true
flow_visibility_ipv6 = true
application_visibility_ipv4 = true
Expand All @@ -26,10 +26,12 @@ resource "sdwan_localized_policy" "test" {
log_frequency = 1000
ipv4_visibility_cache_entries = 1000
ipv6_visibility_cache_entries = 1000
definitions = [{
id = sdwan_qos_map_policy_definition.qos_map.id
type = sdwan_qos_map_policy_definition.qos_map.type
}]
definitions = [
{
id = "2081c2f4-3f9f-4fee-8078-dcc8904e368d"
type = "acl"
}
]
}
```

Expand All @@ -44,13 +46,20 @@ resource "sdwan_localized_policy" "test" {
### Optional

- `application_visibility_ipv4` (Boolean) IPv4 application visibilty
- Default value: `true`
- `application_visibility_ipv6` (Boolean) IPv6 application visibilty
- Default value: `true`
- `cloud_qos` (Boolean) Cloud QoS
- Default value: `true`
- `cloud_qos_service_side` (Boolean) Cloud QoS service side
- Default value: `true`
- `definitions` (Attributes Set) List of policy definitions (see [below for nested schema](#nestedatt--definitions))
- `flow_visibility_ipv4` (Boolean) IPv4 flow visibilty
- Default value: `true`
- `flow_visibility_ipv6` (Boolean) IPv6 flow visibilty
- Default value: `true`
- `implicit_acl_logging` (Boolean) Implicit ACL logging
- Default value: `true`
- `ipv4_visibility_cache_entries` (Number) IPv4 visibility cache entries
- Range: `16`-`2000000`
- `ipv6_visibility_cache_entries` (Number) IPv6 visibility cache entries
Expand All @@ -60,8 +69,8 @@ resource "sdwan_localized_policy" "test" {

### Read-Only

- `id` (String) The id of the localized policy
- `version` (Number) The version of the localized policy
- `id` (String) The id of the object
- `version` (Number) The version of the object

<a id="nestedatt--definitions"></a>
### Nested Schema for `definitions`
Expand Down
16 changes: 9 additions & 7 deletions examples/resources/sdwan_localized_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "sdwan_localized_policy" "test" {
name = "POLICY_1"
description = "My localized policy"
resource "sdwan_localized_policy" "example" {
name = "Example"
description = "My description"
flow_visibility_ipv4 = true
flow_visibility_ipv6 = true
application_visibility_ipv4 = true
Expand All @@ -11,8 +11,10 @@ resource "sdwan_localized_policy" "test" {
log_frequency = 1000
ipv4_visibility_cache_entries = 1000
ipv6_visibility_cache_entries = 1000
definitions = [{
id = sdwan_qos_map_policy_definition.qos_map.id
type = sdwan_qos_map_policy_definition.qos_map.type
}]
definitions = [
{
id = "2081c2f4-3f9f-4fee-8078-dcc8904e368d"
type = "acl"
}
]
}
152 changes: 152 additions & 0 deletions gen/definitions/generic/localized_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
name: Localized Policy
rest_endpoint: /template/policy/vedge/
get_rest_endpoint: /template/policy/vedge/definition/
has_version: true
id_attribute: policyId
doc_category: Localized Policies
attributes:
- model_name: policyType
value: feature
- model_name: policyName
tf_name: name
type: String
mandatory: true
description: The name of the localized policy
example: Example
- model_name: policyDescription
tf_name: description
type: String
mandatory: true
description: The description of the localized policy
example: My description
- model_name: flowVisibility
data_path: [policyDefinition, settings]
tf_name: flow_visibility_ipv4
type: Bool
description: IPv4 flow visibilty
default_value: true
example: true
- model_name: flowVisibilityIPv6
data_path: [policyDefinition, settings]
tf_name: flow_visibility_ipv6
type: Bool
description: IPv6 flow visibilty
default_value: true
example: true
- model_name: appVisibility
data_path: [policyDefinition, settings]
tf_name: application_visibility_ipv4
type: Bool
description: IPv4 application visibilty
default_value: true
example: true
- model_name: appVisibilityIPv6
data_path: [policyDefinition, settings]
tf_name: application_visibility_ipv6
type: Bool
description: IPv6 application visibilty
default_value: true
example: true
- model_name: cloudQos
data_path: [policyDefinition, settings]
tf_name: cloud_qos
type: Bool
description: Cloud QoS
default_value: true
example: true
- model_name: cloudQosServiceSide
data_path: [policyDefinition, settings]
tf_name: cloud_qos_service_side
type: Bool
description: Cloud QoS service side
default_value: true
example: true
- model_name: implicitAclLogging
data_path: [policyDefinition, settings]
tf_name: implicit_acl_logging
type: Bool
description: Implicit ACL logging
default_value: true
example: true
- model_name: logFrequency
data_path: [policyDefinition, settings]
tf_name: log_frequency
type: Int64
min_int: 1
max_int: 2147483647
description: Log frequency
example: 1000
- model_name: ipVisibilityCacheEntries
data_path: [policyDefinition, settings]
tf_name: ipv4_visibility_cache_entries
type: Int64
min_int: 16
max_int: 2000000
description: IPv4 visibility cache entries
example: 1000
- model_name: ipV6VisibilityCacheEntries
data_path: [policyDefinition, settings]
tf_name: ipv6_visibility_cache_entries
type: Int64
min_int: 16
max_int: 2000000
description: IPv6 visibility cache entries
example: 1000
- model_name: assembly
data_path: [policyDefinition]
tf_name: definitions
type: Set
description: List of policy definitions
attributes:
- model_name: definitionId
tf_name: id
type: String
id: true
mandatory: true
description: Policy definition ID
example: 2081c2f4-3f9f-4fee-8078-dcc8904e368d
test_value: sdwan_acl_policy_definition.test.id
- tf_name: version
tf_only: true
type: Version
description: Policy definition version
exclude_test: true
- model_name: type
tf_name: type
type: String
mandatory: true
description: Policy definiton type
example: acl

test_prerequisites: |
resource "sdwan_acl_policy_definition" "test" {
name = "TF_TEST"
description = "Terraform test"
default_action = "drop"
sequences = [
{
id = 10
ip_type = "ipv4"
name = "Sequence 10"
base_action = "accept"
match_entries = [
{
type = "dscp"
dscp = 16
}
]
action_entries = [
{
type = "set"
set_parameters = [
{
type = "dscp"
dscp = 16
}
]
}
]
}
]
}
1 change: 0 additions & 1 deletion gen/doc_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var extraDocs = map[string]string{
"cli_device_template": "Device Templates",
"feature_device_template": "Device Templates",
"attach_feature_device_template": "Device Templates",
"localized_policy": "Localized Policies",
}

func SnakeCase(s string) string {
Expand Down
5 changes: 3 additions & 2 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type YamlConfig struct {
Name string `yaml:"name"`
Model string `yaml:"model"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
Type string `yaml:"type"`
MinimumVersion string `yaml:"minimum_version"`
DsDescription string `yaml:"ds_description"`
Expand Down Expand Up @@ -247,7 +248,7 @@ func HasVersionAttribute(attributes []YamlConfigAttribute) bool {
for _, attr := range attributes {
if attr.Type == "Version" || attr.Type == "Versions" {
return true
} else if attr.Type == "List" {
} else if attr.Type == "List" || attr.Type == "Set" {
if HasVersionAttribute(attr.Attributes) {
return true
}
Expand Down Expand Up @@ -437,7 +438,7 @@ func augmentGenericAttribute(attr *YamlConfigAttribute) {
if attr.TfName == "" {
attr.TfName = SnakeCase(attr.ModelName)
}
if attr.Type == "List" {
if attr.Type == "List" || attr.Type == "Set" {
for a := range attr.Attributes {
augmentGenericAttribute(&attr.Attributes[a])
}
Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: str()
model: str(required=False)
rest_endpoint: str(required=False)
get_rest_endpoint: str(required=False)
type: str(required=False)
minimum_version: str()
ds_description: str(required=False)
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/generic/data_source.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dcb0fa8

Please sign in to comment.