Skip to content

Commit db4eee1

Browse files
authored
Add Source schema settings to Source resource (#71)
1 parent 8fad9d6 commit db4eee1

File tree

17 files changed

+1022
-63
lines changed

17 files changed

+1022
-63
lines changed

docs/data-sources/source.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ data "segment_source" "my_source" {
3535
- `enabled` (Boolean) Enable to receive data from the Source.
3636
- `labels` (Attributes List) A list of labels applied to the Source. (see [below for nested schema](#nestedatt--labels))
3737
- `metadata` (Attributes) The metadata for the Source. (see [below for nested schema](#nestedatt--metadata))
38+
- `schema_settings` (Attributes) The schema settings associated with the Source. (see [below for nested schema](#nestedatt--schema_settings))
3839
- `settings` (String) The settings associated with the Source.
3940
- `slug` (String) The slug used to identify the Source in the Segment app.
4041
- `workspace_id` (String) The id of the Workspace that owns the Source.
@@ -45,7 +46,6 @@ data "segment_source" "my_source" {
4546

4647
Read-Only:
4748

48-
- `description` (String) An optional description of the purpose of this label.
4949
- `key` (String) The key that represents the name of this label.
5050
- `value` (String) The value associated with the key of this label.
5151

@@ -85,3 +85,47 @@ Read-Only:
8585
- `name` (String) The name identifying this option in the context of a Segment Integration.
8686
- `required` (Boolean) Whether this is a required option when setting up the Integration.
8787
- `type` (String) Defines the type for this option in the schema. Types are most commonly strings, but may also represent other primitive types, such as booleans, and numbers, as well as complex types, such as objects and arrays.
88+
89+
90+
91+
<a id="nestedatt--schema_settings"></a>
92+
### Nested Schema for `schema_settings`
93+
94+
Read-Only:
95+
96+
- `forwarding_blocked_events_to` (String) Source id to forward blocked events to.
97+
- `forwarding_violations_to` (String) Source id to forward violations to.
98+
- `group` (Attributes) Group settings. (see [below for nested schema](#nestedatt--schema_settings--group))
99+
- `identify` (Attributes) Identify settings. (see [below for nested schema](#nestedatt--schema_settings--identify))
100+
- `track` (Attributes) Track settings. (see [below for nested schema](#nestedatt--schema_settings--track))
101+
102+
<a id="nestedatt--schema_settings--group"></a>
103+
### Nested Schema for `schema_settings.group`
104+
105+
Read-Only:
106+
107+
- `allow_traits_on_violations` (Boolean) Enable to allow group traits on violations.
108+
- `allow_unplanned_traits` (Boolean) Enable to allow unplanned group traits.
109+
- `common_event_on_violations` (String) The common group event on violations.
110+
111+
112+
<a id="nestedatt--schema_settings--identify"></a>
113+
### Nested Schema for `schema_settings.identify`
114+
115+
Read-Only:
116+
117+
- `allow_traits_on_violations` (Boolean) Enable to allow identify traits on violations.
118+
- `allow_unplanned_traits` (Boolean) Enable to allow unplanned identify traits.
119+
- `common_event_on_violations` (String) The common identify event on violations.
120+
121+
122+
<a id="nestedatt--schema_settings--track"></a>
123+
### Nested Schema for `schema_settings.track`
124+
125+
Read-Only:
126+
127+
- `allow_event_on_violations` (Boolean) Allow track event on violations.
128+
- `allow_properties_on_violations` (Boolean) Enable to allow track properties on violations.
129+
- `allow_unplanned_event_properties` (Boolean) Enable to allow unplanned track event properties.
130+
- `allow_unplanned_events` (Boolean) Enable to allow unplanned track events.
131+
- `common_event_on_violations` (String) The common track event on violations.

docs/data-sources/user.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ Read-Only:
5454

5555
Read-Only:
5656

57-
- `description` (String) An optional description of the purpose of this label.
5857
- `key` (String) The key that represents the name of this label.
5958
- `value` (String) The value associated with the key of this label.

docs/resources/source.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,44 @@ resource "segment_source" "my_source" {
3131
},
3232
]
3333
}
34+
35+
resource "segment_source" "my_source_with_schema_settings" {
36+
slug = "my_source_slug"
37+
name = "My Source"
38+
enabled = true
39+
metadata = {
40+
id = "abc123"
41+
}
42+
settings = jsonencode({
43+
"token" : "xyz321",
44+
})
45+
labels = [
46+
{
47+
key = "env"
48+
value = "dev"
49+
},
50+
]
51+
schema_settings = {
52+
forwarding_blocked_events_to = segment_source.my_source.id
53+
track = {
54+
allow_unplanned_events = true
55+
allow_unplanned_event_properties = true
56+
allow_event_on_violations = false
57+
allow_properties_on_violations = true
58+
common_event_on_violations = "ALLOW"
59+
}
60+
identify = {
61+
allow_traits_on_violations = false
62+
allow_unplanned_traits = false
63+
common_event_on_violations = "ALLOW"
64+
}
65+
group = {
66+
allow_traits_on_violations = true
67+
allow_unplanned_traits = true
68+
common_event_on_violations = "ALLOW"
69+
}
70+
}
71+
}
3472
```
3573

3674
<!-- schema generated by tfplugindocs -->
@@ -47,6 +85,7 @@ resource "segment_source" "my_source" {
4785

4886
- `labels` (Attributes Set) A list of labels applied to the Source. (see [below for nested schema](#nestedatt--labels))
4987
- `name` (String) The name of the Source.
88+
- `schema_settings` (Attributes) The schema settings associated with the Source. Upon import, this field will be empty even if the settings have already been configured due to Terraform limitations, but will be populated on the first apply. Fields not present in the config will not be managed by Terraform. (see [below for nested schema](#nestedatt--schema_settings))
5089

5190
### Read-Only
5291

@@ -103,6 +142,45 @@ Required:
103142
- `key` (String) The key that represents the name of this label.
104143
- `value` (String) The value associated with the key of this label.
105144

106-
Read-Only:
107145

108-
- `description` (String) An optional description of the purpose of this label.
146+
<a id="nestedatt--schema_settings"></a>
147+
### Nested Schema for `schema_settings`
148+
149+
Optional:
150+
151+
- `forwarding_blocked_events_to` (String) Source id to forward blocked events to.
152+
- `forwarding_violations_to` (String) Source id to forward violations to.
153+
- `group` (Attributes) Group settings. (see [below for nested schema](#nestedatt--schema_settings--group))
154+
- `identify` (Attributes) Identify settings. (see [below for nested schema](#nestedatt--schema_settings--identify))
155+
- `track` (Attributes) Track settings. (see [below for nested schema](#nestedatt--schema_settings--track))
156+
157+
<a id="nestedatt--schema_settings--group"></a>
158+
### Nested Schema for `schema_settings.group`
159+
160+
Optional:
161+
162+
- `allow_traits_on_violations` (Boolean) Enable to allow group traits on violations.
163+
- `allow_unplanned_traits` (Boolean) Enable to allow unplanned group traits.
164+
- `common_event_on_violations` (String) The common group event on violations.
165+
166+
167+
<a id="nestedatt--schema_settings--identify"></a>
168+
### Nested Schema for `schema_settings.identify`
169+
170+
Optional:
171+
172+
- `allow_traits_on_violations` (Boolean) Enable to allow identify traits on violations.
173+
- `allow_unplanned_traits` (Boolean) Enable to allow unplanned identify traits.
174+
- `common_event_on_violations` (String) The common identify event on violations.
175+
176+
177+
<a id="nestedatt--schema_settings--track"></a>
178+
### Nested Schema for `schema_settings.track`
179+
180+
Optional:
181+
182+
- `allow_event_on_violations` (Boolean) Allow track event on violations.
183+
- `allow_properties_on_violations` (Boolean) Enable to allow track properties on violations.
184+
- `allow_unplanned_event_properties` (Boolean) Enable to allow unplanned track event properties.
185+
- `allow_unplanned_events` (Boolean) Enable to allow unplanned track events.
186+
- `common_event_on_violations` (String) The common track event on violations.

docs/resources/user.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,3 @@ Required:
7777

7878
- `key` (String) The key that represents the name of this label.
7979
- `value` (String) The value associated with the key of this label.
80-
81-
Read-Only:
82-
83-
- `description` (String) An optional description of the purpose of this label.

docs/resources/user_group.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,3 @@ Required:
8484

8585
- `key` (String) The key that represents the name of this label.
8686
- `value` (String) The value associated with the key of this label.
87-
88-
Read-Only:
89-
90-
- `description` (String) An optional description of the purpose of this label.

examples/resources/segment_source/resource.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,41 @@ resource "segment_source" "my_source" {
1616
},
1717
]
1818
}
19+
20+
resource "segment_source" "my_source_with_schema_settings" {
21+
slug = "my_source_slug"
22+
name = "My Source"
23+
enabled = true
24+
metadata = {
25+
id = "abc123"
26+
}
27+
settings = jsonencode({
28+
"token" : "xyz321",
29+
})
30+
labels = [
31+
{
32+
key = "env"
33+
value = "dev"
34+
},
35+
]
36+
schema_settings = {
37+
forwarding_blocked_events_to = segment_source.my_source.id
38+
track = {
39+
allow_unplanned_events = true
40+
allow_unplanned_event_properties = true
41+
allow_event_on_violations = false
42+
allow_properties_on_violations = true
43+
common_event_on_violations = "ALLOW"
44+
}
45+
identify = {
46+
allow_traits_on_violations = false
47+
allow_unplanned_traits = false
48+
common_event_on_violations = "ALLOW"
49+
}
50+
group = {
51+
allow_traits_on_violations = true
52+
allow_unplanned_traits = true
53+
common_event_on_violations = "ALLOW"
54+
}
55+
}
56+
}

internal/provider/function_resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ func (r *functionResource) Read(ctx context.Context, req resource.ReadRequest, r
198198
function := response.Data.GetFunction()
199199
state.Fill(function)
200200

201+
// Destination functions append workspace name to display name causing inconsistency
202+
if state.ResourceType.ValueString() == "DESTINATION" || state.ResourceType.ValueString() == "INSERT_DESTINATION" {
203+
state.DisplayName = previousState.DisplayName
204+
}
205+
201206
diags = resp.State.Set(ctx, &state)
202207
resp.Diagnostics.Append(diags...)
203208
if resp.Diagnostics.HasError() {
@@ -249,6 +254,11 @@ func (r *functionResource) Update(ctx context.Context, req resource.UpdateReques
249254

250255
state.Fill(api.Function(function))
251256

257+
// Destination functions append workspace name to display name causing inconsistency
258+
if state.ResourceType.ValueString() == "DESTINATION" || state.ResourceType.ValueString() == "INSERT_DESTINATION" {
259+
state.DisplayName = plan.DisplayName
260+
}
261+
252262
diags = resp.State.Set(ctx, &state)
253263
resp.Diagnostics.Append(diags...)
254264
if resp.Diagnostics.HasError() {

internal/provider/label_resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (r *labelResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
8484

8585
func (r *labelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
8686
// Retrieve values from plan
87-
var plan models.LabelState
87+
var plan models.LabelResourceState
8888
diags := req.Plan.Get(ctx, &plan)
8989
resp.Diagnostics.Append(diags...)
9090
if resp.Diagnostics.HasError() {
@@ -115,7 +115,7 @@ func (r *labelResource) Create(ctx context.Context, req resource.CreateRequest,
115115
}
116116

117117
outLabel := out.Data.Label
118-
var state models.LabelState
118+
var state models.LabelResourceState
119119
state.Fill(api.LabelV1(outLabel))
120120

121121
// Set state to fully populated data
@@ -127,7 +127,7 @@ func (r *labelResource) Create(ctx context.Context, req resource.CreateRequest,
127127
}
128128

129129
func (r *labelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
130-
var state models.LabelState
130+
var state models.LabelResourceState
131131
diags := req.State.Get(ctx, &state)
132132
resp.Diagnostics.Append(diags...)
133133
if resp.Diagnostics.HasError() {
@@ -189,7 +189,7 @@ func (r *labelResource) Update(context.Context, resource.UpdateRequest, *resourc
189189

190190
func (r *labelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
191191
// Retrieve values from state
192-
var state models.LabelState
192+
var state models.LabelResourceState
193193
diags := req.State.Get(ctx, &state)
194194
resp.Diagnostics.Append(diags...)
195195
if resp.Diagnostics.HasError() {

internal/provider/models/destination_metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (d *DestinationMetadataState) getLogosDestinationMetadata(logos api.Logos)
312312
}
313313

314314
func getOptions(options []api.IntegrationOptionBeta) ([]IntegrationOptionState, error) {
315-
var integrationOptions []IntegrationOptionState
315+
integrationOptions := []IntegrationOptionState{}
316316

317317
for _, opt := range options {
318318
integrationOption := IntegrationOptionState{

internal/provider/models/label.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
)
1010

1111
type LabelState struct {
12+
Key types.String `tfsdk:"key"`
13+
Value types.String `tfsdk:"value"`
14+
}
15+
16+
type LabelResourceState struct {
1217
Key types.String `tfsdk:"key"`
1318
Value types.String `tfsdk:"value"`
1419
Description types.String `tfsdk:"description"`
@@ -24,6 +29,18 @@ func (l *LabelState) ToAPIValue() api.AllowedLabelBeta {
2429
func (l *LabelState) Fill(label api.LabelV1) {
2530
l.Key = types.StringValue(label.Key)
2631
l.Value = types.StringValue(label.Value)
32+
}
33+
34+
func (l *LabelResourceState) ToAPIValue() api.AllowedLabelBeta {
35+
return api.AllowedLabelBeta{
36+
Key: l.Key.ValueString(),
37+
Value: l.Value.ValueString(),
38+
}
39+
}
40+
41+
func (l *LabelResourceState) Fill(label api.LabelV1) {
42+
l.Key = types.StringValue(label.Key)
43+
l.Value = types.StringValue(label.Value)
2744
l.Description = types.StringPointerValue(label.Description)
2845
}
2946

0 commit comments

Comments
 (0)