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

feat(vm): Add cloud-init network-config support #197

Merged
merged 3 commits into from
Jan 1, 2023
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
2 changes: 2 additions & 0 deletions docs/resources/virtual_environment_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ output "ubuntu_vm_public_key" {
* `keys` - (Optional) The SSH keys.
* `password` - (Optional) The SSH password.
* `username` - (Optional) The SSH username.
* `network_data_file_id` - (Optional) The identifier for a file containing network configuration data passed to the
VM via cloud-init (conflicts with `ip_config`).
* `user_data_file_id` - (Optional) The identifier for a file containing custom user data (conflicts
with `user_account`).
* `vendor_data_file_id` - (Optional) The identifier for a file containing all vendor data passed to the VM via cloud-init.
Expand Down
2 changes: 1 addition & 1 deletion proxmox/virtual_environment_vm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ func (r *CustomCloudInitFiles) UnmarshalJSON(b []byte) error {
case "meta":
r.MetaVolume = &v[1]
case "network":
r.MetaVolume = &v[1]
r.NetworkVolume = &v[1]
case "user":
r.UserVolume = &v[1]
case "vendor":
Expand Down
25 changes: 25 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 = ""
dvResourceVirtualEnvironmentVMInitializationNetworkDataFileID = ""
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"
mkResourceVirtualEnvironmentVMInitializationNetworkDataFileID = "network_data_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(),
},
mkResourceVirtualEnvironmentVMInitializationNetworkDataFileID: {
Type: schema.TypeString,
Description: "The ID of a file containing network config",
Optional: true,
ForceNew: true,
Default: dvResourceVirtualEnvironmentVMInitializationNetworkDataFileID,
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
}

initializationNetworkDataFileID := initializationBlock[mkResourceVirtualEnvironmentVMInitializationNetworkDataFileID].(string)

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

initializationType := initializationBlock[mkResourceVirtualEnvironmentVMInitializationType].(string)

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

if vmConfig.CloudInitType != nil {
Expand Down