Skip to content

feat(aws-vscode-workstation): Add terraform and packer configurtion #10

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ testem.log
Thumbs.db

**/.env

**/.terraform
**/*.tfstate
**/*.tfstate.*
3 changes: 3 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ RUN wget https://github.com/gruntwork-io/cloud-nuke/releases/download/${CLOUD_NU
### https://github.com/jckuester/awsls#installation
RUN brew install jckuester/tap/awsls

### Install terraform cli 1.1.3 as of 01/18/2022
RUN brew tap hashicorp/tap && brew install hashicorp/tap/terraform
RUN brew install hashicorp/tap/packer
9 changes: 9 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform 1.1.4
vault 1.9.3

kubectl 1.23.3
skaffold 1.35.2

awscli 2.4.15
aws-vault 6.4.0
redis-cli 6.2.6
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"users",
"nx",
"devx",
"spotify-passport-auth-express"
"spotify-passport-auth-express",
"serverless-framework-nestjs-sample"
]
}
3 changes: 3 additions & 0 deletions libs/aws-cloud9-terraform/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
18 changes: 18 additions & 0 deletions libs/aws-cloud9-terraform/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
59 changes: 59 additions & 0 deletions libs/aws-cloud9-terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions libs/aws-cloud9-terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# aws-cloud9-terraform

This library was generated with [Nx](https://nx.dev).
59 changes: 59 additions & 0 deletions libs/aws-cloud9-terraform/examples/minimal/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ami = "ami-049164e77a2c5b5f9"
vpc_id = "vpc-2a1b2541"
subnet_id = "subnet-d99aba94"
workstation_ip = "62.216.35.230"
ssh_key_name = "development"
region = "eu-central-1"
29 changes: 29 additions & 0 deletions libs/aws-cloud9-terraform/examples/minimal/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# You cannot create a new backend by simply defining this and then
# immediately proceeding to "terraform apply". The S3 backend must
# be bootstrapped according to the simple yet essential procedure in
# https://github.com/cloudposse/terraform-aws-tfstate-backend#usage
module "terraform_state_backend" {
source = "cloudposse/tfstate-backend/aws"
# Cloud Posse recommends pinning every module to a specific version
version = "0.38.1"
namespace = "lo"
stage = "develop"
name = "terraform"
attributes = ["state"]

terraform_backend_config_file_path = "."
terraform_backend_config_file_name = "backend.tf"
force_destroy = true
}

module "vscode_workstation" {
source = "../../terraform"

region = var.region

ami = "ami-049164e77a2c5b5f9"
vpc_id = var.vpc_id
subnet_id = var.subnet_id
workstation_ip = var.workstation_ip
ssh_key_name = var.ssh_key_name
}
14 changes: 14 additions & 0 deletions libs/aws-cloud9-terraform/examples/minimal/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}

# Configure the AWS Provider
provider "aws" {
region = var.region
}

31 changes: 31 additions & 0 deletions libs/aws-cloud9-terraform/examples/minimal/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variable "ami" {
type = string
default = "ami-0eaa6183e540e9b04"
}

variable "ec2_instance_type" {
type = string
default = "t2.micro"
}

variable "subnet_id" {
type = string
default = "subnet-fd6b7780"
}

variable "vpc_id" {
type = string
}

variable "workstation_ip" {
type = string
}

variable "ssh_key_name" {
type = string
}

variable "region" {
type = string
default = "eu-central-1"
}
79 changes: 79 additions & 0 deletions libs/aws-cloud9-terraform/packer/aws-workstation-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}

source "amazon-ebs" "ubuntu" {
ami_name = "aws-vscode-workstation-linux-aws-0.0.1-rc.7"
instance_type = "t2.micro"
region = var.region

source_ami_filter {
filters = {
name = "ubuntu/images/*ubuntu-bionic-18.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}

ssh_username = "ubuntu"
}

build {
name = "aws-vscode-workstation"

sources = [
"source.amazon-ebs.ubuntu"
]

provisioner "file" {
content = <<EOF
ruby 3.1.0

terraform ${var.terraform_version}
vault 1.9.3

kubectl 1.23.3
skaffold ${var.skaffold_version}

awscli 2.4.15
aws-vault 6.4.0

sonarscanner 4.4.0.2170

jq 1.6
nodejs 12.22.9
EOF
destination = "~/.tool-versions"
}

provisioner "file" {
source = "./install_asdf_plugins.sh"
destination = "/home/ubuntu/install_asdf_plugins.sh"
}

provisioner "file" {
source = "./install_tools.sh"
destination = "/home/ubuntu/install_tools.sh"
}

provisioner "shell" {
environment_vars = [
"FOO=hello world"
]

inline = [
"echo 'Sleeping for 30 seconds to give Ubuntu enough time to initialize (otherwise, packages may fail to install).'",
"sleep 30",
"./install_tools.sh",
"./install_asdf_plugins.sh"
]
}

}
36 changes: 36 additions & 0 deletions libs/aws-cloud9-terraform/packer/install_asdf_plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# install adsf version manager
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.9.0

echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc

source $HOME/.asdf/asdf.sh

asdf plugin-add boundary https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add consul https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add nomad https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add packer https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add sentinel https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add serf https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add terraform https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add vault https://github.com/asdf-community/asdf-hashicorp.git
asdf plugin-add waypoint https://github.com/asdf-community/asdf-hashicorp.git

#
asdf plugin-add kubectl https://github.com/asdf-community/asdf-kubectl.git
asdf plugin-add skaffold https://github.com/virtualstaticvoid/asdf-skaffold.git

#
asdf plugin add awscli
asdf plugin-add aws-vault https://github.com/virtualstaticvoid/asdf-aws-vault.git
#
asdf plugin add redis-cli https://github.com/NeoHsu/asdf-redis-cli.git
asdf plugin add sonarscanner https://github.com/virtualstaticvoid/asdf-sonarscanner.git

asdf plugin add jq
asdf plugin add ruby
asdf plugin add nodejs

asdf install
Loading