From 7154bc7259fd18ac2323872e22a180a1d34031dd Mon Sep 17 00:00:00 2001 From: Eugene Istrati Date: Thu, 9 Apr 2026 03:07:54 -0400 Subject: [PATCH] remove tflocal and awslocal --- backend/README.md | 5 +-- bin/README.md | 2 -- bin/deploy-backend.sh | 2 -- bin/deploy-frontend.sh | 32 ++++++++----------- bin/generate-env.sh | 2 +- bin/setup-environment.sh | 66 +--------------------------------------- bin/start-dev.sh | 18 +++++------ docs/testing.md | 5 +-- infra/README.md | 20 ++++++++++-- 9 files changed, 44 insertions(+), 108 deletions(-) diff --git a/backend/README.md b/backend/README.md index 2609c7c..0460fc7 100644 --- a/backend/README.md +++ b/backend/README.md @@ -86,8 +86,9 @@ To tail logs in real-time: ```sh # Example: Get logs for {{service-name}} -awslocal logs tail /aws/lambda/{{function-name}} \ - --follow --format short --color on +AWS_ENDPOINT_URL="http://localhost:4566" \ + aws logs tail /aws/lambda/{{function-name}} \ + --follow --format short --color on ``` Replace `{{function-name}}` with corresponding service name diff --git a/bin/README.md b/bin/README.md index da2118e..12ebf2b 100644 --- a/bin/README.md +++ b/bin/README.md @@ -200,9 +200,7 @@ Sets up the complete local development environment on Ubuntu 22.04. * Installs Docker (Container runtime) * Installs LocalStack (AWS service emulation) * Installs AWS CLI v2 (AWS command-line tools) -* Installs awslocal (AWS CLI wrapper for LocalStack) * Installs Terraform (Infrastructure as Code) -* Installs tflocal (Terraform wrapper for LocalStack) * Installs PostgreSQL (Relational database) * Installs MongoDB (NoSQL database) * Optionally: Installs and configures dnsmasq (DNS resolution) diff --git a/bin/deploy-backend.sh b/bin/deploy-backend.sh index a08bce6..3595c3c 100755 --- a/bin/deploy-backend.sh +++ b/bin/deploy-backend.sh @@ -20,7 +20,6 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "" echo "Requirements:" echo " - terraform installed" - echo " - tflocal installed (for local development)" echo " - ENVIRONMENT.config file (auto-created for AWS)" echo "" echo "Examples:" @@ -40,7 +39,6 @@ export PATH="$HOME/.local/bin:$PATH" export AWS_REGION=${AWS_REGION:-us-east-1} # Verify required dependencies -tflocal --version > /dev/null 2>&1 || { echo "ERROR: 'tflocal' is missing. Aborting..."; exit 1; } terraform --version > /dev/null 2>&1 || { echo "ERROR: 'terraform' is missing. Aborting..."; exit 1; } # Resolve script directory and project root paths diff --git a/bin/deploy-frontend.sh b/bin/deploy-frontend.sh index 17f82cf..908849b 100755 --- a/bin/deploy-frontend.sh +++ b/bin/deploy-frontend.sh @@ -21,7 +21,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Requirements:" echo " - aws cli installed" echo " - npm installed" - echo " - terraform/tflocal installed" + echo " - terraform installed" echo " - Backend infrastructure deployed first" echo "" echo "Examples:" @@ -39,7 +39,6 @@ echo "" # Verify required dependencies aws --version > /dev/null 2>&1 || { echo "ERROR: 'aws' is missing. Aborting..."; exit 1; } npm --version > /dev/null 2>&1 || { echo "ERROR: 'npm' is missing. Aborting..."; exit 1; } -tflocal --version > /dev/null 2>&1 || { echo "ERROR: 'tflocal' is missing. Aborting..."; exit 1; } terraform --version > /dev/null 2>&1 || { echo "ERROR: 'terraform' is missing. Aborting..."; exit 1; } # Resolve script directory and project root paths @@ -52,9 +51,6 @@ FRONTEND_DIR="$PROJECT_ROOT/frontend" INFRA_DIR="$PROJECT_ROOT/infra" ENVIRONMENT=${1:-"aws"} -# Select terraform command (terraform or tflocal) -TF_CMD="terraform" - # Set up PATH and AWS region export PATH="$HOME/.local/bin:$PATH" export AWS_REGION=${AWS_REGION:-us-east-1} @@ -76,24 +72,20 @@ if [ "$ENVIRONMENT" = "aws" ]; then fi else # Local development configuration - if command -v tflocal > /dev/null 2>&1; then - TF_CMD="tflocal" - else - # Fallback to terraform with local endpoint - export AWS_ENDPOINT_URL="http://localhost:4566" - fi + export AWS_ENDPOINT_URL="http://localhost:4566" + export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566" - # Set dummy AWS credentials for local development - export AWS_ACCESS_KEY_ID=test - export AWS_SECRET_ACCESS_KEY=test - AWS_ENDPOINT="--endpoint-url=http://localhost:4566" + BUCKET_NAME="coding-workshop-tfstate-${PARTICIPANT_ID:-abcd1234}" + if ! aws s3 ls | grep -q "$BUCKET_NAME"; then + aws s3 mb "s3://$BUCKET_NAME" + fi fi # Change to infrastructure directory cd "$INFRA_DIR" # Retrieve S3 bucket name from Terraform outputs -BUCKET_NAME=$($TF_CMD output -raw s3_bucket_name 2>/dev/null || echo "") +BUCKET_NAME=$(terraform output -raw s3_bucket_name 2>/dev/null || echo "") echo "INFO: Target bucket - $BUCKET_NAME" # Verify S3 bucket exists (indicates backend infrastructure is deployed) @@ -104,9 +96,9 @@ if [ -z "$BUCKET_NAME" ]; then fi # Retrieve API configuration from Terraform outputs -API_BASE_URL=$($TF_CMD output -raw api_base_url 2>/dev/null || echo "") +API_BASE_URL=$(terraform output -raw api_base_url 2>/dev/null || echo "") echo "INFO: API Base URL - $API_BASE_URL" -API_ENDPOINTS=$($TF_CMD output -json api_endpoints 2>/dev/null || echo "{}") +API_ENDPOINTS=$(terraform output -json api_endpoints 2>/dev/null || echo "{}") echo "INFO: API Endpoints - $API_ENDPOINTS" # Local Development: Skip frontend build (use start-dev.sh instead) @@ -165,7 +157,7 @@ if [ "$ENVIRONMENT" = "aws" ]; then cd "$INFRA_DIR" # Retrieve CloudFront distribution ID from Terraform outputs - DISTRIBUTION_ID=$($TF_CMD output -raw cloudfront_distribution_id 2>/dev/null || echo "") + DISTRIBUTION_ID=$(terraform output -raw cloudfront_distribution_id 2>/dev/null || echo "") # Create cache invalidation for all files if [ -n "$DISTRIBUTION_ID" ]; then @@ -180,7 +172,7 @@ echo "INFO: Frontend deployment complete!" # Display CloudFront URL cd "$INFRA_DIR" -URL=$($TF_CMD output -raw website_url 2>/dev/null || echo "") +URL=$(terraform output -raw website_url 2>/dev/null || echo "") if [ -n "$URL" ]; then echo "" diff --git a/bin/generate-env.sh b/bin/generate-env.sh index 38a3f5c..912bffb 100755 --- a/bin/generate-env.sh +++ b/bin/generate-env.sh @@ -18,7 +18,7 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo " -h, --help Show this help message" echo "" echo "Requirements:" - echo " - terraform or tflocal installed" + echo " - terraform installed" echo " - Backend infrastructure deployed" echo "" echo "Output:" diff --git a/bin/setup-environment.sh b/bin/setup-environment.sh index 07b697a..e0a01eb 100755 --- a/bin/setup-environment.sh +++ b/bin/setup-environment.sh @@ -12,7 +12,7 @@ # - Browser: Google Chrome # - Containers: Docker (with sudo-less access) # - Cloud Tools: Terraform CLI, AWS CLI v2 -# - LocalStack: LocalStack CLI, tflocal, awslocal +# - LocalStack: LocalStack CLI # - Database: PostgreSQL, pgAdmin # - Database: MongoDB, MongoDB Compass # - Runtimes: Node.js, Python @@ -93,7 +93,6 @@ Installed tools: - Terraform CLI - AWS CLI v2 - LocalStack CLI - - tflocal, awslocal - PostgreSQL with pgAdmin - MongoDB with MongoDB Compass - Node.js @@ -1272,65 +1271,6 @@ EOF fi } -install_tflocal() { - print_section "tflocal (terraform-local)" - - if is_dry_run; then - print_dry_run_header "TFLOCAL" "tflocal (terraform-local)" - if command -v tflocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/tflocal" ]; then - print_dry_run_status "Already installed" - else - print_dry_run_missing "Not installed" - print_dry_run_action "Would install: terraform-local (via pip3)" - print_dry_run_action "Would update PATH in ~/.bashrc" - fi - return - fi - - print_info "Installing tflocal..." - - # Idempotency check - if command -v tflocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/tflocal" ]; then - print_info "tflocal already installed" - return - fi - - if python3 -m pip install terraform-local; then - print_status "tflocal installed" - else - add_failure "Failed to install tflocal" - fi -} - -install_awslocal() { - print_section "awslocal (awscli-local)" - - if is_dry_run; then - print_dry_run_header "AWSLOCAL" "awslocal (awscli-local)" - if command -v awslocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/awslocal" ]; then - print_dry_run_status "Already installed" - else - print_dry_run_missing "Not installed" - print_dry_run_action "Would install: awscli-local (via pip3)" - fi - return - fi - - print_info "Installing awslocal..." - - # Idempotency check - if command -v awslocal &> /dev/null || [ -f "$ACTUAL_HOME/.local/bin/awslocal" ]; then - print_info "awslocal already installed" - return - fi - - if python3 -m pip install awscli-local; then - print_status "awslocal installed" - else - add_failure "Failed to install awslocal" - fi -} - # ============================================================================ # SECTION 13: DNSMASQ CONFIGURATION (OPTIONAL) # ============================================================================ @@ -1472,8 +1412,6 @@ run_verification() { # LocalStack verify_tool "LocalStack" "localstack --version" - verify_tool_path "tflocal" "$ACTUAL_HOME/.local/bin/tflocal" - verify_tool_path "awslocal" "$ACTUAL_HOME/.local/bin/awslocal" # Database verify_tool "MongoDB" "mongod --version" "grep 'db version'" @@ -1793,8 +1731,6 @@ main() { install_terraform install_awscli install_localstack - install_tflocal - install_awslocal configure_dnsmasq # Verification and summary diff --git a/bin/start-dev.sh b/bin/start-dev.sh index e48c9f0..518cc98 100755 --- a/bin/start-dev.sh +++ b/bin/start-dev.sh @@ -26,7 +26,6 @@ if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo " - mongod installed" echo " - npm installed" echo " - localstack installed" - echo " - tflocal installed" exit 0 fi @@ -43,6 +42,10 @@ PROJECT_ROOT="$(cd $SCRIPT_DIR/.. > /dev/null 2>&1 || exit 1; pwd -P)" INFRA_DIR="$PROJECT_ROOT/infra" FRONTEND_DIR="$PROJECT_ROOT/frontend" +# Ensure local development +export AWS_ENDPOINT_URL="http://localhost:4566" +export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566" + # ============================================================ # STEP 1: Check and Start PostgreSQL # ============================================================ @@ -300,13 +303,6 @@ echo "" # ============================================================ echo -e "[4/5] Checking Backend Infrastructure..." -# Verify required tools -if ! command -v tflocal &> /dev/null; then - echo -e "ERROR: tflocal is not installed" - echo "Install: pip install terraform-local" - exit 1 -fi - # Detect MongoDB host for LocalStack Lambda functions if [[ "$OSTYPE" == "linux-gnu"* ]]; then export TF_VAR_mongodb_host="172.17.0.1" @@ -327,9 +323,9 @@ rm -rf "$INFRA_DIR/builds" # Check if backend is deployed BACKEND_OK=false -if tflocal output lambda_urls > /dev/null 2>&1; then +if terraform output lambda_urls > /dev/null 2>&1; then # Backend is deployed, verify functions are accessible - LAMBDA_URLS=$(tflocal output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | head -1 || echo "") + LAMBDA_URLS=$(terraform output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | head -1 || echo "") if [ -n "$LAMBDA_URLS" ]; then # Test if at least one function responds @@ -357,7 +353,7 @@ fi # Display Lambda URLs echo -e " Lambda Function URLs:" -tflocal output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | sed 's/^/ /' || echo " (none)" +terraform output -json lambda_urls 2>/dev/null | grep -o 'http://[^"]*' | sed 's/^/ /' || echo " (none)" echo "" diff --git a/docs/testing.md b/docs/testing.md index f32e48e..eb84067 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -51,8 +51,9 @@ To tail backend logs in real-time: ```sh # Example: Get logs for {{service-name}} -awslocal logs tail /aws/lambda/{{function-name}} \ - --follow --format short --color on +AWS_ENDPOINT_URL="http://localhost:4566" \ + aws logs tail /aws/lambda/{{function-name}} \ + --follow --format short --color on ``` Replace `{{function-name}}` with corresponding service name diff --git a/infra/README.md b/infra/README.md index f75f67f..031fa8e 100644 --- a/infra/README.md +++ b/infra/README.md @@ -41,13 +41,20 @@ To run your application locally: localstack start -d ``` +Make sure that AWS APIs are accessible locally: + +```sh +export AWS_ENDPOINT_URL="http://localhost:4566" +export AWS_ENDPOINT_URL_S3="http://s3.localhost.localstack.cloud:4566" +``` + To deploy infrastructure locally: ```sh cd infra rm -rf .terraform* -tflocal init -backend-config bucket=coding-workshop-us-east-1-abcd1234 -tflocal apply -var aws_app_code=abcd1234 +terraform init -backend-config bucket=coding-workshop-us-east-1-abcd1234 +terraform apply -var aws_app_code=abcd1234 ``` **Note:** Replace `abcd1234` from above with your participant id shared by workshop organizer(s). @@ -55,7 +62,7 @@ tflocal apply -var aws_app_code=abcd1234 After successful execution, view outputs: ```sh -tflocal output +terraform output ``` ### Cloud Deployment @@ -66,6 +73,13 @@ To setup participant environment: ./bin/setup-participant.sh ``` +Make sure that AWS APIs are accessible remotely: + +```sh +unset AWS_ENDPOINT_URL +unset AWS_ENDPOINT_URL_S3 +``` + To deploy your infrastructure to AWS: ```sh