Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F-583: Add validate argument to raw parameters #584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.4.2 (Unreleased)

FEATURES:

* resources/opennebula_template: add validate argument to the raw parameters (#583)
* resources/opennebula_virtual_machine: add validate argument to the raw parameters (#583)

# 1.4.1 (October 22nd, 2024)

FEATURES:
Expand Down
23 changes: 21 additions & 2 deletions opennebula/shared_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ func commonInstanceSchema() map[string]*schema.Schema {
},
Description: "Name of the hypervisor: kvm, lxd, vmware",
},
"validate": {
Type: schema.TypeString,
Required: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
validtypes := []string{"yes", "no"}
value := v.(string)

if !contains(value, validtypes) {
errors = append(errors, fmt.Errorf("Validate %q must be one of: %s", k, strings.Join(validtypes, ",")))
}

return
},
Description: "Validate DATA against XML schema",
},
"data": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -772,6 +787,7 @@ func generateVMTemplate(d *schema.ResourceData, tpl *vm.Template) error {
rawConfig := raw[i].(map[string]interface{})
rawVec := tpl.AddVector("RAW")
rawVec.AddPair("TYPE", rawConfig["type"].(string))
rawVec.AddPair("VALIDATE", rawConfig["validate"].(string))
rawVec.AddPair("DATA", rawConfig["data"].(string))
}
}
Expand Down Expand Up @@ -840,6 +856,7 @@ func updateRaw(d *schema.ResourceData, tpl *dyn.Template) {
rawConfig := raw[i].(map[string]interface{})
rawVec := tpl.AddVector("RAW")
rawVec.AddPair("TYPE", rawConfig["type"].(string))
rawVec.AddPair("VALIDATE", rawConfig["validate"].(string))
rawVec.AddPair("DATA", rawConfig["data"].(string))
}
}
Expand Down Expand Up @@ -1053,11 +1070,13 @@ func flattenTemplate(d *schema.ResourceData, inheritedVectors map[string]interfa
rawMap := make([]map[string]interface{}, 0, 1)

hypType, _ := rawVec.GetStr("TYPE")
validate, _ := rawVec.GetStr("VALIDATE")
data, _ := rawVec.GetStr("DATA")

rawMap = append(rawMap, map[string]interface{}{
"type": hypType,
"data": data,
"type": hypType,
"validate": validate,
"data": data,
})

if _, ok := d.GetOk("raw"); ok {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Minimum 1 item. Maximum 8 items.
`raw` supports the following arguments:

* `type` - (Required) - Hypervisor. Supported values: `kvm`, `lxd`, `vmware`.
* `validate` - (Optional) - Validate `data` against XML schema, possible values `yes`, `no`. Default value is `yes`.
* `data` - (Required) - Raw data to pass to the hypervisor.

### VM group parameters
Expand Down Expand Up @@ -215,7 +216,7 @@ The following attribute are exported:
* `tags_all` - Result of the applied `default_tags` and then resource `tags`.
* `default_tags` - Default tags defined in the provider configuration.

## Import
## Import

`opennebula_template` can be imported using its ID:

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ A NIC update will be triggered in adding or removing a `nic` section, or by a mo
`raw` supports the following arguments:

* `type` - (Required) - Hypervisor. Supported values: `kvm`, `lxd`, `vmware`.
* `validate` - (Optional) - Validate `data` against XML schema, possible values `yes`, `no`. Default value is `yes`.
* `data` - (Required) - Raw data to pass to the hypervisor.

### Template section parameters
Expand Down