From e948f528eec7e4cf66d6a7ba2933ae158a8e3ed6 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Thu, 15 May 2025 23:31:42 -0400 Subject: [PATCH 01/10] added terraform files --- terraform/backend.tf | 7 +++++++ terraform/elastic_beanstalk.tf | 22 ++++++++++++++++++++++ terraform/provider.tf | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 terraform/backend.tf create mode 100644 terraform/elastic_beanstalk.tf create mode 100644 terraform/provider.tf diff --git a/terraform/backend.tf b/terraform/backend.tf new file mode 100644 index 0000000..ce0b354 --- /dev/null +++ b/terraform/backend.tf @@ -0,0 +1,7 @@ +terraform { + backend "s3" { + bucket = "terraform-state-fastapi" + key = "fastapi/terraform.tfstate" + region = "us-east-1" + } +} diff --git a/terraform/elastic_beanstalk.tf b/terraform/elastic_beanstalk.tf new file mode 100644 index 0000000..2db5189 --- /dev/null +++ b/terraform/elastic_beanstalk.tf @@ -0,0 +1,22 @@ +resource "aws_elastic_beanstalk_application" "application" { + name = "fastapi-backend" +} + +resource "aws_elastic_beanstalk_environment" "environment" { + name = "fastapi-env" + cname_prefix = "arihantfastapi" + application = aws_elastic_beanstalk_application.application.name + solution_stack_name = "64bit Amazon Linux 2023 v4.0.1 running Python 3.11" + + setting { + namespace = "aws:autoscaling:launchconfiguration" + name = "IamInstanceProfile" + value = "aws-elasticbeanstalk-ec2-role" + } + + setting { + namespace = "aws:elasticbeanstalk:container:python" + name = "WSGIPath" + value = "main:app" + } +} diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..cee7b7e --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-east-1" +} From 18957bdb8e81926f19f6ab66cb5f1f6ae6b2b11b Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 13:41:08 -0400 Subject: [PATCH 02/10] working terraform configurations --- terraform/.terraform.lock.hcl | 24 +++++++++++ terraform/.terraform/terraform.tfstate | 55 ++++++++++++++++++++++++++ terraform/backend.tf | 2 +- terraform/elastic_beanstalk.tf | 6 +-- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 terraform/.terraform.lock.hcl create mode 100644 terraform/.terraform/terraform.tfstate diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..f95e4b3 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.98.0" + hashes = [ + "h1:/RMObGCrfJlVoQCf9h88hFkSyLafDXnw6r0yi4gpO80=", + "zh:23377bd90204b6203b904f48f53edcae3294eb072d8fc18a4531c0cde531a3a1", + "zh:2e55a6ea14cc43b08cf82d43063e96c5c2f58ee953c2628523d0ee918fe3b609", + "zh:4885a817c16fdaaeddc5031edc9594c1f300db0e5b23be7cd76a473e7dcc7b4f", + "zh:6ca7177ad4e5c9d93dee4be1ac0792b37107df04657fddfe0c976f36abdd18b5", + "zh:78bf8eb0a67bae5dede09666676c7a38c9fb8d1b80a90ba06cf36ae268257d6f", + "zh:874b5a99457a3f88e2915df8773120846b63d820868a8f43082193f3dc84adcb", + "zh:95e1e4cf587cde4537ac9dfee9e94270652c812ab31fce3a431778c053abf354", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a75145b58b241d64570803e6565c72467cd664633df32678755b51871f553e50", + "zh:aa31b13d0b0e8432940d6892a48b6268721fa54a02ed62ee42745186ee32f58d", + "zh:ae4565770f76672ce8e96528cbb66afdade1f91383123c079c7fdeafcb3d2877", + "zh:b99f042c45bf6aa69dd73f3f6d9cbe0b495b30442c526e0b3810089c059ba724", + "zh:bbb38e86d926ef101cefafe8fe090c57f2b1356eac9fc5ec81af310c50375897", + "zh:d03c89988ba4a0bd3cfc8659f951183ae7027aa8018a7ca1e53a300944af59cb", + "zh:d179ef28843fe663fc63169291a211898199009f0d3f63f0a6f65349e77727ec", + ] +} diff --git a/terraform/.terraform/terraform.tfstate b/terraform/.terraform/terraform.tfstate new file mode 100644 index 0000000..3cfcb20 --- /dev/null +++ b/terraform/.terraform/terraform.tfstate @@ -0,0 +1,55 @@ +{ + "version": 3, + "terraform_version": "1.12.0", + "backend": { + "type": "s3", + "config": { + "access_key": null, + "acl": null, + "allowed_account_ids": null, + "assume_role": null, + "assume_role_with_web_identity": null, + "bucket": "terraform-state-chefit-notprowler", + "custom_ca_bundle": null, + "dynamodb_endpoint": null, + "dynamodb_table": null, + "ec2_metadata_service_endpoint": null, + "ec2_metadata_service_endpoint_mode": null, + "encrypt": null, + "endpoint": null, + "endpoints": null, + "forbidden_account_ids": null, + "force_path_style": null, + "http_proxy": null, + "https_proxy": null, + "iam_endpoint": null, + "insecure": null, + "key": "fastapi/terraform.tfstate", + "kms_key_id": null, + "max_retries": null, + "no_proxy": null, + "profile": null, + "region": "us-east-1", + "retry_mode": null, + "secret_key": null, + "shared_config_files": null, + "shared_credentials_file": null, + "shared_credentials_files": null, + "skip_credentials_validation": null, + "skip_metadata_api_check": null, + "skip_region_validation": null, + "skip_requesting_account_id": null, + "skip_s3_checksum": null, + "sse_customer_key": null, + "sts_endpoint": null, + "sts_region": null, + "token": null, + "use_dualstack_endpoint": null, + "use_fips_endpoint": null, + "use_lockfile": null, + "use_path_style": null, + "workspace_key_prefix": null + }, + "hash": 1465801253 + } +} \ No newline at end of file diff --git a/terraform/backend.tf b/terraform/backend.tf index ce0b354..54a383f 100644 --- a/terraform/backend.tf +++ b/terraform/backend.tf @@ -1,6 +1,6 @@ terraform { backend "s3" { - bucket = "terraform-state-fastapi" + bucket = "terraform-state-chefit-notprowler" key = "fastapi/terraform.tfstate" region = "us-east-1" } diff --git a/terraform/elastic_beanstalk.tf b/terraform/elastic_beanstalk.tf index 2db5189..d8a1055 100644 --- a/terraform/elastic_beanstalk.tf +++ b/terraform/elastic_beanstalk.tf @@ -1,12 +1,12 @@ resource "aws_elastic_beanstalk_application" "application" { - name = "fastapi-backend" + name = "chefit-backend" } resource "aws_elastic_beanstalk_environment" "environment" { name = "fastapi-env" - cname_prefix = "arihantfastapi" + cname_prefix = "notprowlerfastapi" application = aws_elastic_beanstalk_application.application.name - solution_stack_name = "64bit Amazon Linux 2023 v4.0.1 running Python 3.11" + solution_stack_name = "64bit Amazon Linux 2023 v4.5.1 running Python 3.11" setting { namespace = "aws:autoscaling:launchconfiguration" From 47a82b7824b7786c1f69f8da01c1f319dfdf5eba Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:02:16 -0400 Subject: [PATCH 03/10] terraform infra workflow --- .github/workflows/terraform.yml | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/terraform.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 0000000..542e3e5 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,88 @@ +# This workflow will provision the infrastructure necessary to deploy. + +name: terraform + +on: + push: + branches: [ main ] + paths: + - 'terraform/*' + - '.github/workflows/terraform.yml' + pull_request: + branches: [ main ] + paths: + - 'terraform/*' + - '.github/workflows/terraform.yml' +jobs: + format: + permissions: + contents: write + runs-on: ubuntu-latest + + name: Format + + steps: + # Clone the repository. + - uses: actions/checkout@v4 + with: + # This is required or we end up in detached head state & thus cannot push any changes. + ref: ${{ github.head_ref }} + # Download & set up the terraform CLI. + - name: Set up terraform CLI + uses: hashicorp/setup-terraform@v3 + + - run: terraform fmt -check + working-directory: ./terraform + id: fmt + continue-on-error: ${{ github.event_name == 'pull_request' }} + + - name: update pr + if: ${{ steps.fmt.outcome == 'failure' && github.event_name == 'pull_request' }} + run: | + terraform fmt + git config --global user.name "terraform-fmt" + git config --global user.email "noreply@corise.com" + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git commit -am "fixup: terraform fmt" + git push + working-directory: ./terraform + terraform: + + runs-on: ubuntu-latest + + name: Validate, Plan, and Apply + env: + AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + + steps: + - uses: actions/checkout@v4 + # Download & set up the terraform CLI. + - name: Set up terraform CLI + uses: hashicorp/setup-terraform@v3 + # Initialize terraform. + - name: terraform init + working-directory: ./terraform + id: init + run: terraform init -input=false + - name: terraform validate + working-directory: ./terraform + if: ${{ github.event_name == 'pull_request' }} + run: terraform validate -no-color + - name: terraform plan + working-directory: ./terraform + id: plan + if: ${{ github.event_name == 'pull_request' }} + run: terraform plan -no-color -input=false + continue-on-error: true + - name: pass or fail + uses: actions/github-script@v6 + if: ${{ steps.plan.outcome == 'failure' }} + with: + script: | + core.setFailed('Plan failed!') + - name: terraform apply + id: apply + working-directory: ./terraform + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + run: terraform apply -auto-approve -input=false \ No newline at end of file From b687c429fb30b27966ed7046c9173236c2d84dba Mon Sep 17 00:00:00 2001 From: terraform-fmt Date: Sat, 17 May 2025 18:02:34 +0000 Subject: [PATCH 04/10] fixup: terraform fmt --- terraform/provider.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/provider.tf b/terraform/provider.tf index cee7b7e..c125940 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "us-east-1" + region = "us-east-1" } From db52f4ef1564e9fc4237b223e906693e2081c0f9 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:36:50 -0400 Subject: [PATCH 05/10] deployment files --- .github/workflows/deploy_aws.yml | 54 ++++++++++++++++++++++++++++++++ deploy.sh | 12 +++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/deploy_aws.yml create mode 100644 deploy.sh diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml new file mode 100644 index 0000000..21a11c8 --- /dev/null +++ b/.github/workflows/deploy_aws.yml @@ -0,0 +1,54 @@ +name: deploy-fastapi + +on: + push: + branches: [main] + paths: + - 'app/**' + - '.github/workflows/deploy_aws.yml' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install dependencies + run: | + pip install -r app/requirements.txt + + - name: Zip application + run: | + cd app + zip -r ../fastapi_deploy_${{ github.sha }}.zip . + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Upload to S3 + run: | + aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://your-bucket-name/fastapi/fastapi_deploy_${{ github.sha }}.zip + + - name: Create new application version + run: | + aws elasticbeanstalk create-application-version \ + --application-name chefit-backend \ + --source-bundle S3Bucket="terraform-state-chefit-notprowler",S3Key=fastapi/fastapi_deploy_${{ github.sha }}.zip \ + --version-label "ver-${{ github.sha }}" \ + --description "FastAPI deploy at commit ${{ github.sha }}" + + - name: Deploy to environment + run: | + aws elasticbeanstalk update-environment \ + --environment-name fastapi-env \ + --version-label "ver-${{ github.sha }}" \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..a77c83f --- /dev/null +++ b/deploy.sh @@ -0,0 +1,12 @@ +zip -r "chefit-backend-$1.zip" ./backend + +aws s3 cp "flaskbb_deploy-$1.zip" s3://flaskbbapp + +aws elasticbeanstalk create-application-version \ + --application-name chefit-backend \ + --version-label "ver-$1" \ + --source-bundle S3Bucket=terraform-state-chefit-notprowler,S3Key=fastapi/fastapi-app.zip + + aws elasticbeanstalk update-environment \ + --environment-name fastapi-env \ + --version-label "ver-$1" From 3a76445be7d9bbd572cd64dc78e2df9053f3b01f Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:44:45 -0400 Subject: [PATCH 06/10] Update deploy_aws.yml --- .github/workflows/deploy_aws.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml index 21a11c8..9320e7d 100644 --- a/.github/workflows/deploy_aws.yml +++ b/.github/workflows/deploy_aws.yml @@ -4,7 +4,14 @@ on: push: branches: [main] paths: - - 'app/**' + - 'backend/**' + - '.github/workflows/deploy_aws.yml' + + pull_request: + branches: [main] + types: [closed] + paths: + - 'backend/**' - '.github/workflows/deploy_aws.yml' jobs: @@ -21,23 +28,23 @@ jobs: - name: Install dependencies run: | - pip install -r app/requirements.txt + pip install -r backend/requirements.txt - name: Zip application run: | cd app - zip -r ../fastapi_deploy_${{ github.sha }}.zip . + zip -r fastapi_deploy_${{ github.sha }}.zip backend -x "*/__pycache__/*" "*.pyc" - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v2 with: - aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} + aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }} aws-region: us-east-1 - name: Upload to S3 run: | - aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://your-bucket-name/fastapi/fastapi_deploy_${{ github.sha }}.zip + aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://terraform-state-chefit-notprowler/fastapi/fastapi_deploy_${{ github.sha }}.zip - name: Create new application version run: | From acfede2b5fba5face404ba5db16985cb7728ec9d Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:47:16 -0400 Subject: [PATCH 07/10] Update deploy_aws.yml --- .github/workflows/deploy_aws.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml index 9320e7d..aeb442c 100644 --- a/.github/workflows/deploy_aws.yml +++ b/.github/workflows/deploy_aws.yml @@ -1,18 +1,9 @@ name: deploy-fastapi on: - push: - branches: [main] - paths: - - 'backend/**' - - '.github/workflows/deploy_aws.yml' - pull_request: - branches: [main] - types: [closed] - paths: - - 'backend/**' - - '.github/workflows/deploy_aws.yml' + branches: + - main jobs: deploy: From a27b6157861f529bd90a06cd65825023589ea577 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:49:17 -0400 Subject: [PATCH 08/10] Update deploy_aws.yml --- .github/workflows/deploy_aws.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml index aeb442c..e90494f 100644 --- a/.github/workflows/deploy_aws.yml +++ b/.github/workflows/deploy_aws.yml @@ -23,7 +23,6 @@ jobs: - name: Zip application run: | - cd app zip -r fastapi_deploy_${{ github.sha }}.zip backend -x "*/__pycache__/*" "*.pyc" - name: Configure AWS credentials From a0a76eb478a20708d8daed68097a86ac9dde5d61 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sat, 17 May 2025 14:58:21 -0400 Subject: [PATCH 09/10] Update terraform.yml --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 542e3e5..1af49e2 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -84,5 +84,5 @@ jobs: - name: terraform apply id: apply working-directory: ./terraform - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - run: terraform apply -auto-approve -input=false \ No newline at end of file + if: github.event_name == 'pull_request' + run: terraform apply -auto-approve -input=false From 581eab269773b13bc1b5b12618334c422e63f929 Mon Sep 17 00:00:00 2001 From: Arihant Tiwari Date: Sun, 1 Jun 2025 21:50:48 -0400 Subject: [PATCH 10/10] AWS charged me $10, commenting out for safety --- .github/workflows/deploy_aws.yml | 102 ++++++++++---------- .github/workflows/terraform.yml | 158 +++++++++++++++---------------- terraform/elastic_beanstalk.tf | 38 ++++---- 3 files changed, 149 insertions(+), 149 deletions(-) diff --git a/.github/workflows/deploy_aws.yml b/.github/workflows/deploy_aws.yml index e90494f..7e531f2 100644 --- a/.github/workflows/deploy_aws.yml +++ b/.github/workflows/deploy_aws.yml @@ -1,51 +1,51 @@ -name: deploy-fastapi - -on: - pull_request: - branches: - - main - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - - name: Install dependencies - run: | - pip install -r backend/requirements.txt - - - name: Zip application - run: | - zip -r fastapi_deploy_${{ github.sha }}.zip backend -x "*/__pycache__/*" "*.pyc" - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Upload to S3 - run: | - aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://terraform-state-chefit-notprowler/fastapi/fastapi_deploy_${{ github.sha }}.zip - - - name: Create new application version - run: | - aws elasticbeanstalk create-application-version \ - --application-name chefit-backend \ - --source-bundle S3Bucket="terraform-state-chefit-notprowler",S3Key=fastapi/fastapi_deploy_${{ github.sha }}.zip \ - --version-label "ver-${{ github.sha }}" \ - --description "FastAPI deploy at commit ${{ github.sha }}" - - - name: Deploy to environment - run: | - aws elasticbeanstalk update-environment \ - --environment-name fastapi-env \ - --version-label "ver-${{ github.sha }}" \ No newline at end of file +# name: deploy-fastapi + +# on: +# pull_request: +# branches: +# - main + +# jobs: +# deploy: +# runs-on: ubuntu-latest +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 + +# - name: Set up Python +# uses: actions/setup-python@v4 +# with: +# python-version: 3.11 + +# - name: Install dependencies +# run: | +# pip install -r backend/requirements.txt + +# - name: Zip application +# run: | +# zip -r fastapi_deploy_${{ github.sha }}.zip backend -x "*/__pycache__/*" "*.pyc" + +# - name: Configure AWS credentials +# uses: aws-actions/configure-aws-credentials@v2 +# with: +# aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }} +# aws-region: us-east-1 + +# - name: Upload to S3 +# run: | +# aws s3 cp fastapi_deploy_${{ github.sha }}.zip s3://terraform-state-chefit-notprowler/fastapi/fastapi_deploy_${{ github.sha }}.zip + +# - name: Create new application version +# run: | +# aws elasticbeanstalk create-application-version \ +# --application-name chefit-backend \ +# --source-bundle S3Bucket="terraform-state-chefit-notprowler",S3Key=fastapi/fastapi_deploy_${{ github.sha }}.zip \ +# --version-label "ver-${{ github.sha }}" \ +# --description "FastAPI deploy at commit ${{ github.sha }}" + +# - name: Deploy to environment +# run: | +# aws elasticbeanstalk update-environment \ +# --environment-name fastapi-env \ +# --version-label "ver-${{ github.sha }}" \ No newline at end of file diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 1af49e2..ca8b3a6 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,88 +1,88 @@ -# This workflow will provision the infrastructure necessary to deploy. +# # This workflow will provision the infrastructure necessary to deploy. -name: terraform +# name: terraform -on: - push: - branches: [ main ] - paths: - - 'terraform/*' - - '.github/workflows/terraform.yml' - pull_request: - branches: [ main ] - paths: - - 'terraform/*' - - '.github/workflows/terraform.yml' -jobs: - format: - permissions: - contents: write - runs-on: ubuntu-latest +# on: +# push: +# branches: [ main ] +# paths: +# - 'terraform/*' +# - '.github/workflows/terraform.yml' +# pull_request: +# branches: [ main ] +# paths: +# - 'terraform/*' +# - '.github/workflows/terraform.yml' +# jobs: +# format: +# permissions: +# contents: write +# runs-on: ubuntu-latest - name: Format +# name: Format - steps: - # Clone the repository. - - uses: actions/checkout@v4 - with: - # This is required or we end up in detached head state & thus cannot push any changes. - ref: ${{ github.head_ref }} - # Download & set up the terraform CLI. - - name: Set up terraform CLI - uses: hashicorp/setup-terraform@v3 +# steps: +# # Clone the repository. +# - uses: actions/checkout@v4 +# with: +# # This is required or we end up in detached head state & thus cannot push any changes. +# ref: ${{ github.head_ref }} +# # Download & set up the terraform CLI. +# - name: Set up terraform CLI +# uses: hashicorp/setup-terraform@v3 - - run: terraform fmt -check - working-directory: ./terraform - id: fmt - continue-on-error: ${{ github.event_name == 'pull_request' }} +# - run: terraform fmt -check +# working-directory: ./terraform +# id: fmt +# continue-on-error: ${{ github.event_name == 'pull_request' }} - - name: update pr - if: ${{ steps.fmt.outcome == 'failure' && github.event_name == 'pull_request' }} - run: | - terraform fmt - git config --global user.name "terraform-fmt" - git config --global user.email "noreply@corise.com" - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git commit -am "fixup: terraform fmt" - git push - working-directory: ./terraform - terraform: +# - name: update pr +# if: ${{ steps.fmt.outcome == 'failure' && github.event_name == 'pull_request' }} +# run: | +# terraform fmt +# git config --global user.name "terraform-fmt" +# git config --global user.email "noreply@corise.com" +# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY +# git commit -am "fixup: terraform fmt" +# git push +# working-directory: ./terraform +# terraform: - runs-on: ubuntu-latest +# runs-on: ubuntu-latest - name: Validate, Plan, and Apply - env: - AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} +# name: Validate, Plan, and Apply +# env: +# AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} +# AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} - steps: - - uses: actions/checkout@v4 - # Download & set up the terraform CLI. - - name: Set up terraform CLI - uses: hashicorp/setup-terraform@v3 - # Initialize terraform. - - name: terraform init - working-directory: ./terraform - id: init - run: terraform init -input=false - - name: terraform validate - working-directory: ./terraform - if: ${{ github.event_name == 'pull_request' }} - run: terraform validate -no-color - - name: terraform plan - working-directory: ./terraform - id: plan - if: ${{ github.event_name == 'pull_request' }} - run: terraform plan -no-color -input=false - continue-on-error: true - - name: pass or fail - uses: actions/github-script@v6 - if: ${{ steps.plan.outcome == 'failure' }} - with: - script: | - core.setFailed('Plan failed!') - - name: terraform apply - id: apply - working-directory: ./terraform - if: github.event_name == 'pull_request' - run: terraform apply -auto-approve -input=false +# steps: +# - uses: actions/checkout@v4 +# # Download & set up the terraform CLI. +# - name: Set up terraform CLI +# uses: hashicorp/setup-terraform@v3 +# # Initialize terraform. +# - name: terraform init +# working-directory: ./terraform +# id: init +# run: terraform init -input=false +# - name: terraform validate +# working-directory: ./terraform +# if: ${{ github.event_name == 'pull_request' }} +# run: terraform validate -no-color +# - name: terraform plan +# working-directory: ./terraform +# id: plan +# if: ${{ github.event_name == 'pull_request' }} +# run: terraform plan -no-color -input=false +# continue-on-error: true +# - name: pass or fail +# uses: actions/github-script@v6 +# if: ${{ steps.plan.outcome == 'failure' }} +# with: +# script: | +# core.setFailed('Plan failed!') +# - name: terraform apply +# id: apply +# working-directory: ./terraform +# if: github.event_name == 'pull_request' +# run: terraform apply -auto-approve -input=false diff --git a/terraform/elastic_beanstalk.tf b/terraform/elastic_beanstalk.tf index d8a1055..f374418 100644 --- a/terraform/elastic_beanstalk.tf +++ b/terraform/elastic_beanstalk.tf @@ -1,22 +1,22 @@ -resource "aws_elastic_beanstalk_application" "application" { - name = "chefit-backend" -} +# resource "aws_elastic_beanstalk_application" "application" { +# name = "chefit-backend" +# } -resource "aws_elastic_beanstalk_environment" "environment" { - name = "fastapi-env" - cname_prefix = "notprowlerfastapi" - application = aws_elastic_beanstalk_application.application.name - solution_stack_name = "64bit Amazon Linux 2023 v4.5.1 running Python 3.11" +# resource "aws_elastic_beanstalk_environment" "environment" { +# name = "fastapi-env" +# cname_prefix = "notprowlerfastapi" +# application = aws_elastic_beanstalk_application.application.name +# solution_stack_name = "64bit Amazon Linux 2023 v4.5.1 running Python 3.11" - setting { - namespace = "aws:autoscaling:launchconfiguration" - name = "IamInstanceProfile" - value = "aws-elasticbeanstalk-ec2-role" - } +# setting { +# namespace = "aws:autoscaling:launchconfiguration" +# name = "IamInstanceProfile" +# value = "aws-elasticbeanstalk-ec2-role" +# } - setting { - namespace = "aws:elasticbeanstalk:container:python" - name = "WSGIPath" - value = "main:app" - } -} +# setting { +# namespace = "aws:elasticbeanstalk:container:python" +# name = "WSGIPath" +# value = "main:app" +# } +# }