Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 27f

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox

Previously, for a TypeScript training, I needed an environment with Visual Studio Code and Node.js (a JavaScript runtime). In a previous article, I shared with you the steps I took, to get this working within an Oracle VirtualBox appliance, with the help of Vagrant.
[https://technology.amis.nl/recent/installing-ubuntu-desktop-22-04-lts-visual-studio-code-and-node-js-on-a-virtual-machine-using-vagrant-and-oracle-virtualbox/]

This time I needed a similar environment that also included Terraform and Azure Command-Line Interface (CLI), for a Terraform training set up by a number of my AMIS colleagues.

Most of the times, I want to keep this kind of environments separate from other software on my Windows laptop and that is why I use a virtual machine (via VirtualBox), by means of Vagrant.

After using Vagrant 2.3.6, as I described in my last article, I had to troubleshoot that environment, because I did run into some errors, with regard to VirtualBox Guest Additions.
[https://technology.amis.nl/tech/trouble-shooting-vagrant-2-3-6-and-virtualbox-guest-additions-while-upgrading-a-vm-with-ubuntu-desktop-22-04-lts-on-my-windows-laptop-using-vagrant-and-oracle-virtualbox/]

In this article I will describe installing Ubuntu Desktop with the help of Vagrant, including Visual Studio Code, Node.js, Terraform and Azure CLI. I also will share with you some details of the first steps of the Terraform training, were I used Azure as the infrastructure provider and I created and later on destroyed a resource group.

Terraform

HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle. Terraform can manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features.
[https://developer.hashicorp.com/terraform/intro]

In the Terraform training we used Azure as the infrastructure provider, in order to build, change, and destroy an Azure infrastructure in the cloud.

For more information about this, see for example:

https://developer.hashicorp.com/terraform/tutorials/azure-get-started

How does Terraform work?

Terraform creates and manages resources on cloud platforms and other services through their application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 28

HashiCorp and the Terraform community have already written thousands of providers to manage many different types of resources and services. You can find all publicly available providers on the Terraform Registry, including Amazon Web Services (AWS), Azure, Google Cloud Platform (GCP), Kubernetes, Helm, GitHub, Splunk, DataDog, and many more.

The core Terraform workflow consists of three stages:

  • Write: You define resources, which may be across multiple cloud providers and services. For example, you might create a configuration to deploy an application on virtual machines in a Virtual Private Cloud (VPC) network with security groups and a load balancer.
  • Plan: Terraform creates an execution plan describing the infrastructure it will create, update, or destroy based on the existing infrastructure and your configuration.
  • Apply: On approval, Terraform performs the proposed operations in the correct order, respecting any resource dependencies. For example, if you update the properties of a VPC and change the number of virtual machines in that VPC, Terraform will recreate the VPC before scaling the virtual machines.

[https://developer.hashicorp.com/terraform/intro]

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 29

For more information on Terraform, please visit:

https://developer.hashicorp.com/terraform

Azure CLI

The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It allows the execution of commands through a terminal using interactive command-line prompts or a script.

For interactive use, you first launch a shell such as cmd.exe on Windows, or Bash on Linux or macOS, and then issue a command at the shell prompt. To automate repetitive tasks, you assemble the CLI commands into a shell script using the script syntax of your chosen shell, and then you execute the script.

You can install the Azure CLI locally on Linux, Mac, or Windows computers. It can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container.
[https://learn.microsoft.com/en-us/cli/azure/what-is-azure-cli]

For more information on Azure CLI, please visit:

https://learn.microsoft.com/en-us/cli/azure/

Terraform training

In the Terraform training, set up by a number of my AMIS colleagues, as an example we had to create a simplified IoT application with several components:

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 30

The training was not about the IoT application itself, but about the infrastructure. The IoT application was used to show the different components and how they interact with each other.

Because, this article is about setting up the training environment, I will not go into all the details of the Terraform training itself, but I can share the steps we had to follow (of which I will share a few in more detail with you):

  • Step 1: Create a Terraform configuration
  • Step 2: Add variables for the Azure provider
  • Step 3: Create a resource group
  • Step 4: Create a log analytics environment
  • Step 5: Create an application insight instance
  • Step 6: Create a storage account
  • Step 7: Create an app service plan
  • Step 8: Create an function app

Extra steps (service integration):

  • Step Extra 1: Create an IoT hub
  • Step Extra 2: Create an event hub
  • Step Extra 3: Create a custom endpoint in IoT hub to the event hub

Extra steps (security / network integration):

  • Step Extra 4: Create a virtual network & sub net
  • Step Extra 5: Integrate function app with storage account via network integration

As I mentioned before, I wanted to keep this training environment separate from other software on my Windows laptop and that is why I chose to use a virtual machine (via VirtualBox) for this, by means of Vagrant.

Vagrantfile and shell script

Since my last article I had the following Vagrantfile in place:
[https://technology.amis.nl/tech/trouble-shooting-vagrant-2-3-6-and-virtualbox-guest-additions-while-upgrading-a-vm-with-ubuntu-desktop-22-04-lts-on-my-windows-laptop-using-vagrant-and-oracle-virtualbox/]

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2204"
  
  config.vm.define "ubuntu_vsc_terraform_azurecli" do |ubuntu_vsc_terraform_azurecli|
    
    config.vm.synced_folder "C:\\My\\AMIS\\MySharedFolder", "/mnt/mysharedfolder", automount: true
    
    config.vm.provider "virtualbox" do |vb|
        vb.name = "Ubuntu Desktop, Visual Studio Code, Terraform and Azure CLI"
        vb.memory = "8192"
        vb.cpus = "2"
        vb.customize ['modifyvm', :id, '--graphicscontroller', 'vmsvga']
        vb.customize ['modifyvm', :id, '--vram', '16']
        vb.customize ["modifyvm", :id, "--clipboard-mode", "bidirectional"]
        vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
        vb.customize ["storageattach", :id, "--storagectl", "IDE Controller", "--port", "0", "--device", "0", "--type", "dvddrive", "--medium", "C:\\My\\App\\Oracle\\VirtualBox\\VBoxGuestAdditions.iso"]
        vb.gui = true
    
    args = []
    config.vm.provision "ubuntu_etc shell script", type: "shell",
        path: "scripts/ubuntu_etc.sh",
        args: args
    
    args = []
    config.vm.provision "fix_vboxguestadditions shell script", type: "shell",
        path: "scripts/fix_vboxguestadditions.sh",
        args: args
    end
    
  end

end

In the scripts directory I had a file ubuntu_etc.sh with the following content:

#!/bin/bash
echo "**** Begin installing Ubuntu, etc"

sudo apt update
sudo apt upgrade -y

echo "**** Begin installing ubuntu-desktop"
sudo apt install ubuntu-desktop -y
sudo timedatectl set-timezone Europe/Amsterdam
echo "**** End installing ubuntu-desktop"

echo "**** Begin installing Visual Studio Code"
#Install the apt repository and signing key to enable auto-updating using the system's package manager
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

#Update the package cache and install the package
sudo apt install apt-transport-https
sudo apt update
sudo apt install code
echo "**** End installing Visual Studio Code"

echo "**** Begin installing Node.js"
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
echo "**** End installing Node.js"

echo "**** End installing Ubuntu, etc"

In the scripts directory I had a file fix_vboxguestadditions.sh with the following content:

#!/bin/bash
echo "**** Begin preparations for installing VBoxGuestAdditions"

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential module-assistant
sudo m-a prepare
#cd /media/vagrant/VBox_GAs_7.0.8
#sudo sh ./VBoxLinuxAdditions.run

echo "**** End preparations for installing VBoxGuestAdditions"

Remark:
For the VBox_GAs_7.0.8 to be present you actually have to be in the GUI. So I commented out these lines, but left them for my own convenience (when I have to manually execute them later on).

Installing Terraform

For installing Terraform on Ubuntu, I followed the instructions from “Install Terraform”:

https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli

I changed the content of my ubuntu_etc.sh script to:
[in bold, I highlighted the changes]

#!/bin/bash
echo "**** Begin installing Ubuntu, etc"

sudo apt update
sudo apt upgrade -y

echo "**** Begin installing ubuntu-desktop"
sudo apt install ubuntu-desktop -y
sudo timedatectl set-timezone Europe/Amsterdam
echo "**** End installing ubuntu-desktop"

echo "**** Begin installing Visual Studio Code"
#Install the apt repository and signing key to enable auto-updating using the system's package manager
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

#Update the package cache and install the package
sudo apt install apt-transport-https
sudo apt update
sudo apt install code
echo "**** End installing Visual Studio Code"

echo "**** Begin installing Node.js"
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
echo "**** End installing Node.js"

echo "**** Begin installing Terraform"
#Ensure that your system is up to date and you have installed the gnupg, software-properties-common, and curl packages installed. You will use these packages to verify HashiCorp's GPG signature and install HashiCorp's Debian package repository.
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
#Install the HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
#Verify the key's fingerprint
sudo gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint
#Add the official HashiCorp repository to your system. The lsb_release -cs command finds the distribution release codename for your current system, such as buster, groovy, or sid.
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
#Download the package information from HashiCorp
sudo apt update
#Install Terraform from the new repository
sudo apt-get install terraform
#Verify the installation
terraform -help
#Enable tab completion
touch ~/.bashrc
#Then install the autocomplete package
terraform -install-autocomplete
echo "**** End installing Terraform"

echo "**** End installing Ubuntu, etc"

Installing Azure Command-Line Interface (CLI)

For installing Azure CLI on Ubuntu, I followed the instructions from “How to install the Azure CLI”:

https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt#install-azure-cli

I changed the content of my ubuntu_etc.shm script to:
[in bold, I highlighted the changes]

#!/bin/bash
echo "**** Begin installing Ubuntu, etc"

sudo apt update
sudo apt upgrade -y

echo "**** Begin installing ubuntu-desktop"
sudo apt install ubuntu-desktop -y
sudo timedatectl set-timezone Europe/Amsterdam
echo "**** End installing ubuntu-desktop"

echo "**** Begin installing Visual Studio Code"
#Install the apt repository and signing key to enable auto-updating using the system's package manager
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

#Update the package cache and install the package
sudo apt install apt-transport-https
sudo apt update
sudo apt install code
echo "**** End installing Visual Studio Code"

echo "**** Begin installing Node.js"
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
echo "**** End installing Node.js"

echo "**** Begin installing Terraform"
#Ensure that your system is up to date and you have installed the gnupg, software-properties-common, and curl packages installed. You will use these packages to verify HashiCorp's GPG signature and install HashiCorp's Debian package repository.
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
#Install the HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
#Verify the key's fingerprint
sudo gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint
#Add the official HashiCorp repository to your system. The lsb_release -cs command finds the distribution release codename for your current system, such as buster, groovy, or sid.
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
#Download the package information from HashiCorp
sudo apt update
#Install Terraform from the new repository
sudo apt-get install terraform
#Verify the installation
terraform -help
#Enable tab completion
touch ~/.bashrc
#Then install the autocomplete package
terraform -install-autocomplete
echo "**** End installing Terraform"

echo "**** Begin installing Azure CLI"
# Get packages needed for the install process
sudo apt-get update
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
#Download and install the Microsoft signing key
sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc |
    gpg --dearmor |
    sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
#Add the Azure CLI software repository
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list
#Update repository information and install the azure-cli package
sudo apt-get update
sudo apt-get install azure-cli
echo "**** End installing Azure CLI"

echo "**** End installing Ubuntu, etc"

Since my last article, on my Windows laptop, I had a running machine with the same name. So, in order to stop that running machine and destroy its resources, I used the following command on the Windows Command Prompt: vagrant destroy

With the following output:

    ubuntu_vsc_terraform_azurecli: Are you sure you want to destroy the ubuntu_vsc_terraform_azurecli' VM? [y/N] y
==> ubuntu_vsc_terraform_azurecli: Discarding saved state of VM...
==> ubuntu_vsc_terraform_azurecli: Destroying VM and associated drives...

This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.
[https://www.vagrantup.com/docs/cli/destroy.html]

From here on in this blog, for simplicity, I will no longer mention the vagrant destroy command preceding the vagrant up command.

Next, I used the following command on the Windows Command Prompt: vagrant up

With the following output (only showing the relevant parts):

Bringing machine ‘ubuntu_vsc_terraform_azurecli’ up with ‘virtualbox’ provider…
==> ubuntu_vsc_terraform_azurecli: Importing base box ‘generic/ubuntu2204’…
==> ubuntu_vsc_terraform_azurecli: Matching MAC address for NAT networking…
==> ubuntu_vsc_terraform_azurecli: Checking if box ‘generic/ubuntu2204’ version ‘4.2.16’ is up to date…
==> ubuntu_vsc_terraform_azurecli: Setting the name of the VM: Ubuntu Desktop, Visual Studio Code, Terraform and Azure CLI
==> ubuntu_vsc_terraform_azurecli: Clearing any previously set network interfaces…
==> ubuntu_vsc_terraform_azurecli: Preparing network interfaces based on configuration…
ubuntu_vsc_terraform_azurecli: Adapter 1: nat
==> ubuntu_vsc_terraform_azurecli: Forwarding ports…
ubuntu_vsc_terraform_azurecli: 22 (guest) => 2222 (host) (adapter 1)
==> ubuntu_vsc_terraform_azurecli: Running ‘pre-boot’ VM customizations…
==> ubuntu_vsc_terraform_azurecli: Booting VM…
==> ubuntu_vsc_terraform_azurecli: Waiting for machine to boot. This may take a few minutes…
ubuntu_vsc_terraform_azurecli: SSH address: 127.0.0.1:2222
ubuntu_vsc_terraform_azurecli: SSH username: vagrant
ubuntu_vsc_terraform_azurecli: SSH auth method: private key
ubuntu_vsc_terraform_azurecli: Warning: Connection reset. Retrying…
ubuntu_vsc_terraform_azurecli: Warning: Connection aborted. Retrying…
ubuntu_vsc_terraform_azurecli: Warning: Remote connection disconnect. Retrying…
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Vagrant insecure key detected. Vagrant will automatically replace
ubuntu_vsc_terraform_azurecli: this with a newly generated keypair for better security.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Inserting generated public key within guest…
ubuntu_vsc_terraform_azurecli: Removing insecure key from the guest if it’s present…
ubuntu_vsc_terraform_azurecli: Key inserted! Disconnecting and reconnecting using new SSH key…
==> ubuntu_vsc_terraform_azurecli: Machine booted and ready!
==> ubuntu_vsc_terraform_azurecli: Checking for guest additions in VM…
ubuntu_vsc_terraform_azurecli: The guest additions on this VM do not match the installed version of
ubuntu_vsc_terraform_azurecli: VirtualBox! In most cases this is fine, but in rare cases it can
ubuntu_vsc_terraform_azurecli: prevent things such as shared folders from working properly. If you see
ubuntu_vsc_terraform_azurecli: shared folder errors, please make sure the guest additions within the
ubuntu_vsc_terraform_azurecli: virtual machine match the version of VirtualBox you have installed on
ubuntu_vsc_terraform_azurecli: your host and reload your VM.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Guest Additions Version: 6.1.38
ubuntu_vsc_terraform_azurecli: VirtualBox Version: 7.0
==> ubuntu_vsc_terraform_azurecli: Mounting shared folders…
ubuntu_vsc_terraform_azurecli: /mnt/mysharedfolder => C:/My/AMIS/MySharedFolder
==> ubuntu_vsc_terraform_azurecli: Running provisioner: ubuntu_etc shell script (shell)…
ubuntu_vsc_terraform_azurecli: Running: C:/Users/marc_l/AppData/Local/Temp/vagrant-shell20230816-13280-9qvc3x.sh
ubuntu_vsc_terraform_azurecli: **** Begin installing Ubuntu, etc
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease
ubuntu_vsc_terraform_azurecli: Get:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease [119 kB]

ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: **** Begin installing ubuntu-desktop
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: The following additional packages will be installed:
ubuntu_vsc_terraform_azurecli: accountsservice acl acpi-support acpid adwaita-icon-theme aisleriot
ubuntu_vsc_terraform_azurecli: alsa-base alsa-topology-conf alsa-ucm-conf alsa-utils anacron apg apport-gtk

ubuntu_vsc_terraform_azurecli: Fetched 660 MB in 6min 2s (1,825 kB/s)

ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: **** End installing ubuntu-desktop
ubuntu_vsc_terraform_azurecli: **** Begin installing Visual Studio Code
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: wget is already the newest version (1.21.2-2ubuntu1).
ubuntu_vsc_terraform_azurecli: gpg is already the newest version (2.2.27-3ubuntu2.1).
ubuntu_vsc_terraform_azurecli: gpg set to manually installed.
ubuntu_vsc_terraform_azurecli: 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: The following NEW packages will be installed:
ubuntu_vsc_terraform_azurecli: apt-transport-https
ubuntu_vsc_terraform_azurecli: 0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
ubuntu_vsc_terraform_azurecli: Need to get 1,510 B of archives.
ubuntu_vsc_terraform_azurecli: After this operation, 169 kB of additional disk space will be used.
ubuntu_vsc_terraform_azurecli: Get:1 https://mirrors.edge.kernel.org/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.10 [1,510 B]
ubuntu_vsc_terraform_azurecli: dpkg-preconfigure: unable to re-open stdin: No such file or directory
ubuntu_vsc_terraform_azurecli: Fetched 1,510 B in 1s (2,745 B/s)
ubuntu_vsc_terraform_azurecli: Selecting previously unselected package apt-transport-https.
(Reading database … 199905 files and directories currently installed.)
ubuntu_vsc_terraform_azurecli: Preparing to unpack …/apt-transport-https_2.4.10_all.deb …
ubuntu_vsc_terraform_azurecli: Unpacking apt-transport-https (2.4.10) …
ubuntu_vsc_terraform_azurecli: Setting up apt-transport-https (2.4.10) …
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Pending kernel upgrade!
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Running kernel version:
ubuntu_vsc_terraform_azurecli: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Diagnostics:
ubuntu_vsc_terraform_azurecli: The currently running kernel version is not the expected kernel version 5.15.0-79-generic.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Services to be restarted:
ubuntu_vsc_terraform_azurecli: systemctl restart irqbalance.service
ubuntu_vsc_terraform_azurecli: systemctl restart multipathd.service
ubuntu_vsc_terraform_azurecli: systemctl restart packagekit.service
ubuntu_vsc_terraform_azurecli: systemctl restart polkit.service
ubuntu_vsc_terraform_azurecli: systemctl restart udisks2.service
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Service restarts being deferred:
ubuntu_vsc_terraform_azurecli: /etc/needrestart/restart.d/dbus.service
ubuntu_vsc_terraform_azurecli: systemctl restart networkd-dispatcher.service
ubuntu_vsc_terraform_azurecli: systemctl restart systemd-logind.service
ubuntu_vsc_terraform_azurecli: systemctl restart user@1000.service
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Get:1 https://packages.microsoft.com/repos/code stable InRelease [3,569 B]
… ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: **** End installing Visual Studio Code
ubuntu_vsc_terraform_azurecli: **** Begin installing Node.js
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: ## Installing the NodeSource Node.js 18.x repo…
ubuntu_vsc_terraform_azurecli:

ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Pending kernel upgrade!
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Running kernel version:
ubuntu_vsc_terraform_azurecli: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Diagnostics:
ubuntu_vsc_terraform_azurecli: The currently running kernel version is not the expected kernel version 5.15.0-79-generic.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Services to be restarted:
..
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: **** End installing Node.js
ubuntu_vsc_terraform_azurecli: **** Begin installing Terraform
ubuntu_vsc_terraform_azurecli: Hit:1 https://deb.nodesource.com/node_18.x jammy InRelease

ubuntu_vsc_terraform_azurecli: Preparing to unpack …/terraform_1.5.5-1_amd64.deb …
ubuntu_vsc_terraform_azurecli: Unpacking terraform (1.5.5-1) …
ubuntu_vsc_terraform_azurecli: Setting up terraform (1.5.5-1) …
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Pending kernel upgrade!
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Running kernel version:
ubuntu_vsc_terraform_azurecli: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Diagnostics:
ubuntu_vsc_terraform_azurecli: The currently running kernel version is not the expected kernel version 5.15.0-79-generic.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Services to be restarted:

ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: Usage: terraform [global options] <subcommand> [args]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: The available commands for execution are listed below.
ubuntu_vsc_terraform_azurecli: The primary workflow commands are given first, followed by
ubuntu_vsc_terraform_azurecli: less common or more advanced commands.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Main commands:
ubuntu_vsc_terraform_azurecli: init Prepare your working directory for other commands
ubuntu_vsc_terraform_azurecli: validate Check whether the configuration is valid
ubuntu_vsc_terraform_azurecli: plan Show changes required by the current configuration
ubuntu_vsc_terraform_azurecli: apply Create or update infrastructure
ubuntu_vsc_terraform_azurecli: destroy Destroy previously-created infrastructure
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: All other commands:
ubuntu_vsc_terraform_azurecli: console Try Terraform expressions at an interactive command prompt
ubuntu_vsc_terraform_azurecli: fmt Reformat your configuration in the standard style
ubuntu_vsc_terraform_azurecli: force-unlock Release a stuck lock on the current workspace
ubuntu_vsc_terraform_azurecli: get Install or upgrade remote Terraform modules
ubuntu_vsc_terraform_azurecli: graph Generate a Graphviz graph of the steps in an operation
ubuntu_vsc_terraform_azurecli: import Associate existing infrastructure with a Terraform resource
ubuntu_vsc_terraform_azurecli: login Obtain and save credentials for a remote host
ubuntu_vsc_terraform_azurecli: logout Remove locally-stored credentials for a remote host
ubuntu_vsc_terraform_azurecli: metadata Metadata related commands
ubuntu_vsc_terraform_azurecli: output Show output values from your root module
ubuntu_vsc_terraform_azurecli: providers Show the providers required for this configuration
ubuntu_vsc_terraform_azurecli: refresh Update the state to match remote systems
ubuntu_vsc_terraform_azurecli: show Show the current state or a saved plan
ubuntu_vsc_terraform_azurecli: state Advanced state management
ubuntu_vsc_terraform_azurecli: taint Mark a resource instance as not fully functional
ubuntu_vsc_terraform_azurecli: test Experimental support for module integration testing
ubuntu_vsc_terraform_azurecli: untaint Remove the ‘tainted’ state from a resource instance
ubuntu_vsc_terraform_azurecli: version Show the current Terraform version
ubuntu_vsc_terraform_azurecli: workspace Workspace management
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Global options (use these before the subcommand, if any):
ubuntu_vsc_terraform_azurecli: -chdir=DIR Switch to a different working directory before executing the
ubuntu_vsc_terraform_azurecli: given subcommand.
ubuntu_vsc_terraform_azurecli: -help Show this help output, or the help for a specified subcommand.
ubuntu_vsc_terraform_azurecli: -version An alias for the “version” subcommand.
ubuntu_vsc_terraform_azurecli: **** End installing Terraform
ubuntu_vsc_terraform_azurecli: **** Begin installing Azure CLI
ubuntu_vsc_terraform_azurecli: Hit:1 https://apt.releases.hashicorp.com jammy InRelease

ubuntu_vsc_terraform_azurecli: Preparing to unpack …/azure-cli_2.51.0-1~jammy_amd64.deb …
ubuntu_vsc_terraform_azurecli: Unpacking azure-cli (2.51.0-1~jammy) …
ubuntu_vsc_terraform_azurecli: Setting up azure-cli (2.51.0-1~jammy) …
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Pending kernel upgrade!
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Running kernel version:
ubuntu_vsc_terraform_azurecli: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Diagnostics:
ubuntu_vsc_terraform_azurecli: The currently running kernel version is not the expected kernel version 5.15.0-79-generic.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Services to be restarted:

ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: **** End installing Azure CLI
ubuntu_vsc_terraform_azurecli: **** End installing Ubuntu, etc
==> ubuntu_vsc_terraform_azurecli: Running provisioner: fix_vboxguestadditions shell script (shell)…
ubuntu_vsc_terraform_azurecli: Running: C:/Users/marc_l/AppData/Local/Temp/vagrant-shell20230816-13280-e2nehr.sh
ubuntu_vsc_terraform_azurecli: **** Begin preparations for installing VBoxGuestAdditions
ubuntu_vsc_terraform_azurecli: Hit:1 https://apt.releases.hashicorp.com jammy InRelease
ubuntu_vsc_terraform_azurecli: Hit:2 https://packages.microsoft.com/repos/azure-cli jammy InRelease
ubuntu_vsc_terraform_azurecli: Hit:3 https://packages.microsoft.com/repos/code stable InRelease
ubuntu_vsc_terraform_azurecli: Hit:4 https://deb.nodesource.com/node_18.x jammy InRelease
ubuntu_vsc_terraform_azurecli: Hit:5 https://mirrors.edge.kernel.org/ubuntu jammy InRelease
ubuntu_vsc_terraform_azurecli: Hit:6 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease
ubuntu_vsc_terraform_azurecli: Hit:7 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease
ubuntu_vsc_terraform_azurecli: Hit:8 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: Calculating upgrade…
ubuntu_vsc_terraform_azurecli: The following packages have been kept back:
ubuntu_vsc_terraform_azurecli: apt apt-utils libapt-pkg6.0
ubuntu_vsc_terraform_azurecli: 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: The following additional packages will be installed:
ubuntu_vsc_terraform_azurecli: dpkg-dev fakeroot g++ g++-11 gcc gcc-11 libalgorithm-diff-perl
ubuntu_vsc_terraform_azurecli: libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libc-dev-bin
ubuntu_vsc_terraform_azurecli: libc-devtools libc6-dev libcc1-0 libcrypt-dev libdpkg-perl libfakeroot
ubuntu_vsc_terraform_azurecli: libfile-fcntllock-perl libgcc-11-dev libitm1 liblsan0 libnsl-dev
ubuntu_vsc_terraform_azurecli: libquadmath0 libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev
ubuntu_vsc_terraform_azurecli: lto-disabled-list make manpages-dev rpcsvc-proto
ubuntu_vsc_terraform_azurecli: Suggested packages:
ubuntu_vsc_terraform_azurecli: debian-keyring g++-multilib g++-11-multilib gcc-11-doc gcc-multilib autoconf
ubuntu_vsc_terraform_azurecli: automake libtool flex bison gcc-doc gcc-11-multilib gcc-11-locales glibc-doc
ubuntu_vsc_terraform_azurecli: bzr libstdc++-11-doc make-doc
ubuntu_vsc_terraform_azurecli: The following NEW packages will be installed:
ubuntu_vsc_terraform_azurecli: build-essential dpkg-dev fakeroot g++ g++-11 gcc gcc-11
ubuntu_vsc_terraform_azurecli: libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
ubuntu_vsc_terraform_azurecli: libasan6 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
ubuntu_vsc_terraform_azurecli: libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-11-dev libitm1
ubuntu_vsc_terraform_azurecli: liblsan0 libnsl-dev libquadmath0 libstdc++-11-dev libtirpc-dev libtsan0
ubuntu_vsc_terraform_azurecli: libubsan1 linux-libc-dev lto-disabled-list make manpages-dev
ubuntu_vsc_terraform_azurecli: module-assistant rpcsvc-proto
ubuntu_vsc_terraform_azurecli: 0 upgraded, 34 newly installed, 0 to remove and 3 not upgraded.
ubuntu_vsc_terraform_azurecli: Need to get 50.9 MB of archives.
ubuntu_vsc_terraform_azurecli: After this operation, 172 MB of additional disk space will be used.

ubuntu_vsc_terraform_azurecli: Setting up build-essential (12.9ubuntu3) …
ubuntu_vsc_terraform_azurecli: Processing triggers for man-db (2.10.2-1) …
ubuntu_vsc_terraform_azurecli: Processing triggers for libc-bin (2.35-0ubuntu3.1) …
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Pending kernel upgrade!
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Running kernel version:
ubuntu_vsc_terraform_azurecli: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Diagnostics:
ubuntu_vsc_terraform_azurecli: The currently running kernel version is not the expected kernel version 5.15.0-79-generic.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Services to be restarted:
ubuntu_vsc_terraform_azurecli: systemctl restart irqbalance.service
ubuntu_vsc_terraform_azurecli: systemctl restart multipathd.service
ubuntu_vsc_terraform_azurecli: systemctl restart packagekit.service
ubuntu_vsc_terraform_azurecli: systemctl restart polkit.service
ubuntu_vsc_terraform_azurecli: systemctl restart udisks2.service
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Service restarts being deferred:
ubuntu_vsc_terraform_azurecli: /etc/needrestart/restart.d/dbus.service
ubuntu_vsc_terraform_azurecli: systemctl restart networkd-dispatcher.service
ubuntu_vsc_terraform_azurecli: systemctl restart systemd-logind.service
ubuntu_vsc_terraform_azurecli: systemctl restart user@1000.service
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No containers need to be restarted.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No user sessions are running outdated binaries.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: No VM guests are running outdated hypervisor (qemu) binaries on this host.
ubuntu_vsc_terraform_azurecli: Getting source for kernel version: 5.15.0-69-generic
ubuntu_vsc_terraform_azurecli: Kernel headers available in /usr/src/linux-headers-5.15.0-69-generic
ubuntu_vsc_terraform_azurecli: Creating symlink…
ubuntu_vsc_terraform_azurecli: apt-get install build-essential
ubuntu_vsc_terraform_azurecli: Reading package lists…
ubuntu_vsc_terraform_azurecli: Building dependency tree…
ubuntu_vsc_terraform_azurecli: Reading state information…
ubuntu_vsc_terraform_azurecli: build-essential is already the newest version (12.9ubuntu3).
ubuntu_vsc_terraform_azurecli: 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
ubuntu_vsc_terraform_azurecli:
ubuntu_vsc_terraform_azurecli: Done!
ubuntu_vsc_terraform_azurecli: **** End preparations for installing VBoxGuestAdditions

By the way, importing this base box and creating the virtual machine takes quite some time!

In the VirtualBox GUI, I logged in as user: vagrant

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 31

I used the following command on the VirtualBox GUI shell: sudo reboot
After a while, the login screen appeared.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 32

After I logged in as user vagrant, I had to step through some welcome screens.
Please see my previous article for more information about this.
[https://technology.amis.nl/tech/trouble-shooting-vagrant-2-3-6-and-virtualbox-guest-additions-while-upgrading-a-vm-with-ubuntu-desktop-22-04-lts-on-my-windows-laptop-using-vagrant-and-oracle-virtualbox/]

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 33

As I mentioned in my previous article, I still needed to do some manual steps, to fix the problem with regard to VirtualBox Guest Additions.
[https://technology.amis.nl/tech/trouble-shooting-vagrant-2-3-6-and-virtualbox-guest-additions-while-upgrading-a-vm-with-ubuntu-desktop-22-04-lts-on-my-windows-laptop-using-vagrant-and-oracle-virtualbox/]

I used vagrant ssh to open a Linux Command Prompt where I used the following commands:

cd /media/vagrant/VBox_GAs_7.0.8
sudo sh ./VBoxLinuxAdditions.run

With the following output:

Verifying archive integrity...  100%   MD5 checksums are OK. All good.
Uncompressing VirtualBox 7.0.8 Guest Additions for Linux  100%
VirtualBox Guest Additions installer
This system appears to have a version of the VirtualBox Guest Additions
already installed.  If it is part of the operating system and kept up-to-date,
there is most likely no need to replace it.  If it is not up-to-date, you
should get a notification when you start the system.  If you wish to replace
it with this version, please do not continue with this installation now, but
instead remove the current version first, following the instructions for the
operating system.

If your system simply has the remains of a version of the Additions you could
not remove you should probably continue now, and these will be removed during
installation.

Do you wish to continue? [yes or no]
yes
touch: cannot touch '/var/lib/VBoxGuestAdditions/skip-5.15.0-69-generic': No such file or directory
touch: cannot touch '/var/lib/VBoxGuestAdditions/skip-5.15.0-79-generic': No such file or directory
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Setting up modules
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 5.15.0-79-generic.
update-initramfs: Generating /boot/initrd.img-5.15.0-79-generic
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted or 'rcvboxadd reload' triggered
VirtualBox Guest Additions: reloading kernel modules and services
Cannot reload kernel modules: one or more module(s) is still in use
The log file /var/log/vboxadd-setup.log may contain further information.

As you can see in the output, with this last command I had to type yes when asked to continue.

The following error message was shown:

Cannot reload kernel modules: one or more module(s) is still in use

Of course, we have seen this error before (as I mentioned in my last article).

This time, to solve it, I only did a sudo reboot and logged in.

As I did before, in the appliance, I could Auto-resize Guest Display and I also successfully tried out the copy and paste from guest to host.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 34

Next, I closed the right side bar.

In order to check if Visual Studio Code (VSC) was installed successfully, I clicked on the ‘Show Applications’ icon at the bottom left of the dashboard.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 35

I navigated to the second tab.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 36

Next, I right clicked “Add to Favorites” on the “Visual Studio Code” icon and then I left clicked on the icon, to start the program.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 37

In the ”Welcome” screen, I selected “Light Modern” and I maximized the VSC screen.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 38

Next, I clicked on “Mark Done”.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 39

For the Terraform training, one of the prerequisites was to install the Terraform Extension for Visual Studio Code.

Terraform Extension for Visual Studio Code

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 40

The HashiCorp Terraform Extension for Visual Studio Code (VS Code) with the Terraform Language Server adds editing features for Terraform files such as syntax highlighting, IntelliSense, code navigation, code formatting, module explorer and much more!

Quick Start
Get started writing Terraform configurations with VS Code in three steps:

  • Step 1: If you haven’t done so already, install Terraform
  • Step 2: Install the Terraform Extension for VS Code.
  • Step 3: To activate the extension, open any folder or VS Code workspace containing Terraform files. Once activated, the Terraform language indicator will appear in the bottom right corner of the window.

[https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform]

Installing Terraform Extension for Visual Studio Code

To install the Terraform Extension for Visual Studio Code, in the VSC menu I clicked on File | Preferences | Extensions.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 41

I the “Search Extensions in Marketplace” field, I typed: HashiCorp Terraform.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 42

Next, I clicked on button “Install” at the official HashiCorp Terraform extension.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 43

After the installation finished, in the left hand menu, the “HashiCorp Terraform” icon was visible (below the “Extensions” icon).

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 44

Next, I clicked on the “HashiCorp Terraform” icon.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 45

Here, information is shown about installed providers and modules.
At the moment, of course, neither of them are present.

For now, this was OK.

My shared folder

The Terraform training provided a folder structure, which I copied to my shared folder on my Windows laptop.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 46

In the appliance menu, via Files, I navigated to /mnt/mysharedfolder, in order to check if they were visible.

I could see the amis-terraform-training directory, so this worked.

Next, in VSC I clicked on the “Explorer” icon and then I chose “Open Folder” were I selected the mywork subdirectoy.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 47

In the pop-up I checked the checkbox and clicked on “Yes, I trust the authors”.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 48

In the Explorer tree, I could now see the folder structure of working directory mywork.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 49

Of course to find out if my environment was working correctly, I actually had to try using Terraform. So, I followed the instructions from the Terraform training.

I will now share with you some details of the first steps.

Step 1: Create a Terraform configuration

I needed to create a file provider.tf with the following content:

terraform {
  required_providers {
    azurerm = {
      source  = "azurerm"
      version = "3.52.0"
    }
  }
  #backend "azurerm" {}
}

provider "azurerm" {
  subscription_id = var.ARM_SUBSCRIPTION_ID
  client_id       = var.ARM_CLIENT_ID
  client_secret   = var.ARM_CLIENT_SECRET
  tenant_id       = var.ARM_TENANT_ID
  features {
    resource_group {
      prevent_deletion_if_contains_resources = false
    }
  }
}

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 50

This file defines the provider for Azure and the version of the provider. The provider is the plugin that Terraform uses to interact with Azure. The provider is responsible for understanding API interactions and exposing resources. See also Terraform providers and Azure provider.

As you can see the provider needs some variables. I defined them in a separate file variables.tf with the following content:

variable "ARM_SUBSCRIPTION_ID" {
  description = "Subscription ID for FIP."
  type        = string
}
variable "ARM_CLIENT_ID" {
  description = "See AAD, App registration: Application (client) ID"
  type        = string
}
variable "ARM_CLIENT_SECRET" {
  description = "See AAD, App registration: Client Secret. Use the value"
  type        = string
}
variable "ARM_TENANT_ID" {
  description = "Tenant ID. See Azure Active Directory"
  type        = string
}

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 51

All variables are defined as string. The values will be provided later.

In the VSC menu, I clicked on File | Save All and then I clicked on Terminal | New Terminal.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 52

This opened a new terminal in the working directory mywork.
Then, I used the following command:

terraform init

With the following output:

Initializing the backend…

Initializing provider plugins…
– Finding hashicorp/azurerm versions matching “3.52.0”…
– Installing hashicorp/azurerm v3.52.0…
– Installed hashicorp/azurerm v3.52.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run “terraform init” in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

The terraform init command initializes a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times.
[https://developer.hashicorp.com/terraform/cli/commands/init]

Step 2: Add variables for the Azure provider

To interact with Azure I needed a Service Principal. See also Create an Azure Active Directory application and service principal that can access resources. For the Terraform training, the credentials for the tenant were provided. However, when using your own tenant, you can create a Service Principal (if you do not have one yet) with the following command (after login with az login or az login –tenant <tenant-id>):

az ad sp create-for-rbac --name "appreg-sp-terraform" --role contributor --scopes /subscriptions/$(az account show --query id -o tsv) --sdk-auth

This will output a JSON object with the credentials.

Next, I clicked on the “New Folder” icon, and created a folder with the name “environments” with 1 file dev.tfvars with the following content:

# Terraform Service Principal credentials for the development environment
# =======================================================================
ARM_SUBSCRIPTION_ID = "<subscription-id>"
ARM_CLIENT_ID       = "<client-id>"
ARM_CLIENT_SECRET   = "<client-secret>"
ARM_TENANT_ID       = "<tenant-id>"

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 53

I replaced the values with the values from my Service Principal.

In the VSC menu, I clicked on File | Save.

Next, I checked if the Terraform code worked by running the following command in the terminal:

terraform plan -var-file="environments/dev.tfvars"

With the following output:

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan it:

  • Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date.
  • Compares the current configuration to the prior state and noting any differences.
  • Proposes a set of change actions that should, if applied, make the remote objects match the configuration.

[https://developer.hashicorp.com/terraform/cli/commands/plan]

Step 3: Create a resource group

Now I was ready to actually create some things in Azure. I started with a resource group and created a file resourcegroup.tf with the following content:

resource "azurerm_resource_group" "rg" {
  location = var.location
  name     = "${var.rg_name}"
  tags     = var.tags
}

For this, I had a look at:

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 54

As you can see, I did not hardcoded the name and location of the resource group. I used a variable for that.

I changed the content of file variables.tf to:
[in bold, I highlighted the changes]

variable "ARM_SUBSCRIPTION_ID" {
  description = "Subscription ID for FIP."
  type        = string
}
variable "ARM_CLIENT_ID" {
  description = "See AAD, App registration: Application (client) ID"
  type        = string
}
variable "ARM_CLIENT_SECRET" {
  description = "See AAD, App registration: Client Secret. Use the value"
  type        = string
}
variable "ARM_TENANT_ID" {
  description = "Tenant ID. See Azure Active Directory"
  type        = string
}

variable "rg_name" {
  description = "Resource group name"
  type        = string
}

variable "location" {
  description = "Azure region"
  type        = string
}

variable "tags" {
  description = "Tags for the resources"
  type        = map(string)
}

I also added the default tags which I will use for all resources.

Next, I changed the content of file dev.tfvars to:
[in bold, I highlighted the changes]

# Global variables
location = "West Europe"
tags = {
  "ContactPerson" = "Marc Lameriks"
}

# Terraform Service Principal credentials for the development environment
# =======================================================================
ARM_SUBSCRIPTION_ID = "<subscription-id>"
ARM_CLIENT_ID       = "<client-id>"
ARM_CLIENT_SECRET   = "<client-secret>"
ARM_TENANT_ID       = "<tenant-id>"

rg_name = "rg-amis-terraform-training"

In the VSC menu I clicked on File | Save All.

After I completed the exercise, I used the following command in the terminal:

terraform plan -var-file="environments/dev.tfvars"

With the following output:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.rg will be created
  + resource "azurerm_resource_group" "rg" {
      + id       = (known after apply)
      + location = "westeurope"
      + name     = "rg-amis-terraform-training"
      + tags     = {
          + "ContactPerson" = "Marc Lameriks"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

In order to apply this change (create the resource group), I executed the apply command. The apply command will ask for confirmation. You can add the -auto-approve flag to the command to skip the confirmation:

terraform apply -var-file="environments/dev.tfvars" -auto-approve

With the following output:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.rg will be created
  + resource "azurerm_resource_group" "rg" {
      + id       = (known after apply)
      + location = "westeurope"
      + name     = "rg-amis-terraform-training"
      + tags     = {
          + "ContactPerson" = "Marc Lameriks"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
azurerm_resource_group.rg: Creating...
azurerm_resource_group.rg: Creation complete after 1s [id=/subscriptions/abc..xyz/resourceGroups/rg-amis-terraform-training]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The terraform apply command executes the actions proposed in a Terraform plan.
[https://developer.hashicorp.com/terraform/cli/commands/apply]

In order to check if it worked, I logged in to my Microsoft Azure portal.
Build, manage, and monitor everything from simple web apps to complex cloud applications in a single, unified console.
[https://azure.microsoft.com/en-us/get-started/azure-portal]

In the Azure portal I navigated to the Resource groups.
Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 55

As you can see, the resource group I created via Terraform was present😊.

A resource group is a container that holds related resources for an Azure solution. The resource group can include all the resources for the solution, or only those resources that you want to manage as a group. You decide how you want to allocate resources to resource groups based on what makes the most sense for your organization. Generally, add resources that share the same lifecycle to the same resource group so you can easily deploy, update, and delete them as a group.

The resource group stores metadata about the resources. Therefore, when you specify a location for the resource group, you are specifying where that metadata is stored. For compliance reasons, you may need to ensure that your data is stored in a particular region.
[https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal#what-is-a-resource-group]

In order to destroy the resource group, I used the following command in the terminal:

terraform destroy -var-file="environments/dev.tfvars"

With the following output:

azurerm_resource_group.rg: Refreshing state... [id=/subscriptions/abc..xyz/resourceGroups/rg-amis-terraform-training]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # azurerm_resource_group.rg will be destroyed
  - resource "azurerm_resource_group" "rg" {
      - id       = "/subscriptions/abc..xyz/resourceGroups/rg-amis-terraform-training" -> null
      - location = "westeurope" -> null
      - name     = "rg-amis-terraform-training" -> null
      - tags     = {
          - "ContactPerson" = "Marc Lameriks"
        } -> null
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

azurerm_resource_group.rg: Destroying... [id=/subscriptions/abc..xyz/resourceGroups/rg-amis-terraform-training]
azurerm_resource_group.rg: Still destroying... [id=/subscriptions/abc..xyz/resourceGroups/rg-amis-terraform-training, 10s elapsed]
azurerm_resource_group.rg: Destruction complete after 15s

Destroy complete! Resources: 1 destroyed.

The terraform destroy command will ask for confirmation. You can add the -auto-approve flag to the command to skip the confirmation.

The terraform destroy command is a convenient way to destroy all remote objects managed by a particular Terraform configuration.

While you will typically not want to destroy long-lived objects in a production environment, Terraform is sometimes used to manage ephemeral infrastructure for development purposes, in which case you can use terraform destroy to conveniently clean up all of those temporary objects once you are finished with your work.
[https://developer.hashicorp.com/terraform/cli/commands/destroy]

What I did so far was of course prove enough that my environment was working correctly.

Next, I returned to the left hand menu were I clicked on the “HashiCorp Terraform” icon.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 56

Now, the Azure provider was visible.

Finally, I closed the system, via the VirtualBox menu, File | Close | Save the machine state.

Installing Ubuntu Desktop 22.04 LTS, Visual Studio Code, Terraform and Azure Command-Line Interface (CLI) on a virtual machine using Vagrant and Oracle VirtualBox lameriks 2023 08 57

I now had a working environment to continue the Terraform training later on.

So, that is it. In this article I described, installing Ubuntu Desktop with the help of Vagrant, including Visual Studio Code, Node.js, Terraform and Azure CLI. I also shared with you some details of the first steps of the Terraform training, were I used Azure as the infrastructure provider and I created and later on destroyed a resource group.

You can find the Vagrant code, belonging to my article, here:
https://github.com/marclameriks/amis-technology-blog-2023-08-2

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.