Skip to content
Closed
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
17 changes: 8 additions & 9 deletions pkg/channels/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type Channel struct {
CustomFieldDefinitions []ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"`
CustomFieldDefinitions *[]ChannelCustomFieldDefinition `json:"CustomFieldDefinitions,omitempty"`
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* means that the field is a pointer to a slice. Instead of holding the slice directly, it holds a reference to a slice (or nothing at all if nil). When we use a pointer instead of the slice itself, omitempty treats an empty slice differently to an omitted field.

This will enable us to:

  • clear the custom field definitions by setting the pointer to an empty slice.
  • leave the custom field definitions unchanged by omitting the pointer entirely.

Description string `json:"Description,omitempty"`
EphemeralEnvironmentNameTemplate string `json:"EphemeralEnvironmentNameTemplate,omitempty"`
IsDefault bool `json:"IsDefault"`
Expand All @@ -31,14 +31,13 @@ type Channel struct {

func NewChannel(name string, projectID string) *Channel {
return &Channel{
Name: strings.TrimSpace(name),
ProjectID: projectID,
Rules: []ChannelRule{},
TenantTags: []string{},
GitReferenceRules: []string{},
GitResourceRules: []ChannelGitResourceRule{},
CustomFieldDefinitions: []ChannelCustomFieldDefinition{},
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are using a pointer above, if we left this line in we would be creating a custom field definition property on every new channel. The terraform provider will now create the new channel and then add the custom field definitions.

Resource: *resources.NewResource(),
Name: strings.TrimSpace(name),
ProjectID: projectID,
Rules: []ChannelRule{},
TenantTags: []string{},
GitReferenceRules: []string{},
GitResourceRules: []ChannelGitResourceRule{},
Resource: *resources.NewResource(),
}
}

Expand Down
Loading