Giter Site home page Giter Site logo

dev-machine's Introduction

Set up a ubuntu dev machine in AWS.

Requirements

  • aws-vault brew install aws-vault [usage]
  • terraform brew install terraform
  • python3 brew install python3

Setup

Fork this repo and clone locally. Then run:

./bin/setup

Usage

Set variables in .env, then:

./bin/create

Teardown

./bin/destroy

Update

git pull upstream main

Details

Install ansible

python3 -m venv env && \
source env/bin/activate && \
pip3 install ansible && \
ansible-galaxy install diodonfrost.terraform && \
ansible-galaxy install darkwizard242.awsvault

Create .env

cp .env.example .env

Init terraform

terraform init

Generate setup key for ec2 instance

ssh-keygen -t ed25519 -N '' -f ./key

Do this for every new shell

source env/bin/activate
source ./.env

Run terraform plan to test

aws-vault exec $DM_AWS_VAULT_ROLE -- \
  terraform plan \
  -var "instance_type=$DEVMACHINE_INSTANCE_TYPE" \
  -var "ami=$DEVMACHINE_AMI" \
  -var "vpc_id=$DEVMACHINE_VPC_ID" \
  -var "name=$DEVMACHINE_NAME" \
  -var "subnet=$DEVMACHINE_SUBNET" \
  -var "kms_key_arn=$DEVMACHINE_KMS_KEY_ARN"a

Create resources

aws-vault exec $DM_AWS_VAULT_ROLE -- \
  terraform apply \
  -var "instance_type=$DEVMACHINE_INSTANCE_TYPE" \
  -var "ami=$DEVMACHINE_AMI" \
  -var "vpc_id=$DEVMACHINE_VPC_ID" \
  -var "name=$DEVMACHINE_NAME" \
  -var "subnet=$DEVMACHINE_SUBNET" \
  -var "kms_key_arn=$DEVMACHINE_KMS_KEY_ARN"

Tear down resources

aws-vault exec $DM_AWS_VAULT_ROLE -- \
  terraform destroy \
  -auto-approve \
  -var "instance_type=$DEVMACHINE_INSTANCE_TYPE" \
  -var "ami=$DEVMACHINE_AMI" \
  -var "vpc_id=$DEVMACHINE_VPC_ID" \
  -var "name=$DEVMACHINE_NAME" \
  -var "subnet=$DEVMACHINE_SUBNET" \
  -var "kms_key_arn=$DEVMACHINE_KMS_KEY_ARN"

Verify values

terraform state show aws_instance.instance
terraform output -raw ip

Set up ssh access

# trailing comma is required to specify ip list
DM_IP=$(terraform output -raw ip)
DEVMACHINE_HOST="$DM_IP,"
ansible-playbook \
  --private-key "$(pwd)/key" \
  -i $DEVMACHINE_HOST \
  playbooks/ssh.yaml
ssh "ubuntu@$DEVMACHINE_HOST"

Add ssh host

https://stormssh.readthedocs.io/en/latest/index.html

pip3 install stormssh
storm add $DEVMACHINE_NAME ubuntu@$DM_IP
# or update
storm edit $DEVMACHINE_NAME ubuntu@$DM_IP
storm delete $DEVMACHINE_NAME
ssh "ubuntu@$DEVMACHINE_NAME"

Upgrade packages

ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/upgrade.yaml

Setup workspace folders

ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/workspace.yaml

Install nvm

ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/nvm.yaml
ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/packages.yaml
ansible-galaxy install diodonfrost.terraform
ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/terraform.yaml
ansible-galaxy install darkwizard242.awsvault
ansible-playbook \
  -i "$DEVMACHINE_NAME," \
  playbooks/aws-vault.yaml
ssh-add -K ~/.ssh/id_ed25519

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.