Skip to content

Commit dbe6c70

Browse files
committed
feat: update dynatrace_openpipeline_v2_usersessions_* to 1.51
Also slightly changed/updated the existing empty-set workaround to be more future-proof. Adds new properties and preconditions
1 parent 01d49a7 commit dbe6c70

28 files changed

+400
-113
lines changed

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/schema.json

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"constraints": [
66
{
7-
"customValidatorId": "ppx-management-service.ppx-management-service:8080/internal/settings-validation/v0.1/validate-container/ingest-source-container-validator",
7+
"customValidatorId": "ingest-source-container-validator",
88
"skipAsyncValidation": false,
99
"timeout": 10,
1010
"type": "CUSTOM_VALIDATOR_REF"
@@ -71,6 +71,22 @@
7171
],
7272
"type": "enum"
7373
},
74+
"FieldValueExtractionType": {
75+
"description": "",
76+
"displayName": "Field value extraction type",
77+
"documentation": "",
78+
"items": [
79+
{
80+
"displayName": "Constant literal will be assigned to destination field.",
81+
"value": "constant"
82+
},
83+
{
84+
"displayName": "Dynamic value from field or default will be assigned to destination field.",
85+
"value": "field"
86+
}
87+
],
88+
"type": "enum"
89+
},
7490
"IngestSourceType": {
7591
"description": "",
7692
"displayName": "Ingest Source Type",
@@ -835,10 +851,55 @@
835851
"displayName": "FieldExtractionEntry",
836852
"documentation": "",
837853
"properties": {
854+
"constantFieldName": {
855+
"constraints": [
856+
{
857+
"maxLength": 350,
858+
"type": "LENGTH"
859+
},
860+
{
861+
"type": "NOT_BLANK"
862+
}
863+
],
864+
"default": "",
865+
"description": "",
866+
"displayName": "Destination field name",
867+
"documentation": "",
868+
"maxObjects": 1,
869+
"modificationPolicy": "DEFAULT",
870+
"nullable": false,
871+
"precondition": {
872+
"expectedValue": "constant",
873+
"property": "extractionType",
874+
"type": "EQUALS"
875+
},
876+
"type": "text"
877+
},
878+
"constantValue": {
879+
"constraints": [
880+
{
881+
"maxLength": 512,
882+
"type": "LENGTH"
883+
}
884+
],
885+
"default": "",
886+
"description": "",
887+
"displayName": "Constant value to be assigned to field",
888+
"documentation": "",
889+
"maxObjects": 1,
890+
"modificationPolicy": "DEFAULT",
891+
"nullable": false,
892+
"precondition": {
893+
"expectedValue": "constant",
894+
"property": "extractionType",
895+
"type": "EQUALS"
896+
},
897+
"type": "text"
898+
},
838899
"defaultValue": {
839900
"constraints": [
840901
{
841-
"maxLength": 500,
902+
"maxLength": 512,
842903
"minLength": 1,
843904
"type": "LENGTH"
844905
}
@@ -849,14 +910,22 @@
849910
"maxObjects": 1,
850911
"modificationPolicy": "DEFAULT",
851912
"nullable": true,
913+
"precondition": {
914+
"expectedValue": "field",
915+
"property": "extractionType",
916+
"type": "EQUALS"
917+
},
852918
"type": "text"
853919
},
854920
"destinationFieldName": {
855921
"constraints": [
856922
{
857-
"maxLength": 500,
923+
"maxLength": 350,
858924
"minLength": 1,
859925
"type": "LENGTH"
926+
},
927+
{
928+
"type": "NOT_BLANK"
860929
}
861930
],
862931
"description": "",
@@ -865,13 +934,33 @@
865934
"maxObjects": 1,
866935
"modificationPolicy": "DEFAULT",
867936
"nullable": true,
937+
"precondition": {
938+
"expectedValue": "field",
939+
"property": "extractionType",
940+
"type": "EQUALS"
941+
},
868942
"type": "text"
869943
},
944+
"extractionType": {
945+
"default": "field",
946+
"description": "",
947+
"displayName": "Field value extraction type",
948+
"documentation": "",
949+
"maxObjects": 1,
950+
"modificationPolicy": "DEFAULT",
951+
"nullable": false,
952+
"type": {
953+
"$ref": "#/enums/FieldValueExtractionType"
954+
}
955+
},
870956
"sourceFieldName": {
871957
"constraints": [
872958
{
873959
"maxLength": 256,
874960
"type": "LENGTH"
961+
},
962+
{
963+
"type": "NOT_BLANK"
875964
}
876965
],
877966
"default": "",
@@ -881,10 +970,15 @@
881970
"maxObjects": 1,
882971
"modificationPolicy": "DEFAULT",
883972
"nullable": false,
973+
"precondition": {
974+
"expectedValue": "field",
975+
"property": "extractionType",
976+
"type": "EQUALS"
977+
},
884978
"type": "text"
885979
}
886980
},
887-
"summaryPattern": "{sourceFieldName} - {destinationFieldName} - {defaultValue}",
981+
"summaryPattern": "{extractionType} - {sourceFieldName} - {destinationFieldName} - {defaultValue} - {constantFieldName} - {constantValue}",
888982
"type": "object",
889983
"version": "0",
890984
"versionInfo": ""
@@ -3156,5 +3250,5 @@
31563250
"versionInfo": ""
31573251
}
31583252
},
3159-
"version": "1.43"
3253+
"version": "1.51"
31603254
}

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings/services/settings20"
2525
)
2626

27-
const SchemaVersion = "1.43"
27+
const SchemaVersion = "1.51"
2828
const SchemaID = "builtin:openpipeline.usersessions.ingest-sources"
2929

3030
func Service(credentials *rest.Credentials) settings.CRUDService[*service.Settings] {

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/service_unit_test.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,24 @@ func TestOpenPipelineUsersessionsIngestSourcesUnmarshal(t *testing.T) {
3232
entries := new(ingestsources.FieldExtractionEntries)
3333
validEntries := []*ingestsources.FieldExtractionEntry{
3434
{
35-
DefaultValue: testing2.ToPointer("value"),
36-
DestinationFieldName: nil,
37-
SourceFieldName: "",
35+
DefaultValue: testing2.ToPointer("value"),
3836
},
3937
{
40-
DefaultValue: nil,
4138
DestinationFieldName: testing2.ToPointer("value"),
42-
SourceFieldName: "",
4339
},
4440
{
45-
DefaultValue: nil,
46-
DestinationFieldName: nil,
47-
SourceFieldName: "value",
41+
SourceFieldName: testing2.ToPointer("value"),
4842
},
4943
{
5044
DefaultValue: testing2.ToPointer("value1"),
5145
DestinationFieldName: testing2.ToPointer("value2"),
52-
SourceFieldName: "value3",
46+
SourceFieldName: testing2.ToPointer("value3"),
5347
},
54-
}
55-
validWithEmpty := ingestsources.FieldExtractionEntries{
5648
{
57-
DefaultValue: nil,
58-
DestinationFieldName: nil,
59-
SourceFieldName: "",
49+
ExtractionType: "field",
6050
},
6151
}
52+
validWithEmpty := ingestsources.FieldExtractionEntries{{}}
6253
validWithEmpty = append(validWithEmpty, validEntries...)
6354
err := entries.UnmarshalHCL(testing2.MockDecoder{Elements: map[string]any{"dimension": validWithEmpty}})
6455
require.NoError(t, err)

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/settings/enums.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ var FieldExtractionTypes = struct {
5151
"includeAll",
5252
}
5353

54+
type FieldValueExtractionType string
55+
56+
var FieldValueExtractionTypes = struct {
57+
Constant FieldValueExtractionType
58+
Field FieldValueExtractionType
59+
}{
60+
"constant",
61+
"field",
62+
}
63+
5464
type IngestSourceType string
5565

5666
var IngestSourceTypes = struct {

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/settings/field_extraction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
type FieldExtraction struct {
2626
Exclude []string `json:"exclude,omitempty"` // Fields
2727
Include FieldExtractionEntries `json:"include,omitempty"` // Fields
28-
Type FieldExtractionType `json:"type"` // Fields Extraction type. Possible Values: `exclude`, `include`, `includeAll`
28+
Type FieldExtractionType `json:"type"` // Fields Extraction type. Possible values: `exclude`, `include`, `includeAll`
2929
}
3030

3131
func (me *FieldExtraction) Schema() map[string]*schema.Schema {
@@ -46,7 +46,7 @@ func (me *FieldExtraction) Schema() map[string]*schema.Schema {
4646
},
4747
"type": {
4848
Type: schema.TypeString,
49-
Description: "Fields Extraction type. Possible Values: `exclude`, `include`, `includeAll`",
49+
Description: "Fields Extraction type. Possible values: `exclude`, `include`, `includeAll`",
5050
Required: true,
5151
},
5252
}

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/settings/field_extraction_entry.go

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
package ingestsources
1919

2020
import (
21+
"fmt"
22+
23+
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/opt"
2124
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
2225
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2326
)
@@ -47,8 +50,9 @@ func (me *FieldExtractionEntries) UnmarshalHCL(decoder hcl.Decoder) error {
4750
// https://github.com/hashicorp/terraform-plugin-sdk/issues/895
4851
// Only known workaround is to ignore these blocks
4952
newEntries := FieldExtractionEntries{}
53+
var emptyItem FieldExtractionEntry
5054
for _, entry := range *me {
51-
if entry.SourceFieldName != "" || entry.DestinationFieldName != nil || entry.DefaultValue != nil {
55+
if *entry != emptyItem {
5256
newEntries = append(newEntries, entry)
5357
}
5458
}
@@ -57,43 +61,87 @@ func (me *FieldExtractionEntries) UnmarshalHCL(decoder hcl.Decoder) error {
5761
}
5862

5963
type FieldExtractionEntry struct {
60-
DefaultValue *string `json:"defaultValue,omitempty"` // Default value
61-
DestinationFieldName *string `json:"destinationFieldName,omitempty"` // Destination field name
62-
SourceFieldName string `json:"sourceFieldName"` // Source field name
64+
ConstantFieldName *string `json:"constantFieldName,omitempty"` // Destination field name
65+
ConstantValue *string `json:"constantValue,omitempty"` // Constant value to be assigned to field
66+
DefaultValue *string `json:"defaultValue,omitempty"` // Default value
67+
DestinationFieldName *string `json:"destinationFieldName,omitempty"` // Destination field name
68+
ExtractionType FieldValueExtractionType `json:"extractionType"` // Field value extraction type. Possible values: `constant`, `field`
69+
SourceFieldName *string `json:"sourceFieldName,omitempty"` // Source field name
6370
}
6471

6572
func (me *FieldExtractionEntry) Schema() map[string]*schema.Schema {
6673
return map[string]*schema.Schema{
74+
"constant_field_name": {
75+
Type: schema.TypeString,
76+
Description: "Destination field name",
77+
Optional: true, // precondition
78+
},
79+
"constant_value": {
80+
Type: schema.TypeString,
81+
Description: "Constant value to be assigned to field",
82+
Optional: true, // precondition
83+
},
6784
"default_value": {
6885
Type: schema.TypeString,
6986
Description: "Default value",
70-
Optional: true, // nullable
87+
Optional: true, // nullable & precondition
7188
},
7289
"destination_field_name": {
7390
Type: schema.TypeString,
7491
Description: "Destination field name",
75-
Optional: true, // nullable
92+
Optional: true, // nullable & precondition
93+
},
94+
"extraction_type": {
95+
Type: schema.TypeString,
96+
Description: "Field value extraction type. Possible values: `constant`, `field`",
97+
Optional: true,
98+
Default: "field", // new required attribute. Fallback to "field"
7699
},
77100
"source_field_name": {
78101
Type: schema.TypeString,
79102
Description: "Source field name",
80-
Required: true,
103+
Optional: true, // precondition
81104
},
82105
}
83106
}
84107

85108
func (me *FieldExtractionEntry) MarshalHCL(properties hcl.Properties) error {
86109
return properties.EncodeAll(map[string]any{
110+
"constant_field_name": me.ConstantFieldName,
111+
"constant_value": me.ConstantValue,
87112
"default_value": me.DefaultValue,
88113
"destination_field_name": me.DestinationFieldName,
114+
"extraction_type": me.ExtractionType,
89115
"source_field_name": me.SourceFieldName,
90116
})
91117
}
92118

119+
func (me *FieldExtractionEntry) HandlePreconditions() error {
120+
if (me.ConstantFieldName == nil) && (string(me.ExtractionType) == "constant") {
121+
me.ConstantFieldName = opt.NewString("")
122+
}
123+
if (me.ConstantValue == nil) && (string(me.ExtractionType) == "constant") {
124+
me.ConstantValue = opt.NewString("")
125+
}
126+
if (me.SourceFieldName == nil) && (string(me.ExtractionType) == "field") {
127+
me.SourceFieldName = opt.NewString("")
128+
}
129+
if (me.DefaultValue != nil) && (string(me.ExtractionType) != "field") {
130+
return fmt.Errorf("'default_value' must not be specified if 'extraction_type' is set to '%v'", me.ExtractionType)
131+
}
132+
if (me.DestinationFieldName != nil) && (string(me.ExtractionType) != "field") {
133+
return fmt.Errorf("'destination_field_name' must not be specified if 'extraction_type' is set to '%v'", me.ExtractionType)
134+
}
135+
return nil
136+
}
137+
93138
func (me *FieldExtractionEntry) UnmarshalHCL(decoder hcl.Decoder) error {
94139
return decoder.DecodeAll(map[string]any{
140+
"constant_field_name": &me.ConstantFieldName,
141+
"constant_value": &me.ConstantValue,
95142
"default_value": &me.DefaultValue,
96143
"destination_field_name": &me.DestinationFieldName,
144+
"extraction_type": &me.ExtractionType,
97145
"source_field_name": &me.SourceFieldName,
98146
})
99147
}

dynatrace/api/builtin/openpipeline/usersessions/ingestsources/settings/generic_value_assignment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type GenericValueAssignment struct {
2929
Constant *string `json:"constant,omitempty"` // Constant value
3030
Field *ValueAssignmentFromFieldEntry `json:"field,omitempty"` // Value from field
3131
MultiValueConstant []string `json:"multiValueConstant,omitempty"` // Constant multi value
32-
Type AssignmentType `json:"type"` // Type of value assignment. Possible Values: `constant`, `field`, `multiValueConstant`
32+
Type AssignmentType `json:"type"` // Type of value assignment. Possible values: `constant`, `field`, `multiValueConstant`
3333
}
3434

3535
func (me *GenericValueAssignment) Schema() map[string]*schema.Schema {
@@ -55,7 +55,7 @@ func (me *GenericValueAssignment) Schema() map[string]*schema.Schema {
5555
},
5656
"type": {
5757
Type: schema.TypeString,
58-
Description: "Type of value assignment. Possible Values: `constant`, `field`, `multiValueConstant`",
58+
Description: "Type of value assignment. Possible values: `constant`, `field`, `multiValueConstant`",
5959
Required: true,
6060
},
6161
}

0 commit comments

Comments
 (0)