diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index d40eac0..12bcdc4 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -55,6 +55,7 @@ const ( dvResourceVirtualEnvironmentVMInitializationIPConfigIPv6Gateway = "" dvResourceVirtualEnvironmentVMInitializationUserAccountPassword = "" dvResourceVirtualEnvironmentVMInitializationUserDataFileID = "" + dvResourceVirtualEnvironmentVMInitializationType = "" dvResourceVirtualEnvironmentVMKeyboardLayout = "en-us" dvResourceVirtualEnvironmentVMMemoryDedicated = 512 dvResourceVirtualEnvironmentVMMemoryFloating = 0 @@ -131,6 +132,7 @@ const ( mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6 = "ipv6" mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6Address = "address" mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6Gateway = "gateway" + mkResourceVirtualEnvironmentVMInitializationType = "type" mkResourceVirtualEnvironmentVMInitializationUserAccount = "user_account" mkResourceVirtualEnvironmentVMInitializationUserAccountKeys = "keys" mkResourceVirtualEnvironmentVMInitializationUserAccountPassword = "password" @@ -674,6 +676,14 @@ func resourceVirtualEnvironmentVM() *schema.Resource { Default: dvResourceVirtualEnvironmentVMInitializationUserDataFileID, ValidateFunc: getFileIDValidator(), }, + mkResourceVirtualEnvironmentVMInitializationType: { + Type: schema.TypeString, + Description: "The cloud-init configuration format", + Optional: true, + ForceNew: true, + Default: dvResourceVirtualEnvironmentVMInitializationType, + ValidateFunc: getCloudInitTypeValidator(), + }, }, }, MaxItems: 1, @@ -1854,6 +1864,12 @@ func resourceVirtualEnvironmentVMGetCloudInitConfig(d *schema.ResourceData, m in UserVolume: &initializationUserDataFileID, } } + + initializationType := initializationBlock[mkResourceVirtualEnvironmentVMInitializationType].(string) + + if initializationType != "" { + initializationConfig.Type = &initializationType + } } return initializationConfig, nil @@ -2555,6 +2571,12 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{ initialization[mkResourceVirtualEnvironmentVMInitializationUserDataFileID] = "" } + if vmConfig.CloudInitType != nil { + initialization[mkResourceVirtualEnvironmentVMInitializationType] = *vmConfig.CloudInitType + } else if len(initialization) > 0 { + initialization[mkResourceVirtualEnvironmentVMInitializationType] = "" + } + currentInitialization := d.Get(mkResourceVirtualEnvironmentVMInitialization).([]interface{}) if len(clone) > 0 { diff --git a/proxmoxtf/utils.go b/proxmoxtf/utils.go index c755b9b..e4a847c 100644 --- a/proxmoxtf/utils.go +++ b/proxmoxtf/utils.go @@ -370,6 +370,13 @@ func getVMIDValidator() schema.SchemaValidateFunc { } } +func getCloudInitTypeValidator() schema.SchemaValidateFunc { + return validation.StringInSlice([]string{ + "configdrive2", + "nocloud", + }, false) +} + func testComputedAttributes(t *testing.T, s *schema.Resource, keys []string) { for _, v := range keys { if s.Schema[v] == nil {