This is a template Visual Studio Code workspace for developing AWS automation programs using Terraform and Kubernetes Operations (kops).
It uses a remote development container that has all of the tools you need to interact with AWS. It stores programs and configurations in a directory called containerfs, which is mounted to the container user home directory. This enables the persistence of credentials and configurations so that you do not have to repeatedly create them whenever you start a new development container ON THE SAME WORKSTATION. For security reasons, you should not be storing these credentials in a Git repository. If you switch to another workstation, you will have to provide the credentials and configurations again.
This was created and used where the contents are stored WITHIN a Linux WSL distro (e.g. Ubuntu WSL) running under Windows Subsystem for Linux 2 (WSL2). Visual Studio Code is started from within the WSL2 environment. If you try opening this project from within Microsoft Windows or using WSL1, you may have to tweak things to make it work smoothly for your environment.
Software components
-
Microsoft Windows 10 2004+ (or a build that allows Docker Desktop for Windows to use WSL2)
-
Microsoft Windows Subsystem for Linux 2
-
Docker Desktop for Windows Inte WSL2 Extensions
-
Visual Studio Code
-
Visual Studio Code Extensions
-
Remote Development
-
Remote - WSL
-
Remote - Container
-
-
Start a WSL2 terminal session
-
Clone this git repo into your local WSL2 file system (do no use a path to the Windows file system from within WSL2)
-
Change your working directory to the directory where cloned contents are stored
-
Remove the git remote to the original / upstream repo
git remote remove origin
Or delete the .git directory or execute git init to not keep the change history
git init
-
(Optional) Add a new git remote as your to your own remote repo and push changes to new remote
git remote add origin <url to your remote repo> git push origin master
-
Start Visual Studio Code from within WSL using the "code ." command
-
Check to see if you have the option to re-open the project using Remote Containers (select the lower-left corner and a pop-up menu should list the options available to you)
Note
|
The network configuration for the Windows OS and the WSL Linux distro you are using may affect your ability to communicate to network services. The following are some configuration variants:
You will need to understand your specific configuration and how to adjust things so that it will work with your environment. |
When using Docker Desktop for Windows that is using a Hyper-V virtual machine to host Docker containers, there are issues and limitations with using WSL1 and Docker Desktop for Windows together. For this setup to work, do not use Visual Studio Code Remote WSL extension. Make sure that you start Visual Studio Code using local Windows and not the remote WSL connection.
-
Clone the git repo into your local Windows file system
-
Remove the git remote to the original / upstream repo
git remote remove origin
Or delete the .git directory or execute git init to not keep the change history
git init
-
(Optional) Add a new git remote as your to your own remote repo and push changes to new remote
git remote add origin <url to your remote repo> git push origin master
-
Open the folder using Visual Studio Code
-
Check to see if you have the option to re-open the project using Remote Containers (select the lower-left corner and a pop-up menu should list the options available to you)
-
Edit .devcontainer/devcontainer.json file if needed
-
Change the following line if there is an updated container image
"image": "zmaker123/aci-aws_client-ubi:2-8.2-latest"
-
Change the following line if the 11100 port is already used
"appPort": ["11100:8001"]
-
Comment the following line if you are using Docker Desktop for Windows Integrated With Hyper-Visual
"initializeCommand": "if [ -f containerfs/.vscode-server/data/Machine/.postCreateCommandMarker ]; then rm containerfs/.vscode-server/data/Machine/.postCreateCommandMarker; fi",
-
Install the Visual Studio Code extension called "Project Templates" by cantonios.
-
Press Control+Shift+P
-
Type "Project: Save Project as Template"
-
Select "Project: Save Project as Template" option that appears
-
Enter a name for the workspace template
-
Create a folder for a new workspace
-
Open the folder using Visual Studio Code
-
Press Control+Shift+P
-
Type "Project: Create Project from Template"
-
Select "Project: Create Project from Template" option that appears
-
Select the workspace template that you created from the previous steps
-
Click on the lower-left corner of the Visual Studio Code window
-
Select "Remote-Containers: Reopen in Container"
This will download the container image and instantiate a development container for you.
The Linux container user home directory is mounted to the containerfs folder located within the project folder. This enables you to keep configuration and cached files that Linux CLI programs like awscli, kubectl, and terraform store in the Linux user home directory. Whenever you start a new container instance, the files created from previous container instances will still be available for use.
DO NOT COMMIT these files to the git repository. They may contain your security credentials.
-
After you are in development container mode, open a terminal within Visual Studio Code
-
Check your current directory
pwd
The response should be something like "/workspaces/<name of your directory>"
-
List the contents of your current directory
ls -la total 4 drwxrwxrwx 1 root root 0 May 6 17:08 . drwxr-xr-x 3 root root 4096 May 6 17:09 .. drwxrwxrwx 1 root root 0 May 6 17:08 .devcontainer drwxrwxrwx 1 root root 4096 May 6 17:08 .git -rwxr-xr-x 1 root root 45 May 6 17:08 .gitignore -rwxr-xr-x 1 root root 837 May 6 17:08 README.md drwxrwxrwx 1 root root 0 May 6 17:10 containerfs
The containerfs directory is mounted to the container Linux user home directory. To see this, change to the containerfs directory and list its contents.
cd containerfs ls -la total 0 drwxrwxrwx 1 root root 0 May 6 17:10 . drwxrwxrwx 1 root root 0 May 6 17:08 .. drwxrwxrwx 1 root root 0 May 6 17:10 .aws -rwxr-xr-x 1 root root 250 May 6 17:09 .gitconfig drwxrwxrwx 1 root root 0 May 6 17:09 .vscode-server
-
Check your username
whoami me
-
Change to the "me" user home directory
cd ~
-
Check your current path
pwd /home/me
-
Check the contents of the current directory
ls -la total 4 drwxrwxrwx 1 root root 0 May 6 17:10 . drwxr-xr-x 1 root root 4096 May 6 16:17 .. -rwxr-xr-x 1 root root 250 May 6 17:09 .gitconfig drwxrwxrwx 1 root root 0 May 6 17:09 .vscode-server
-
Notice that they are the same contents
-
Create an empty file called "testfile"
touch testfile
-
List the contents of the directory
ls -la total 4 drwxrwxrwx 1 root root 0 May 6 17:30 . drwxr-xr-x 1 root root 4096 May 6 16:17 .. -rwxr-xr-x 1 root root 250 May 6 17:09 .gitconfig drwxrwxrwx 1 root root 0 May 6 17:09 .vscode-server -rwxr-xr-x 1 root root 0 May 6 17:30 testfile
-
Look at the Explorer panel in Visual Studio Code and expand the containerfs folder
-
You will notice that the testfile is also listed there
-
Change to the containerfs folder under the workspace folder
cd /workspaces/<name of your folder>/containerfs
-
List the contents of that directory
ls -la
You should see the same contents that was in the home directory of the "me" user.
The container image will already have the basic software needed to work with AWS. Please read the README file located in the root folder within the container for further details. The name of the file may have different extensions (e.g., no extension, .txt, .adoc, .md, etc.).
The container image repo is located in DockerHub
cd / ls -la more <name-of-readme-file>