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

Allow vApp userConfigurable=false properties to be configured #1199

Merged
merged 1 commit into from
May 7, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ func VirtualMachineOvfDeploySchema() map[string]*schema.Schema {
Default: true,
Description: "Allow unverified ssl certificates while deploying ovf/ova from url.",
},
"enable_hidden_properties": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Allow properties with ovf:userConfigurable=false to be set.",
ForceNew: true,
},
}
}
38 changes: 33 additions & 5 deletions vsphere/virtual_machine_config_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,15 @@ func expandVAppConfig(d *schema.ResourceData, client *govmomi.Client) (*types.Vm
}
allProperties := vmProps.Config.VAppConfig.GetVmConfigInfo().Property

enableHiddenProperties := d.Get("ovf_deploy.0.enable_hidden_properties").(bool)

for _, p := range allProperties {
if *p.UserConfigurable == true {
if enableHiddenProperties {
defaultValue := " "
if p.DefaultValue != "" {
defaultValue = p.DefaultValue
}
userConfigurable := true
prop := types.VAppPropertySpec{
ArrayUpdateSpec: types.ArrayUpdateSpec{
Operation: types.ArrayUpdateOperationEdit,
Expand All @@ -687,7 +690,7 @@ func expandVAppConfig(d *schema.ResourceData, client *govmomi.Client) (*types.Vm
Key: p.Key,
Id: p.Id,
Value: defaultValue,
UserConfigurable: p.UserConfigurable,
UserConfigurable: &userConfigurable,
},
}

Expand All @@ -698,9 +701,34 @@ func expandVAppConfig(d *schema.ResourceData, client *govmomi.Client) (*types.Vm
}
props = append(props, prop)
} else {
_, ok := newMap[p.Id]
if ok {
return nil, fmt.Errorf("vApp property with userConfigurable=false specified in vapp.properties: %+v", reflect.ValueOf(newMap).MapKeys())
if *p.UserConfigurable == true {
defaultValue := " "
if p.DefaultValue != "" {
defaultValue = p.DefaultValue
}
prop := types.VAppPropertySpec{
ArrayUpdateSpec: types.ArrayUpdateSpec{
Operation: types.ArrayUpdateOperationEdit,
},
Info: &types.VAppPropertyInfo{
Key: p.Key,
Id: p.Id,
Value: defaultValue,
UserConfigurable: p.UserConfigurable,
},
}

newValue, ok := newMap[p.Id]
if ok {
prop.Info.Value = newValue.(string)
delete(newMap, p.Id)
}
props = append(props, prop)
} else {
_, ok := newMap[p.Id]
if ok {
return nil, fmt.Errorf("vApp property with userConfigurable=false specified in vapp.properties: %+v", reflect.ValueOf(newMap).MapKeys())
}
}
}
}
Expand Down