Skip to content

Commit 7c67172

Browse files
committed
Remove deprecated fields from plugin config to avoid false drift
1 parent 72a0ea3 commit 7c67172

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

konnect/client/plugin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ type PluginSchema struct {
2828
Fields []map[string]PluginField `json:"fields"`
2929
}
3030
type PluginField struct {
31-
Type string `json:"type"`
32-
Default interface{} `json:"default"`
33-
Fields []map[string]PluginField `json:"fields"`
31+
Type string `json:"type"`
32+
Default interface{} `json:"default"`
33+
Fields []map[string]PluginField `json:"fields"`
34+
ShorthandFields []map[string]PluginField `json:"shorthand_fields"`
3435
}
3536

3637
func (s *Plugin) PluginEncodeId() string {

konnect/resource_plugin.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ func fillPlugin(c *client.Plugin, d *schema.ResourceData) {
128128

129129
func fillResourceDataFromPlugin(ctx context.Context, c *client.Plugin, d *schema.ResourceData, pluginSchema *client.PluginSchema) {
130130
// Grab just the schema for config parameter from plugin schema
131-
var configSchema []map[string]client.PluginField
132-
configSchema = nil
131+
var fieldSchema []map[string]client.PluginField
132+
fieldSchema = nil
133+
var shorthandFieldSchema []map[string]client.PluginField
134+
shorthandFieldSchema = nil
133135
for _, value := range pluginSchema.Fields {
134136
valueMap, ok := value["config"]
135137
if ok {
136-
configSchema = valueMap.Fields
138+
fieldSchema = valueMap.Fields
139+
shorthandFieldSchema = valueMap.ShorthandFields
137140
break
138141
}
139142
}
@@ -159,29 +162,33 @@ func fillResourceDataFromPlugin(ctx context.Context, c *client.Plugin, d *schema
159162
d.Set("consumer_id", consumerId)
160163
d.Set("plugin_id", c.Id)
161164
// Remove all default values from config based on plugin schema
162-
if configSchema != nil {
163-
pruneConfigValues(ctx, c.Config, configSchema)
165+
if fieldSchema != nil {
166+
pruneConfigValues(ctx, c.Config, fieldSchema, false)
167+
}
168+
if shorthandFieldSchema != nil {
169+
pruneConfigValues(ctx, c.Config, shorthandFieldSchema, true)
164170
}
165171
bytes, _ := json.Marshal(c.Config)
166172
d.Set("config_json", string(bytes[:]))
167173
bytes, _ = json.Marshal(c.ConfigAll)
168174
d.Set("config_all_json", string(bytes[:]))
169175
}
170176

171-
func pruneConfigValues(ctx context.Context, config map[string]interface{}, configSchema []map[string]client.PluginField) {
177+
func pruneConfigValues(ctx context.Context, config map[string]interface{}, configSchema []map[string]client.PluginField, isShorthand bool) {
172178
for _, fieldConfig := range configSchema {
173179
for fieldKey, field := range fieldConfig {
174180
configValue, ok := config[fieldKey]
175181
if ok {
176182
// If field type is record, then recurse
177183
if field.Type == "record" {
178184
childConfigValue := configValue.(map[string]interface{})
179-
pruneConfigValues(ctx, childConfigValue, field.Fields)
185+
pruneConfigValues(ctx, childConfigValue, field.Fields, false)
186+
pruneConfigValues(ctx, childConfigValue, field.ShorthandFields, true)
180187
// If all fields of child config are defaults, then remove entire child config from parent
181188
if len(childConfigValue) == 0 {
182189
delete(config, fieldKey)
183190
}
184-
} else if areConfigValuesEqual(ctx, fieldKey, configValue, field.Default) {
191+
} else if areConfigValuesEqual(ctx, fieldKey, configValue, field.Default) || isShorthand {
185192
delete(config, fieldKey)
186193
}
187194
}

test/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ provider "konnect" {
9292
# role_display_name = data.konnect_role.R.display_name
9393
#}
9494

95-
data "konnect_team" "T" {
96-
name = "api-product-developer"
97-
}
95+
# data "konnect_team" "T" {
96+
# name = "api-product-developer"
97+
# }
9898

9999
#resource "konnect_user" "U" {
100100
# email = "[email protected]"

0 commit comments

Comments
 (0)