Skip to content

Commit

Permalink
fix scripts and destroy yml
Browse files Browse the repository at this point in the history
  • Loading branch information
FaithKovi committed Aug 3, 2024
1 parent c38e16f commit 86ba5b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:

- name: Terraform Destroy
working-directory: ./terraform
run: terraform destroy -auto-approve -var-file="terraform.tfvars"
run: |
terraform init
terraform destroy -auto-approve -var-file="terraform.tfvars"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
23 changes: 13 additions & 10 deletions terraform/scripts/s3_backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# Exit immediately if a command exits with a non-zero status
set -e

# create s3 bucket for terraform backend
aws s3api create-bucket --bucket terraform-state-bucket1232444231 --region us-east-1
# Define variables
BUCKET_NAME="terraform-state-bucket1232444231"
TABLE_NAME="resume-terraform-locks"
REGION="us-east-1"

# create dynamodb table for state lock
# Create S3 bucket for Terraform backend
echo "Creating S3 bucket $BUCKET_NAME in region $REGION"
aws s3api create-bucket --bucket "$BUCKET_NAME" --region "$REGION"

# Create DynamoDB table for state lock
echo "Creating DynamoDB table $TABLE_NAME in region $REGION"
aws dynamodb create-table \
--table-name resume-terraform-locks \
--table-name "$TABLE_NAME" \
--attribute-definitions AttributeName=LockID,AttributeType=S \
--key-schema AttributeName=LockID,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region us-east-1


exit 0


--region "$REGION"

echo "Resources created successfully."
12 changes: 9 additions & 3 deletions terraform/scripts/upload_to_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
# Exit immediately if a command exits with a non-zero status
set -e

# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <bucket_name> <lambda_s3_key> <lambda_zip_path>"
exit 1
fi

BUCKET_NAME=$1
LAMBDA_S3_KEY=$2
LAMBDA_ZIP_PATH=$3

# upload lambda function to s3
echo "Uploading lambda_function.zip to s3"
aws s3 cp $LAMBDA_ZIP_PATH s3://$BUCKET_NAME/$LAMBDA_S3_KEY
# Upload Lambda function to S3
echo "Uploading $LAMBDA_ZIP_PATH to s3://$BUCKET_NAME/$LAMBDA_S3_KEY"
aws s3 cp "$LAMBDA_ZIP_PATH" "s3://$BUCKET_NAME/$LAMBDA_S3_KEY"

0 comments on commit 86ba5b4

Please sign in to comment.