Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Reintroduce the schema escaping for the pg user config - but not incl…
Browse files Browse the repository at this point in the history
…ude double underscore
  • Loading branch information
stack72 committed Mar 31, 2020
1 parent 64146bc commit 296d9e0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions aiven/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func GenerateTerraformUserConfigSchema(data map[string]interface{}) map[string]*
definition["api_type"] = "boolean"
}

terraformSchema[name] = generateTerraformUserConfigSchema(name, definition)
terraformSchema[encodeKeyName(name)] = generateTerraformUserConfigSchema(name, definition)
}

return terraformSchema
Expand Down Expand Up @@ -258,6 +258,7 @@ func convertAPIUserConfigToTerraformCompatibleFormat(
}

apiValue, ok := apiUserConfig[key]
key = encodeKeyName(key)
if !ok || apiValue == nil {
// To avoid undesired "changes" for values that are not explicitly defined return
// default values for anything that is not returned in the API response
Expand Down Expand Up @@ -347,6 +348,7 @@ func convertTerraformUserConfigToAPICompatibleFormat(
apiConfig := make(map[string]interface{})
for key, value := range userConfig {
definitionRaw, ok := configSchema[key]
key = decodeKeyName(key)
if !ok {
panic(fmt.Sprintf("Unsupported %v user config key %v", serviceType, key))
}
Expand Down Expand Up @@ -500,11 +502,11 @@ func convertTerraformUserConfigValueToAPICompatibleFormat(
return convertedValue, omit
}

//func encodeKeyName(key string) string {
// // Terraform does not accept dots in key names but Aiven API has those at least in PG user config
// return strings.Replace(key, ".", "__dot__", -1)
//}
//
//func decodeKeyName(key string) string {
// return strings.Replace(key, "__dot__", ".", -1)
//}
func encodeKeyName(key string) string {
// Terraform does not accept dots in key names but Aiven API has those at least in PG user config
return strings.Replace(key, ".", "_dot_", -1)
}

func decodeKeyName(key string) string {
return strings.Replace(key, "_dot_", ".", -1)
}

0 comments on commit 296d9e0

Please sign in to comment.