Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"constraints": [
{
"customValidatorId": "ppx-management-service.ppx-management-service:8080/internal/settings-validation/v0.1/validate-container/ingest-source-container-validator",
"customValidatorId": "ingest-source-container-validator",
"skipAsyncValidation": false,
"timeout": 10,
"type": "CUSTOM_VALIDATOR_REF"
Expand Down Expand Up @@ -71,6 +71,22 @@
],
"type": "enum"
},
"FieldValueExtractionType": {
"description": "",
"displayName": "Field value extraction type",
"documentation": "",
"items": [
{
"displayName": "Constant literal will be assigned to destination field.",
"value": "constant"
},
{
"displayName": "Dynamic value from field or default will be assigned to destination field.",
"value": "field"
}
],
"type": "enum"
},
"IngestSourceType": {
"description": "",
"displayName": "Ingest Source Type",
Expand Down Expand Up @@ -835,10 +851,55 @@
"displayName": "FieldExtractionEntry",
"documentation": "",
"properties": {
"constantFieldName": {
"constraints": [
{
"maxLength": 350,
"type": "LENGTH"
},
{
"type": "NOT_BLANK"
}
],
"default": "",
"description": "",
"displayName": "Destination field name",
"documentation": "",
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": false,
"precondition": {
"expectedValue": "constant",
"property": "extractionType",
"type": "EQUALS"
},
"type": "text"
},
"constantValue": {
"constraints": [
{
"maxLength": 512,
"type": "LENGTH"
}
],
"default": "",
"description": "",
"displayName": "Constant value to be assigned to field",
"documentation": "",
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": false,
"precondition": {
"expectedValue": "constant",
"property": "extractionType",
"type": "EQUALS"
},
"type": "text"
},
"defaultValue": {
"constraints": [
{
"maxLength": 500,
"maxLength": 512,
"minLength": 1,
"type": "LENGTH"
}
Expand All @@ -849,14 +910,22 @@
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": true,
"precondition": {
"expectedValue": "field",
"property": "extractionType",
"type": "EQUALS"
},
"type": "text"
},
"destinationFieldName": {
"constraints": [
{
"maxLength": 500,
"maxLength": 350,
"minLength": 1,
"type": "LENGTH"
},
{
"type": "NOT_BLANK"
}
],
"description": "",
Expand All @@ -865,13 +934,33 @@
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": true,
"precondition": {
"expectedValue": "field",
"property": "extractionType",
"type": "EQUALS"
},
"type": "text"
},
"extractionType": {
"default": "field",
"description": "",
"displayName": "Field value extraction type",
"documentation": "",
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": false,
"type": {
"$ref": "#/enums/FieldValueExtractionType"
}
},
"sourceFieldName": {
"constraints": [
{
"maxLength": 256,
"type": "LENGTH"
},
{
"type": "NOT_BLANK"
}
],
"default": "",
Expand All @@ -881,10 +970,15 @@
"maxObjects": 1,
"modificationPolicy": "DEFAULT",
"nullable": false,
"precondition": {
"expectedValue": "field",
"property": "extractionType",
"type": "EQUALS"
},
"type": "text"
}
},
"summaryPattern": "{sourceFieldName} - {destinationFieldName} - {defaultValue}",
"summaryPattern": "{extractionType} - {sourceFieldName} - {destinationFieldName} - {defaultValue} - {constantFieldName} - {constantValue}",
"type": "object",
"version": "0",
"versionInfo": ""
Expand Down Expand Up @@ -3156,5 +3250,5 @@
"versionInfo": ""
}
},
"version": "1.43"
"version": "1.51"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings/services/settings20"
)

const SchemaVersion = "1.43"
const SchemaVersion = "1.51"
const SchemaID = "builtin:openpipeline.bizevents.ingest-sources"

func Service(credentials *rest.Credentials) settings.CRUDService[*service.Settings] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,24 @@ func TestOpenPipelineBizeventsIngestSourcesUnmarshal(t *testing.T) {
entries := new(ingestsources.FieldExtractionEntries)
validEntries := []*ingestsources.FieldExtractionEntry{
{
DefaultValue: testing2.ToPointer("value"),
DestinationFieldName: nil,
SourceFieldName: "",
DefaultValue: testing2.ToPointer("value"),
},
{
DefaultValue: nil,
DestinationFieldName: testing2.ToPointer("value"),
SourceFieldName: "",
},
{
DefaultValue: nil,
DestinationFieldName: nil,
SourceFieldName: "value",
SourceFieldName: testing2.ToPointer("value"),
},
{
DefaultValue: testing2.ToPointer("value1"),
DestinationFieldName: testing2.ToPointer("value2"),
SourceFieldName: "value3",
SourceFieldName: testing2.ToPointer("value3"),
},
}
validWithEmpty := ingestsources.FieldExtractionEntries{
{
DefaultValue: nil,
DestinationFieldName: nil,
SourceFieldName: "",
ExtractionType: "field",
},
}
validWithEmpty := ingestsources.FieldExtractionEntries{{}}
validWithEmpty = append(validWithEmpty, validEntries...)
err := entries.UnmarshalHCL(testing2.MockDecoder{Elements: map[string]any{"dimension": validWithEmpty}})
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ var FieldExtractionTypes = struct {
"includeAll",
}

type FieldValueExtractionType string

var FieldValueExtractionTypes = struct {
Constant FieldValueExtractionType
Field FieldValueExtractionType
}{
"constant",
"field",
}

type IngestSourceType string

var IngestSourceTypes = struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type FieldExtraction struct {
Exclude []string `json:"exclude,omitempty"` // Fields
Include FieldExtractionEntries `json:"include,omitempty"` // Fields
Type FieldExtractionType `json:"type"` // Fields Extraction type. Possible Values: `exclude`, `include`, `includeAll`
Type FieldExtractionType `json:"type"` // Fields Extraction type. Possible values: `exclude`, `include`, `includeAll`
}

func (me *FieldExtraction) Schema() map[string]*schema.Schema {
Expand All @@ -46,7 +46,7 @@ func (me *FieldExtraction) Schema() map[string]*schema.Schema {
},
"type": {
Type: schema.TypeString,
Description: "Fields Extraction type. Possible Values: `exclude`, `include`, `includeAll`",
Description: "Fields Extraction type. Possible values: `exclude`, `include`, `includeAll`",
Required: true,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package ingestsources

import (
"fmt"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/opt"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -47,8 +50,9 @@ func (me *FieldExtractionEntries) UnmarshalHCL(decoder hcl.Decoder) error {
// https://github.com/hashicorp/terraform-plugin-sdk/issues/895
// Only known workaround is to ignore these blocks
newEntries := FieldExtractionEntries{}
var emptyItem FieldExtractionEntry
for _, entry := range *me {
if entry.SourceFieldName != "" || entry.DestinationFieldName != nil || entry.DefaultValue != nil {
if *entry != emptyItem {
newEntries = append(newEntries, entry)
}
}
Expand All @@ -57,43 +61,87 @@ func (me *FieldExtractionEntries) UnmarshalHCL(decoder hcl.Decoder) error {
}

type FieldExtractionEntry struct {
DefaultValue *string `json:"defaultValue,omitempty"` // Default value
DestinationFieldName *string `json:"destinationFieldName,omitempty"` // Destination field name
SourceFieldName string `json:"sourceFieldName"` // Source field name
ConstantFieldName *string `json:"constantFieldName,omitempty"` // Destination field name
ConstantValue *string `json:"constantValue,omitempty"` // Constant value to be assigned to field
DefaultValue *string `json:"defaultValue,omitempty"` // Default value
DestinationFieldName *string `json:"destinationFieldName,omitempty"` // Destination field name
ExtractionType FieldValueExtractionType `json:"extractionType"` // Field value extraction type. Possible values: `constant`, `field`
SourceFieldName *string `json:"sourceFieldName,omitempty"` // Source field name
}

func (me *FieldExtractionEntry) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"constant_field_name": {
Type: schema.TypeString,
Description: "Destination field name",
Optional: true, // precondition
},
"constant_value": {
Type: schema.TypeString,
Description: "Constant value to be assigned to field",
Optional: true, // precondition
},
"default_value": {
Type: schema.TypeString,
Description: "Default value",
Optional: true, // nullable
Optional: true, // nullable & precondition
},
"destination_field_name": {
Type: schema.TypeString,
Description: "Destination field name",
Optional: true, // nullable
Optional: true, // nullable & precondition
},
"extraction_type": {
Type: schema.TypeString,
Description: "Field value extraction type. Possible values: `constant`, `field`",
Optional: true,
Default: "field", // new required attribute. Fallback to "field"
},
"source_field_name": {
Type: schema.TypeString,
Description: "Source field name",
Required: true,
Optional: true, // precondition
},
}
}

func (me *FieldExtractionEntry) MarshalHCL(properties hcl.Properties) error {
return properties.EncodeAll(map[string]any{
"constant_field_name": me.ConstantFieldName,
"constant_value": me.ConstantValue,
"default_value": me.DefaultValue,
"destination_field_name": me.DestinationFieldName,
"extraction_type": me.ExtractionType,
"source_field_name": me.SourceFieldName,
})
}

func (me *FieldExtractionEntry) HandlePreconditions() error {
if (me.ConstantFieldName == nil) && (string(me.ExtractionType) == "constant") {
me.ConstantFieldName = opt.NewString("")
}
if (me.ConstantValue == nil) && (string(me.ExtractionType) == "constant") {
me.ConstantValue = opt.NewString("")
}
if (me.SourceFieldName == nil) && (string(me.ExtractionType) == "field") {
me.SourceFieldName = opt.NewString("")
}
if (me.DefaultValue != nil) && (string(me.ExtractionType) != "field") {
return fmt.Errorf("'default_value' must not be specified if 'extraction_type' is set to '%v'", me.ExtractionType)
}
if (me.DestinationFieldName != nil) && (string(me.ExtractionType) != "field") {
return fmt.Errorf("'destination_field_name' must not be specified if 'extraction_type' is set to '%v'", me.ExtractionType)
}
return nil
}

func (me *FieldExtractionEntry) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"constant_field_name": &me.ConstantFieldName,
"constant_value": &me.ConstantValue,
"default_value": &me.DefaultValue,
"destination_field_name": &me.DestinationFieldName,
"extraction_type": &me.ExtractionType,
"source_field_name": &me.SourceFieldName,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type GenericValueAssignment struct {
Constant *string `json:"constant,omitempty"` // Constant value
Field *ValueAssignmentFromFieldEntry `json:"field,omitempty"` // Value from field
MultiValueConstant []string `json:"multiValueConstant,omitempty"` // Constant multi value
Type AssignmentType `json:"type"` // Type of value assignment. Possible Values: `constant`, `field`, `multiValueConstant`
Type AssignmentType `json:"type"` // Type of value assignment. Possible values: `constant`, `field`, `multiValueConstant`
}

func (me *GenericValueAssignment) Schema() map[string]*schema.Schema {
Expand All @@ -55,7 +55,7 @@ func (me *GenericValueAssignment) Schema() map[string]*schema.Schema {
},
"type": {
Type: schema.TypeString,
Description: "Type of value assignment. Possible Values: `constant`, `field`, `multiValueConstant`",
Description: "Type of value assignment. Possible values: `constant`, `field`, `multiValueConstant`",
Required: true,
},
}
Expand Down
Loading
Loading