Skip to content

Commit

Permalink
feat: Add cloud-init network-config support
Browse files Browse the repository at this point in the history
  • Loading branch information
groggemans committed Dec 29, 2022
1 parent 13080b4 commit c4be509
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions proxmoxtf/resource_virtual_environment_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
dvResourceVirtualEnvironmentVMInitializationUserAccountPassword = ""
dvResourceVirtualEnvironmentVMInitializationUserDataFileID = ""
dvResourceVirtualEnvironmentVMInitializationVendorDataFileID = ""
dvResourceVirtualEnvironmentVMInitializationNetworkConfigFileID = ""
dvResourceVirtualEnvironmentVMInitializationType = ""
dvResourceVirtualEnvironmentVMKeyboardLayout = "en-us"
dvResourceVirtualEnvironmentVMMachineType = ""
Expand Down Expand Up @@ -183,6 +184,7 @@ const (
mkResourceVirtualEnvironmentVMInitializationUserAccountUsername = "username"
mkResourceVirtualEnvironmentVMInitializationUserDataFileID = "user_data_file_id"
mkResourceVirtualEnvironmentVMInitializationVendorDataFileID = "vendor_data_file_id"
mkResourceVirtualEnvironmentVMInitializationNetworkConfigFileID = "network_config_file_id"
mkResourceVirtualEnvironmentVMIPv4Addresses = "ipv4_addresses"
mkResourceVirtualEnvironmentVMIPv6Addresses = "ipv6_addresses"
mkResourceVirtualEnvironmentVMKeyboardLayout = "keyboard_layout"
Expand Down Expand Up @@ -782,6 +784,14 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
Default: dvResourceVirtualEnvironmentVMInitializationVendorDataFileID,
ValidateDiagFunc: getFileIDValidator(),
},
mkResourceVirtualEnvironmentVMInitializationNetworkConfigFileID: {
Type: schema.TypeString,
Description: "The ID of a file containing network config",
Optional: true,
ForceNew: true,
Default: dvResourceVirtualEnvironmentVMInitializationNetworkConfigFileID,
ValidateDiagFunc: getFileIDValidator(),
},
mkResourceVirtualEnvironmentVMInitializationType: {
Type: schema.TypeString,
Description: "The cloud-init configuration format",
Expand Down Expand Up @@ -2315,6 +2325,15 @@ func resourceVirtualEnvironmentVMGetCloudInitConfig(d *schema.ResourceData) (*pr
initializationConfig.Files.VendorVolume = &initializationVendorDataFileID
}

initializationNetworkConfigFileID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationNetworkConfigFileID].(string)

if initializationNetworkConfigFileID != "" {
if initializationConfig.Files == nil {
initializationConfig.Files = &proxmox.CustomCloudInitFiles{}
}
initializationConfig.Files.NetworkVolume = &initializationNetworkConfigFileID
}

initializationType := initializationBlock[mkResourceVirtualEnvironmentVMInitializationType].(string)

if initializationType != "" {
Expand Down Expand Up @@ -3183,6 +3202,11 @@ func resourceVirtualEnvironmentVMReadCustom(ctx context.Context, d *schema.Resou
} else {
initialization[mkResourceVirtualEnvironmentVMInitializationVendorDataFileID] = ""
}
if vmConfig.CloudInitFiles.NetworkVolume != nil {
initialization[mkResourceVirtualEnvironmentVMInitializationNetworkConfigFileID] = *vmConfig.CloudInitFiles.NetworkVolume
} else {
initialization[mkResourceVirtualEnvironmentVMInitializationNetworkConfigFileID] = ""
}
} else if len(initialization) > 0 {
initialization[mkResourceVirtualEnvironmentVMInitializationUserDataFileID] = ""
initialization[mkResourceVirtualEnvironmentVMInitializationVendorDataFileID] = ""
Expand Down

0 comments on commit c4be509

Please sign in to comment.