Skip to content

Commit

Permalink
adding citype support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Sissons committed Dec 13, 2020
1 parent eb06704 commit fd85eb8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions proxmoxtf/resource_virtual_environment_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
dvResourceVirtualEnvironmentVMInitializationIPConfigIPv6Gateway = ""
dvResourceVirtualEnvironmentVMInitializationUserAccountPassword = ""
dvResourceVirtualEnvironmentVMInitializationUserDataFileID = ""
dvResourceVirtualEnvironmentVMInitializationType = ""
dvResourceVirtualEnvironmentVMKeyboardLayout = "en-us"
dvResourceVirtualEnvironmentVMMemoryDedicated = 512
dvResourceVirtualEnvironmentVMMemoryFloating = 0
Expand Down Expand Up @@ -131,6 +132,7 @@ const (
mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6 = "ipv6"
mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6Address = "address"
mkResourceVirtualEnvironmentVMInitializationIPConfigIPv6Gateway = "gateway"
mkResourceVirtualEnvironmentVMInitializationType = "type"
mkResourceVirtualEnvironmentVMInitializationUserAccount = "user_account"
mkResourceVirtualEnvironmentVMInitializationUserAccountKeys = "keys"
mkResourceVirtualEnvironmentVMInitializationUserAccountPassword = "password"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions proxmoxtf/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fd85eb8

Please sign in to comment.