Skip to content

Commit 9967879

Browse files
authored
Merge pull request #149 from proactiveops/example
Improve example
2 parents e6775e9 + 8c7aa32 commit 9967879

File tree

5 files changed

+134
-30698
lines changed

5 files changed

+134
-30698
lines changed

Diff for: example/.github/workflows/deploy.yaml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: "Deploy"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
schedule:
8+
- cron: '30 3 * * 6'
9+
10+
jobs:
11+
12+
deploy:
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
steps:
20+
- name: Check out code
21+
id: checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: 3.12
28+
29+
- name: Install pipx
30+
id: install-pipx
31+
run: pip install pipx
32+
33+
- name: Run PicoFun
34+
id: run-picofun
35+
run: pipx run --spec git+https://github.com/proactiveops/picofun --config-file picofun.toml zendesk https://developer.zendesk.com/zendesk/oas.yaml
36+
37+
- name: Copy Extra Terraform Files
38+
id: copy-extra-tf-files
39+
run: cp *.tf output/
40+
41+
- name: Setup TFLint
42+
id: setup-tflint
43+
uses: terraform-linters/setup-tflint@19a52fbac37dacb22a09518e4ef6ee234f2d4987 # v4.0.0
44+
45+
- name: Init TFLint
46+
id: init-tflint
47+
run: tflint --init
48+
env:
49+
# Needed to avoid getting rate limited by GitHub API
50+
GITHUB_TOKEN: ${{ github.token }}
51+
52+
- name: TFLint
53+
id: tflint
54+
run: tflint
55+
working-directory: ./output
56+
57+
- name: TFSec
58+
id: tfsec
59+
uses: aquasecurity/tfsec-action@b466648d6e39e7c75324f25d83891162a721f2d6 # v1.0.3
60+
with:
61+
# Avoiding rate limit again
62+
github_token: ${{ github.token }}
63+
64+
- name: Setup Terraform
65+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
66+
id: tf-setup
67+
with:
68+
terraform_version: 1.9.8
69+
70+
- name: AWS Login
71+
id: aws-login
72+
uses: aws-actions/configure-aws-credentials@v4
73+
with:
74+
aws-region: us-east-1
75+
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
76+
role-session-name: GitHubActions
77+
78+
- name: Terraform init
79+
id: tf-init
80+
run: terraform init
81+
working-directory: ./output
82+
83+
- name: Terraform validate
84+
id: tf-validate
85+
run: terraform validate
86+
working-directory: ./output
87+
88+
- name: Terraform Apply
89+
id: apply
90+
run: terraform apply -auto-approve
91+
working-directory: ./output

Diff for: example/README.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If my agent email address was [email protected] the JSON would look like so:
2929

3030
## Generating Lambdas
3131

32-
To generate the Lambda functions and associated Terraform, run the following commmand:
32+
To generate the Lambda functions and associated Terraform, you can run the following commmand:
3333

3434
```sh
3535
picofun --config-file example/picofun.toml zendesk https://developer.zendesk.com/zendesk/oas.yaml
@@ -88,6 +88,27 @@ Do you want to perform these actions?
8888

8989
Review scrollback to ensure everything looks in order. When you're confident things look ok, type `yes` and hit [enter]. Go make a cup of tea, then bake a cake, make another cup of tea, eat the cake, drink both cups of tea, and then your lambda should have deployed.
9090

91-
## TODO
91+
## GitHub Action
9292

93-
Create a GitHub Actions workflow for regenerating the functions on a weekly basis.
93+
There is a full GitHub Actions deployment pipeline included in the project. It is designed to update the deployment once a week or when code is pushed to the main branch.
94+
95+
To use the workflow you must create a repository level environment `AWS_ROLE_ARN` and set the value to the ARN of the role that will perform the deployments. Follow the [AWS documentation for setting up the role using OIDC](https://aws.amazon.com/blogs/security/use-iam-roles-to-connect-github-actions-to-actions-in-aws/).
96+
97+
The role must have access to manage IAM roles and policies, lambda functions, and CloudWatch log groups along with the ability to read and write to the Terraform backend resources.
98+
99+
The workflow also needs a backend defined. Add a file called `backend.tf` with the following contents:
100+
101+
```hcl
102+
terraform {
103+
backend "s3" {
104+
region = "us-east-1"
105+
bucket = "your-state-bucket" # Change to a bucket in your account
106+
key = "picofun-zendesk/terraform.tfstate"
107+
dynamodb_table = "terraform-lock" # Make sure this table exists
108+
}
109+
}
110+
```
111+
112+
For more information on the configuration, [refer to the Terraform S3 backend documentation](https://developer.hashicorp.com/terraform/language/backend/s3).
113+
114+
When run for the first time, the pipeline will take a while. It is deploying over 450 Lambda functions and CloudWatch Log groups.

Diff for: example/extra.tf

+18
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,21 @@ resource "aws_iam_role_policy_attachment" "ssm_read" {
2525
role = aws_iam_role.lambda.name
2626
policy_arn = aws_iam_policy.ssm_read.arn
2727
}
28+
29+
terraform {
30+
required_version = "~> 1.0"
31+
required_providers {
32+
archive = {
33+
source = "hashicorp/archive"
34+
version = ">= 2.0, < 3.0"
35+
}
36+
aws = {
37+
source = "hashicorp/aws"
38+
version = ">= 5.0, < 6.0"
39+
}
40+
null = {
41+
source = "hashicorp/null"
42+
version = ">= 3.0, < 4.0"
43+
}
44+
}
45+
}

Diff for: example/picofun.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bundle = "helpers"
2+
iam_role_prefix = "pf-example-"
23
preprocessor = "zendesk_common.preprocessor.preprocess"
34
layers = ["arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:79"]
45

0 commit comments

Comments
 (0)