Skip to content

Commit 8bc1e51

Browse files
authored
feat: 🚀 Created cloudformation workflow and its readme (#90)
1 parent 6b14cb1 commit 8bc1e51

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
name: "Deploy CloudFormation Stack"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
s3-bucket:
8+
description: 'Add bucket name'
9+
required: true
10+
type: string
11+
bucket-prefix:
12+
description: 'bucket folder name'
13+
required: true
14+
type: string
15+
aws-region:
16+
description: 'AWS REGION'
17+
required: false
18+
default: 'us-east-1'
19+
type: string
20+
stack-name:
21+
description: 'Stack name defined'
22+
required: true
23+
type: string
24+
template-path:
25+
description: 'Cloudformation template path add here'
26+
required: true
27+
type: string
28+
organization-name:
29+
description: ' GitHub organization name'
30+
required: true
31+
type: string
32+
GitHub-repo-name:
33+
description: ' GitHub repo name'
34+
required: true
35+
type: string
36+
GitHub-branch:
37+
description: 'GitHub branch name'
38+
required: true
39+
default: 'main'
40+
type: string
41+
code-folder:
42+
description: 'Code folder where your lambda code stored ex-src(format-.ts/.py)'
43+
required: false
44+
default: 'src'
45+
type: string
46+
zip-file-name:
47+
description: 'Name of zip file which converted into zip & adding into S3 bucket'
48+
required: true
49+
default: 'main.zip'
50+
type: string
51+
parameter-overrides:
52+
description: 'The parameters to override in the stack inputs. You can pass a comma-delimited list or a file URL. The comma-delimited list has each entry formatted as <ParameterName>=<ParameterValue> or <ParameterName>="<ParameterValue>,<ParameterValue>".'
53+
required: false
54+
type: string
55+
secrets:
56+
AWS_ACCESS_KEY_ID:
57+
required: false
58+
description: 'AWS Access Key ID to install AWS CLI.'
59+
AWS_SECRET_ACCESS_KEY:
60+
required: false
61+
description: 'AWS Secret access key to install AWS CLI'
62+
AWS_SESSION_TOKEN:
63+
required: false
64+
description: 'AWS Session Token to install AWS CLI'
65+
ROLE-TO-ASSUME:
66+
required: false
67+
description: 'AWS Role ARN defined'
68+
GITHUB:
69+
required: false
70+
description: 'GitHub token'
71+
72+
jobs:
73+
deploy-cf-stack:
74+
runs-on: ubuntu-latest
75+
76+
steps:
77+
- name: Checkout code from master branch
78+
uses: actions/checkout@v2
79+
80+
- name: Checkout code from another Repo
81+
uses: actions/checkout@v4
82+
with:
83+
repository: ${{ inputs.organization-name }}/${{ inputs.GitHub-repo-name }}
84+
ref: ${{ inputs.GitHub-branch }}
85+
token: ${{ secrets.GITHUB }}
86+
path: ${{ inputs.GitHub-repo-name }}
87+
88+
- name: Configure AWS Credentials
89+
uses: aws-actions/configure-aws-credentials@v4
90+
with:
91+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}}
92+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
93+
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
94+
aws-region: ${{ inputs.aws-region }}
95+
role-to-assume: ${{ inputs.ROLE-TO-ASSUME }}
96+
97+
- name: Src folder code convert into zip and upload to S3
98+
run: |
99+
cd ${{ inputs.GitHub-repo-name }}/${{ inputs.code-folder }}
100+
find . -maxdepth 1 -type f -exec zip ${{inputs.zip-file-name}} {} +
101+
run: |
102+
aws s3 cp ${{inputs.zip-file-name}} s3://${{ inputs.s3-bucket }}/${{ inputs.bucket-prefix }}/
103+
104+
- name: Deploy cloudformation stack using template
105+
uses: aws-actions/aws-cloudformation-github-deploy@v1
106+
with:
107+
name: ${{ inputs.stack-name }}
108+
template: ${{ inputs.template-path }}
109+
no-fail-on-empty-changeset: "1"
110+
parameter-overrides: ${{ inputs.parameter-overrides}}
111+
...

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Above example is just a simple example to call workflow from github shared workf
6363
7. [Checkov Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/checkov.md)
6464
8. [Terraform Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform_workflow.md)
6565
9. [Infracost workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/infracost.md)
66+
10. [ Deploy Cloudformation workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/deploy-cloudformation.md)
6667
6768
## Feedback
6869
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/github-shared-workflows/issues), or feel free to drop us an email at [[email protected]](mailto:[email protected]).

docs/deploy-cloudformation.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## [Deploy Cloudformation Stack](https://github.com/clouddrove/github-shared-workflows/blob/master/.github/workflows/infracost.yml)
2+
The process starts with the creation of a shared workflow template. This template contains CloudFormation resource definitions, parameter declarations, and other configuration settings that are commonly used across multiple projects or environments. It serves as a blueprint for the infrastructure you want to create. `.github/workflows/deploy-cloudformation.yml`
3+
4+
#### Usage
5+
6+
- Using this workflow we just defined cloudformation template file and deploy your application.
7+
- In this workflow we added multiple parameters like S3 bucket for source code, stack-parameters and parameters we overrides from called.yml as we defined below.
8+
- In this workflow most beneficial part is we upload our source code to S3 bucket and from there your template take code and deploy the lambda function.
9+
10+
#### Example
11+
12+
```yaml
13+
name: Cloudformation stack deploy
14+
on:
15+
push:
16+
branches: [ main ]
17+
workflow_dispatch:
18+
jobs:
19+
cloudformation-stack-deploy:
20+
uses: clouddrove/github-shared-workflows/.github/workflows/deploy-cloudformation.yml@master
21+
with:
22+
s3-bucket: # S3 Bucket name where code is stored
23+
bucket-prefix: # S3 Bucket prefix/folder name where you push the zip file
24+
aws-region: # Aws region add if you want else default will be used (us-east-1)
25+
stack-name: # Stack name add here
26+
template-path: # Add repo name & template file name ( ex- Repo-name/template.yml)
27+
GitHub-repo-name: # GitHub-repo-name where your src code and template are located
28+
GitHub-branch: # GitHub Repo branch where your src code and template are located
29+
organization-name: # GitHub Organization name where your src code and template are located
30+
code-folder: # Add folder name where your code is located ex-(.ts/.py) else default used (src)
31+
zip-file-name: # Add zip file name which you uploading to S3 bucket after converting code to zip (ex- myfile.zip).
32+
parameter-overrides: # add your overrides parameters here ( ex- VpcName=MyCustomVPC, Cidr=10.0.0.0/16 )
33+
secrets:
34+
AWS_ACCESS_KEY_ID:
35+
AWS_SECRET_ACCESS_KEY: # Add AWS credentials
36+
AWS_SESSION_TOKEN:
37+
GITHUB: # Add GitHub token
38+
```

0 commit comments

Comments
 (0)