Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from Locomotive-Ventures/parameterize-cloudfor…
Browse files Browse the repository at this point in the history
…mation-stack

chore: Rename parameters where required
  • Loading branch information
vincentkoc authored Nov 25, 2023
2 parents ce06447 + e706242 commit d5dd441
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/deploy_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,51 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: 'ap-southeast-2'

# Check if CloudFormation stack already exists
- name: Check if CloudFormation stack exists
id: check-stack
run: |
stack_status=$(aws cloudformation describe-stacks --stack-name wombat-stack --query 'Stacks[0].StackStatus' --output text 2>/dev/null || echo "STACK_NOT_FOUND")
echo "Stack Status: $stack_status"
if [ "$stack_status" != "STACK_NOT_FOUND" ]; then
echo "::set-output name=stack_exists::true"
else
echo "::set-output name=stack_exists::false"
fi
# If CF stack exists, delete stack
- name: Delete CloudFormation stack
if: steps.check-stack.outputs.stack_exists == 'true'
run: |
aws cloudformation delete-stack --stack-name wombat-stack
aws cloudformation wait stack-delete-complete --stack-name wombat-stack
# Create new CloudFormation stack
- name: Create CloudFormation Stack
run: |
aws cloudformation create-stack \
--stack-name wombat-stack \
--template-url https://cf-templates-1h5bilay8ris2-ap-southeast-2.s3.ap-southeast-2.amazonaws.com/wombat-stack.yml \
--capabilities CAPABILITY_IAM
# Get S3 Website URI
- name: Get S3 Website name
run: |
set -x
website_bucket_name=$(aws cloudformation describe-stacks \
--stack-name wombat-stack \
--query 'Stacks[0].Outputs[3].OutputValue' \
--output text)
echo "S3 website name exported from CF template: $website_bucket_name"
# Set the output value as an environment variable
echo "CF_BUCKET_NAME=$website_bucket_name" >> $GITHUB_ENV
# Deploy frontend to s3 bucket using AWS CLI
- name: Deploy to S3
run: |
aws s3 sync ./frontend/ s3://wombat-warden-s3-static-website/ --delete
aws s3 sync ./frontend/ s3://{$GITHUB_ENV}/ --delete
12 changes: 6 additions & 6 deletions infrastructure/cloudformation/wombat-stack.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: Testing resourses excluding the Caller part
Description: Testing resources excluding the Caller part

Parameters:
QueueName:
Type: String
Description: The name of the SQS queue
Default: contact-queue
Default: wombat-contact-queue

Resources:
WebsiteBucket:
Expand Down Expand Up @@ -36,14 +36,14 @@ Resources:
Properties:
DistributionConfig:
Origins:
- Id: myS3Origin
- Id: wombat-s3-origin
DomainName: !GetAtt [WebsiteBucket, DomainName]
S3OriginConfig:
OriginAccessIdentity: ''
OriginAccessControlId: !GetAtt CloudFrontOriginAccessControl.Id
Enabled: true
DefaultCacheBehavior:
TargetOriginId: myS3Origin
TargetOriginId: wombat-s3-origin
ViewerProtocolPolicy: redirect-to-https
ForwardedValues:
QueryString: false
Expand Down Expand Up @@ -89,7 +89,7 @@ Resources:
ContactTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: 'contact-table'
TableName: 'wombat-contact-table'
AttributeDefinitions:
- AttributeName: uniqueId
AttributeType: S
Expand Down Expand Up @@ -194,7 +194,7 @@ Resources:
ContactAPI:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: 'ContactAPI'
Name: 'WombatContactAPI'

ContactAPIResource:
Type: 'AWS::ApiGateway::Resource'
Expand Down

0 comments on commit d5dd441

Please sign in to comment.