Skip to content

zombiemaker/vsc-rc-aws_client-ubi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Visual Studio Code Workspace Template: Terraform Development For AWS With Remote Containers

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.

Requirements

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

Cloning & Starting Visual Studio Code When Using Docker Desktop for Windows Integrated With WSL2

  1. Start a WSL2 terminal session

  2. Clone this git repo into your local WSL2 file system (do no use a path to the Windows file system from within WSL2)

  3. Change your working directory to the directory where cloned contents are stored

  4. 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
  5. (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
  6. Start Visual Studio Code from within WSL using the "code ." command

  7. 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:

  • Workstation connected to company network using network adapter installed on computer and internet traffic controlled with internet proxy

  • Workstation connected to company network using network adapter installed on docking station and internet traffic controlled with internet proxy

  • Workstation connected to non-company network without VPN to company network and internet traffic NOT controlled with internet proxy

  • Workstation connected to non-company network without VPN to company network and internet traffic controlled with internet proxy

  • Workstation connected to non-company network with VPN to company network and internet traffic NOT controlled with internet proxy

  • Workstation connected to non-company network with VPN to company network and internet traffic controlled with internet proxy

You will need to understand your specific configuration and how to adjust things so that it will work with your environment.

Cloning & Starting Visual Studio Code When Using Docker Desktop for Windows Integrated With Hyper-V

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.

  1. Clone the git repo into your local Windows file system

  2. 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
  3. (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
  4. Open the folder using Visual Studio Code

  5. 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)

Configurations

  • 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",

Save Workspace As A Template

  1. Install the Visual Studio Code extension called "Project Templates" by cantonios.

  2. Press Control+Shift+P

  3. Type "Project: Save Project as Template"

  4. Select "Project: Save Project as Template" option that appears

  5. Enter a name for the workspace template

Create Workspace From Template

  1. Create a folder for a new workspace

  2. Open the folder using Visual Studio Code

  3. Press Control+Shift+P

  4. Type "Project: Create Project from Template"

  5. Select "Project: Create Project from Template" option that appears

  6. Select the workspace template that you created from the previous steps

Switch To Remote Container Mode

  1. Click on the lower-left corner of the Visual Studio Code window

  2. Select "Remote-Containers: Reopen in Container"

    This will download the container image and instantiate a development container for you.

Container User Home Directory & Visual Studio Project Folder contents

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.

  1. After you are in development container mode, open a terminal within Visual Studio Code

  2. Check your current directory

    pwd

    The response should be something like "/workspaces/<name of your directory>"

  3. 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
  4. Check your username

    whoami
    
    me
  5. Change to the "me" user home directory

    cd ~
  6. Check your current path

    pwd
    
    /home/me
  7. 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
  8. Notice that they are the same contents

  9. Create an empty file called "testfile"

    touch testfile
  10. 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
  11. Look at the Explorer panel in Visual Studio Code and expand the containerfs folder

  12. You will notice that the testfile is also listed there

  13. Change to the containerfs folder under the workspace folder

    cd /workspaces/<name of your folder>/containerfs
  14. List the contents of that directory

    ls -la

    You should see the same contents that was in the home directory of the "me" user.

Container Image Contents

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>

Features

  • Fixed .postCreateCommandMarker issue

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages