diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db225434..9bc9bd61d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/opennebula/shared_schemas.go b/opennebula/shared_schemas.go index 24bb0eb75..a4dafef14 100644 --- a/opennebula/shared_schemas.go +++ b/opennebula/shared_schemas.go @@ -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, @@ -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)) } } @@ -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)) } } @@ -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 { diff --git a/website/docs/r/template.html.markdown b/website/docs/r/template.html.markdown index 3500ced7c..87cc7c108 100644 --- a/website/docs/r/template.html.markdown +++ b/website/docs/r/template.html.markdown @@ -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 @@ -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: diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index 0b78586ca..16517f6da 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -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