Skip to content

Commit

Permalink
Fix openstack_db_configuration_v1 type mismatch for bool and string t…
Browse files Browse the repository at this point in the history
…ypes.

Add parameter's value conversion to bool type and new parameter that allows store parameter's value as string.
  • Loading branch information
pawcykca authored and nikParasyr committed Oct 2, 2022
1 parent 9077d55 commit 0518050
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
14 changes: 10 additions & 4 deletions openstack/db_configuration_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ func expandDatabaseConfigurationV1Values(rawValues []interface{}) map[string]int
v := rawValue.(map[string]interface{})
name := v["name"].(string)
value := v["value"]

// check if value can be converted into int
if valueInt, err := strconv.Atoi(value.(string)); err == nil {
value = valueInt
isStringType := v["string_type"].(bool)

if !isStringType {
// check if value can be converted into int
if valueInt, err := strconv.Atoi(value.(string)); err == nil {
value = valueInt
// check if value can be converted into bool
} else if valueBool, err := strconv.ParseBool(value.(string)); err == nil {
value = valueBool
}
}

values[name] = value
Expand Down
5 changes: 5 additions & 0 deletions openstack/resource_openstack_db_configuration_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func resourceDatabaseConfigurationV1() *schema.Resource {
Required: true,
ForceNew: true,
},
"string_type": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
},
},
Expand Down
12 changes: 11 additions & 1 deletion website/docs/r/db_configuration_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The `configuration` block supports:

* `name` - (Optional) Configuration parameter name. Changing this creates a new resource.
* `value` - (Optional) Configuration parameter value. Changing this creates a new resource.
* `string_type` - (Optional) Whether or not to store configuration parameter value as string. Changing this creates a new resource. See the below note for more information.


## Attributes Reference
Expand All @@ -68,4 +69,13 @@ The following attributes are exported:
* `datastore/type` - See Argument Reference above.
* `datastore/version` - See Argument Reference above.
* `configuration/name` - See Argument Reference above.
* `configuration/value` - See Argument Reference above.
* `configuration/value` - See Argument Reference above.
* `configuration/string_type` - See Argument Reference above.

## Types of configuration parameter values

Openstack API requires to store some database configuration parameter's values as strings, even if they contain numbers.
To force store their values as strings set `string_type` to `true`. Otherwise Terraform will try to store them as number what can cause error from Openstack API like below:
```
"The value provided for the configuration parameter log_min_duration_statement is not of type string."
```

0 comments on commit 0518050

Please sign in to comment.