diff --git a/.github/workflows/destroy.yml b/.github/workflows/destroy.yml index 4065060..f0b5446 100644 --- a/.github/workflows/destroy.yml +++ b/.github/workflows/destroy.yml @@ -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 }} diff --git a/terraform/scripts/s3_backend.sh b/terraform/scripts/s3_backend.sh index 9a880ae..275bfba 100755 --- a/terraform/scripts/s3_backend.sh +++ b/terraform/scripts/s3_backend.sh @@ -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." \ No newline at end of file diff --git a/terraform/scripts/upload_to_s3.sh b/terraform/scripts/upload_to_s3.sh index d7e9947..eab707b 100755 --- a/terraform/scripts/upload_to_s3.sh +++ b/terraform/scripts/upload_to_s3.sh @@ -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 " + 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" \ No newline at end of file