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

Resolve Issue #364 #368

Merged
merged 2 commits into from
Nov 21, 2024
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
4 changes: 2 additions & 2 deletions docs/data-sources/service_ipv4_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ Read-Only:

Read-Only:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Read-Only:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number
4 changes: 2 additions & 2 deletions docs/data-sources/service_ipv6_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ Read-Only:

Read-Only:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Read-Only:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number
4 changes: 2 additions & 2 deletions docs/data-sources/transport_ipv4_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ Read-Only:

Read-Only:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Read-Only:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number
4 changes: 2 additions & 2 deletions docs/data-sources/transport_ipv6_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ Read-Only:

Read-Only:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Read-Only:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number
4 changes: 2 additions & 2 deletions docs/resources/service_ipv4_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ Optional:

Optional:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Optional:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number

## Import

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_ipv6_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ Optional:

Optional:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Optional:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number

## Import

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/transport_ipv4_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ Optional:

Optional:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Optional:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number

## Import

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/transport_ipv6_acl_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ Optional:

Optional:

- `port` (Number) destination port range or individual port number
- `port` (String) destination port range or individual port number


<a id="nestedatt--sequences--match_entries--source_ports"></a>
### Nested Schema for `sequences.match_entries.source_ports`

Optional:

- `port` (Number) source port range or individual port number
- `port` (String) source port range or individual port number

## Import

Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/profile_parcels/service_ipv4_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ attributes:
exclude_null: true
attributes:
- model_name: sourcePort
type: StringInt64
id: true
tf_name: port
example: 8000
- model_name: refId
Expand All @@ -72,6 +74,8 @@ attributes:
attributes:
- model_name: destinationPort
tf_name: port
type: StringInt64
id: true
example: 9000
exclude_test: true
- model_name: tcp
Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/profile_parcels/service_ipv6_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ attributes:
attributes:
- model_name: sourcePort
tf_name: port
type: StringInt64
id: true
example: 8000
- model_name: refId
data_path: [destinationDataPrefix, destinationDataPrefixList]
Expand All @@ -64,6 +66,8 @@ attributes:
attributes:
- model_name: destinationPort
tf_name: port
type: StringInt64
id: true
example: 9000
exclude_test: true
- model_name: tcp
Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/profile_parcels/transport_ipv4_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ attributes:
attributes:
- model_name: sourcePort
tf_name: port
type: StringInt64
id: true
example: 8000
- model_name: refId
data_path: [destinationDataPrefix, destinationDataPrefixList]
Expand All @@ -72,6 +74,8 @@ attributes:
attributes:
- model_name: destinationPort
tf_name: port
type: StringInt64
id: true
example: 9000
exclude_test: true
- model_name: tcp
Expand Down
4 changes: 4 additions & 0 deletions gen/definitions/profile_parcels/transport_ipv6_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ attributes:
attributes:
- model_name: sourcePort
tf_name: port
type: StringInt64
id: true
example: 8000
- model_name: refId
data_path: [destinationDataPrefix, destinationDataPrefixList]
Expand All @@ -64,6 +66,8 @@ attributes:
attributes:
- model_name: destinationPort
tf_name: port
type: StringInt64
id: true
example: 9000
exclude_test: true
- model_name: tcp
Expand Down
19 changes: 15 additions & 4 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ func IsInt64ListSet(attribute YamlConfigAttribute) bool {
return false
}

// Templating helper function to return true if type is StringInt64
func IsStringInt64(attribute YamlConfigAttribute) bool {
if attribute.Type == "StringInt64" {
return true
}
return false
}

// Templating helper function to return true if type is a list or set with nested elements
func IsNestedListSet(attribute YamlConfigAttribute) bool {
if (attribute.Type == "List" || attribute.Type == "Set") && attribute.ElementType == "" {
Expand Down Expand Up @@ -543,6 +551,7 @@ var functions = template.FuncMap{
"isSet": IsSet,
"isStringListSet": IsStringListSet,
"isInt64ListSet": IsInt64ListSet,
"isStringInt64": IsStringInt64,
"isNestedListSet": IsNestedListSet,
"isNestedList": IsNestedList,
"isNestedSet": IsNestedSet,
Expand Down Expand Up @@ -800,8 +809,10 @@ func parseProfileParcelAttribute(attr *YamlConfigAttribute, model gjson.Result,
}

if t.Exists() {
if t.Get("properties.value.type").String() == "string" || t.Get("properties.value.anyOf.0.type").String() == "string" || t.Get("properties.value.oneOf.0.type").String() == "string" {
attr.Type = "String"
if attr.Type == "String" || attr.Type == "StringInt64" || t.Get("properties.value.type").String() == "string" || t.Get("properties.value.anyOf.0.type").String() == "string" || t.Get("properties.value.oneOf.0.type").String() == "string" {
if attr.Type != "StringInt64" {
attr.Type = "String"
}
if value := t.Get("properties.value.minLength"); value.Exists() {
attr.StringMinLength = value.Int()
}
Expand All @@ -816,9 +827,9 @@ func parseProfileParcelAttribute(attr *YamlConfigAttribute, model gjson.Result,
attr.EnumValues = append(attr.EnumValues, v.String())
}
}
} else if t.Get("properties.value.type").String() == "boolean" {
} else if attr.Type == "Bool" || t.Get("properties.value.type").String() == "boolean" {
attr.Type = "Bool"
} else if t.Get("properties.value.type").String() == "integer" || t.Get("properties.value.type").String() == "number" || t.Get("properties.value.oneOf.0.type").String() == "integer" || t.Get("properties.value.oneOf.0.type").String() == "number" {
} else if attr.Type == "Int64" || t.Get("properties.value.type").String() == "integer" || t.Get("properties.value.type").String() == "number" || t.Get("properties.value.oneOf.0.type").String() == "integer" || t.Get("properties.value.oneOf.0.type").String() == "number" {

if value := t.Get("properties.value.multipleOf"); value.Exists() {
attr.Type = "Float64"
Expand Down
2 changes: 1 addition & 1 deletion gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ attribute:
model_name: str(required=False) # Name of the attribute in the model (payload)
response_model_name: str(required=False) # Name of the attribute in the model (response payload)
tf_name: str(required=False) # Name of the attribute in the Terraform resource, by default derived from model_name
type: enum('String', 'Int64', 'Bool', 'List', 'Set', 'Version', 'Versions', required=False) # Type of the attribute
type: enum('String', 'Int64', 'StringInt64', 'Bool', 'List', 'Set', 'Version', 'Versions', required=False) # Type of the attribute
element_type: enum('String', 'Int64', required=False) # only relevant if type is either 'List' or 'Set'
object_type: enum('object', 'tree', 'list', required=False) # Feature template schema object type
model_type_string: bool(required=False) # Set to true if element should be added as string to payload
Expand Down
8 changes: 4 additions & 4 deletions gen/templates/profile_parcels/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (d *{{camelCase .Name}}ProfileParcelDataSource) Schema(ctx context.Context,
},
{{- range .Attributes}}
{{- if not .Value}}
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else}}{{.Type}}{{end}}Attribute{
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else if isStringInt64 .}}String{{else}}{{.Type}}{{end}}Attribute{
MarkdownDescription: "{{.Description}}",
{{- if isListSet .}}
ElementType: types.{{.ElementType}}Type,
Expand All @@ -95,7 +95,7 @@ func (d *{{camelCase .Name}}ProfileParcelDataSource) Schema(ctx context.Context,
Attributes: map[string]schema.Attribute{
{{- range .Attributes}}
{{- if not .Value}}
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else}}{{.Type}}{{end}}Attribute{
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else if isStringInt64 .}}String{{else}}{{.Type}}{{end}}Attribute{
MarkdownDescription: "{{.Description}}",
{{- if isListSet .}}
ElementType: types.{{.ElementType}}Type,
Expand All @@ -106,7 +106,7 @@ func (d *{{camelCase .Name}}ProfileParcelDataSource) Schema(ctx context.Context,
Attributes: map[string]schema.Attribute{
{{- range .Attributes}}
{{- if not .Value}}
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else}}{{.Type}}{{end}}Attribute{
"{{.TfName}}": schema.{{if isNestedListSet .}}{{.Type}}Nested{{else if isList .}}List{{else if isSet .}}Set{{else if isStringInt64 .}}String{{else}}{{.Type}}{{end}}Attribute{
MarkdownDescription: "{{.Description}}",
{{- if isListSet .}}
ElementType: types.{{.ElementType}}Type,
Expand All @@ -117,7 +117,7 @@ func (d *{{camelCase .Name}}ProfileParcelDataSource) Schema(ctx context.Context,
Attributes: map[string]schema.Attribute{
{{- range .Attributes}}
{{- if not .Value}}
"{{.TfName}}": schema.{{if isList .}}List{{else if isSet .}}Set{{else}}{{.Type}}{{end}}Attribute{
"{{.TfName}}": schema.{{if isList .}}List{{else if isSet .}}Set{{else if isStringInt64 .}}String{{else}}{{.Type}}{{end}}Attribute{
MarkdownDescription: "{{.Description}}",
{{- if isListSet .}}
ElementType: types.{{.ElementType}}Type,
Expand Down
Loading
Loading