diff --git a/pkg/properties/normalized.go b/pkg/properties/normalized.go index 911d416..ea4a7b8 100644 --- a/pkg/properties/normalized.go +++ b/pkg/properties/normalized.go @@ -158,6 +158,7 @@ type SpecParam struct { Name *NameVariant Description string `json:"description" yaml:"description"` TerraformProviderConfig *SpecParamTerraformProviderConfig `json:"terraform_provider_config" yaml:"terraform_provider_config"` + IsNil bool `json:"-" yaml:"-"` Type string `json:"type" yaml:"type"` Default string `json:"default" yaml:"default"` Required bool `json:"required" yaml:"required"` @@ -346,6 +347,7 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam var defaultVal string + var paramTypeIsNil bool var innerSpec *Spec var itemsSpec SpecParamItems @@ -408,7 +410,8 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam case *parameter.EnumSpec: defaultVal = spec.Default case *parameter.NilSpec: - specType = "string" + paramTypeIsNil = true + specType = "" case *parameter.SimpleSpec: if typed, ok := spec.Default.(string); ok { defaultVal = typed @@ -453,6 +456,7 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam specParameter := &SpecParam{ Description: schemaSpec.Description, Type: specType, + IsNil: paramTypeIsNil, Default: defaultVal, Required: schemaSpec.Required, Sensitive: sensitive, diff --git a/pkg/translate/terraform_provider/funcs.go b/pkg/translate/terraform_provider/funcs.go index 6213e01..6d7b5a5 100644 --- a/pkg/translate/terraform_provider/funcs.go +++ b/pkg/translate/terraform_provider/funcs.go @@ -957,11 +957,17 @@ func createSchemaSpecForParameter(schemaTyp schemaType, manager *imports.Manager }) } + validatorFn := "ExactlyOneOf" var expressions []string for _, elt := range param.Spec.OneOf { if elt.IsPrivateParameter() { continue } + + if elt.IsNil { + validatorFn = "ConflictsWith" + } + expressions = append(expressions, fmt.Sprintf(`path.MatchRelative().AtParent().AtName("%s")`, elt.Name.Underscore)) } @@ -973,7 +979,7 @@ func createSchemaSpecForParameter(schemaTyp schemaType, manager *imports.Manager } functions := []validatorFunctionCtx{{ - Function: "ExactlyOneOf", + Function: validatorFn, Expressions: expressions, }} @@ -1418,16 +1424,21 @@ func createSchemaSpecForNormalization(resourceTyp properties.ResourceType, schem schemas = append(schemas, createSchemaSpecForParameter(schemaTyp, manager, structName, packageName, elt, nil)...) } + validatorFn := "ExactlyOneOf" var expressions []string for _, elt := range spec.Spec.OneOf { if elt.IsPrivateParameter() { continue } + + if elt.IsNil { + validatorFn = "ConflictsWith" + } expressions = append(expressions, fmt.Sprintf(`path.MatchRelative().AtParent().AtName("%s")`, elt.Name.Underscore)) } functions := []validatorFunctionCtx{{ - Function: "ExactlyOneOf", + Function: validatorFn, Expressions: expressions, }} diff --git a/specs/policies/network-address-translation.yaml b/specs/policies/network-address-translation.yaml index 02af4d6..ee085bd 100644 --- a/specs/policies/network-address-translation.yaml +++ b/specs/policies/network-address-translation.yaml @@ -344,10 +344,36 @@ spec: type: list profiles: - type: member - xpath: [tags] + xpath: [tag] spec: items: type: string + - name: target + type: object + profiles: + - xpath: [target] + spec: + params: + - name: devices + type: list + profiles: + - type: entry + xpath: [devices] + spec: + items: + type: string + - name: tags + type: list + profiles: + - type: member + xpath: [tags] + spec: + items: + type: string + - name: negate + type: bool + profiles: + - xpath: [negate] - name: disabled type: bool profiles: @@ -372,6 +398,10 @@ spec: spec: max: 127 variants: + - name: none + type: nil + profiles: + - xpath: [] - name: destination-translation type: object profiles: