Skip to content

Commit

Permalink
Merge pull request ine-labs#12 from SSKale1/master
Browse files Browse the repository at this point in the history
Bug Fixes and Handling Repeated Deployment
  • Loading branch information
jeswinMathai authored Aug 14, 2022
2 parents bdf1e80 + fbf170c commit 57f7385
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 165 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/tf-apply-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set Account ID
id: account
run: |
echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)"
- name: Check previous AWSGoat Deployment
id: check
run: |
echo $ACCOUNT_ID
aws s3api head-object --bucket do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }} --key terraform.tfstate
continue-on-error: true

- name: Exit if previous deployment exists
if: steps.check.outcome == 'success'
run: |
echo "A Previous AWSGoat deployment exists, run the Terraform Destroy Action"
exit 1
# Initialize a new or existing Terraform working directory
- name: Terraform Init
run: |
Expand All @@ -37,14 +55,15 @@ jobs:
pip install boto3
- name: Terraform Plan
id: plan
run: |
terraform plan -input=false
ls -al
continue-on-error: false

- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: "exit 1"
run: exit 1

- name: Terraform Apply
run: |
Expand All @@ -54,8 +73,9 @@ jobs:

# Copy tfstate file to s3 bucket
- name: Copy terraform.tfstate file to s3bucket
if: always()
run: |
aws s3 cp ./terraform.tfstate s3://do-not-delete-awsgoat-state-files-${{secrets.AWS_ACCOUNT_ID}}/terraform.tfstate
aws s3 cp ./terraform.tfstate s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate
# Terraform Output the API Gateway url
- name: Application URL
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tf-destroy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set Account ID
id: account
run: |
echo "::set-output name=ACCOUNT_ID::$(aws sts get-caller-identity --query Account --output text)"
# Copy and delete terraform.tfstate files from s3 bucket
- name: Retrieve tfstate
run: |
aws s3 cp s3://do-not-delete-awsgoat-state-files-${{secrets.AWS_ACCOUNT_ID}}/terraform.tfstate ./terraform.tfstate
aws s3 cp s3://do-not-delete-awsgoat-state-files-${{ steps.account.outputs.ACCOUNT_ID }}/terraform.tfstate ./terraform.tfstate
# Initialize a new Terraform working directory
- name: Terraform Init
run: terraform init


- name: Terraform Destroy
run: terraform destroy -auto-approve -input=false
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ Here are the steps to follow:

```
AWS_ACCESS_KEY
AWS_ACCOUNT_ID
AWS_SECRET_ACCESS_KEY
```

![2](https://user-images.githubusercontent.com/65826354/179526772-16e84787-3ac9-4fd2-b57c-0c794dad5e4f.png)
![2](https://user-images.githubusercontent.com/65826354/184551000-29f59b56-cbcc-4daf-9dad-a40e35bd6e02.png)

**Step 3.** From the repository actions tab, run the ``Terraform Apply`` Workflow.

![3](https://user-images.githubusercontent.com/65826354/179526776-f03918c2-d944-4480-a098-f9483156b570.png)

**Step 4.** Find the application URL in the Terraform output section.

![4](https://user-images.githubusercontent.com/65826354/179526780-b01d5c3f-9968-45e9-b698-a9b1905b32b9.png)
![4](https://user-images.githubusercontent.com/65826354/184553744-c1ba94a1-0d67-4a86-b97d-ee7afe6c65fe.png)


### Manual Installation
Expand Down
Loading

0 comments on commit 57f7385

Please sign in to comment.