Skip to content

Commit 7d08228

Browse files
authored
feat: refactor & e2e test (#2)
* Various tidy up & code refactor * Introducing Lambda@Edge to overcome the requirement for public Lambda function URL. * Added Terraform test
1 parent c1c7639 commit 7d08228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1337
-1157
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#!/bin/bash
22
## NOTE: this script runs at the end of functional test
3-
## Use this to load any configurations after the functional test
3+
## Use this to load any configurations after the functional test
44
## TIPS: avoid modifying the .project_automation/functional_test/entrypoint.sh
55
## migrate any customization you did on entrypoint.sh to this helper script
6-
echo "Executing Post-Entrypoint Helpers"
6+
echo "Executing Post-Entrypoint Helpers"
7+
8+
#********** Project Path *************
9+
PROJECT_PATH=${BASE_PATH}/project
10+
PROJECT_TYPE_PATH=${BASE_PATH}/projecttype
11+
cd ${PROJECT_PATH}
12+
13+
#********** CLEANUP *************
14+
echo "Cleaning up all temp files and artifacts"
15+
cd ${PROJECT_PATH}
16+
make -s clean
17+
rm -rf ./tests/terraform.auto.tfvars
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
#!/bin/bash
22
## NOTE: this script runs at the start of functional test
3-
## use this to load any configuration before the functional test
3+
## use this to load any configuration before the functional test
44
## TIPS: avoid modifying the .project_automation/functional_test/entrypoint.sh
55
## migrate any customization you did on entrypoint.sh to this helper script
6-
echo "Executing Pre-Entrypoint Helpers"
6+
echo "Executing Pre-Entrypoint Helpers"
7+
8+
9+
#********** Project Path *************
10+
PROJECT_PATH=${BASE_PATH}/project
11+
PROJECT_TYPE_PATH=${BASE_PATH}/projecttype
12+
cd ${PROJECT_PATH}
13+
14+
#********** TFC Env Vars *************
15+
export AWS_DEFAULT_REGION=us-west-2
16+
export TFE_TOKEN=`aws secretsmanager get-secret-value --secret-id abp/hcp/token --region $AWS_DEFAULT_REGION | jq -r ".SecretString"`
17+
export TF_TOKEN_app_terraform_io=`aws secretsmanager get-secret-value --secret-id abp/hcp/token --region $AWS_DEFAULT_REGION | jq -r ".SecretString"`
18+
19+
#********** MAKEFILE *************
20+
echo "Build the lambda function packages"
21+
make all
22+
23+
#********** Get tfvars from SSM *************
24+
echo "Get *.tfvars from SSM parameter"
25+
aws ssm get-parameter \
26+
--name "/abp/hcp/functional/terraform-aws-runtask-tf-plan-analyzer/terraform_tests.tfvars" \
27+
--with-decryption \
28+
--query "Parameter.Value" \
29+
--output "text" \
30+
--region $AWS_DEFAULT_REGION >> ./tests/terraform.auto.tfvars
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
## NOTE: this script runs at the end of static test
3-
## Use this to load any configurations after the static test
3+
## Use this to load any configurations after the static test
44
## TIPS: avoid modifying the .project_automation/static_test/entrypoint.sh
55
## migrate any customization you did on entrypoint.sh to this helper script
66
echo "Executing Post-Entrypoint Helpers"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
## NOTE: this script runs at the start of static test
3-
## use this to load any configuration before the static test
3+
## use this to load any configuration before the static test
44
## TIPS: avoid modifying the .project_automation/static_test/entrypoint.sh
55
## migrate any customization you did on entrypoint.sh to this helper script
66
echo "Executing Pre-Entrypoint Helpers"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Local .terraform directories
22
**/.terraform/*
3+
**/.terraform
34

45
# .tfstate files
56
*.tfstate
@@ -40,4 +41,6 @@ terraform.rc
4041

4142
**/site-packages
4243
*.zip
43-
settings.json
44+
settings.json
45+
TODO.md
46+
.DS_Store

.header.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
# terraform-aws-plan-analyzer-runtask
1+
# Runtask Terraform Plan Analyzer
22

3-
Use this module to develop HCP Terraform run task and deploy it in AWS.
3+
## Overview
4+
5+
Integrate Amazon Bedrock to your HashiCorp Cloud Platform Terraform (Terraform Cloud) Run Tasks for:
6+
7+
* Analyzing Terraform plan and generate short-summary
8+
9+
* Function calling for other API-based analysis (e.g AMI analysis)
10+
11+
### Terraform plan summary
12+
13+
![Example](./images/example.png)
14+
15+
### Function calling (AMI analysis)
16+
17+
![Example2](./images/example2.png)
18+
19+
## Architecture
420

521
![Diagram](./images/arch.png)
622

23+
This module must be deployed in AWS account with access to Amazon Bedrock model. We recommend you to use hub-spoke model, by deploying this module in one dedicated account.
24+
25+
Please refer to the [best-practice](#best-practice) section below for more details.
26+
727
## Prerequisites
828

929
To use this module you need have the following:
@@ -13,7 +33,13 @@ To use this module you need have the following:
1333

1434
## Usage
1535

16-
1. Reference the `examples/basic` folder on how to use this module
36+
* Build and package the Lambda files
37+
38+
```
39+
make all
40+
```
41+
42+
* Reference the `examples/basic` folder on how to use this module
1743

1844
```sh
1945
cd examples/basic

.project_automation/functional_tests/entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
## WARNING: DO NOT modify the content of entrypoint.sh
4-
# Use ./config/functional_tests/pre-entrypoint-helpers.sh or ./config/functional_tests/post-entrypoint-helpers.sh
4+
# Use ./config/functional_tests/pre-entrypoint-helpers.sh or ./config/functional_tests/post-entrypoint-helpers.sh
55
# to load any customizations or additional configurations
66

77
## NOTE: paths may differ when running in a managed task. To ensure behavior is consistent between
@@ -22,7 +22,7 @@ pre_entrypoint() {
2222
post_entrypoint() {
2323
if [ -f ${PROJECT_PATH}/.config/functional_tests/post-entrypoint-helpers.sh ]; then
2424
echo "Post-entrypoint helper found"
25-
source ${PROJECT_PATH}/.config/functional_tests/post-entrypoint-helpers.sh
25+
source ${PROJECT_PATH}/.config/functional_tests/post-entrypoint-helpers.sh
2626
echo "Post-entrypoint helper loaded"
2727
else
2828
echo "Post-entrypoint helper not found - skipped"

.project_automation/functional_tests/functional_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if test -f ${MANDATORY_TEST_PATH}; then
2020
else
2121
echo "File ${MANDATORY_TEST_PATH} not found. You must include at least one test run in file ${MANDATORY_TEST_PATH}"
2222
(exit 1)
23-
fi
23+
fi
2424

2525
if [ $? -eq 0 ]; then
2626
echo "Terraform Test Successfull"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
FROM public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:4.0
2-
RUN yum install -y yum-utils && yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && yum install -y gh
2+
RUN yum install -y yum-utils && yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && yum install -y gh
33
RUN pip install awscli

.project_automation/static_tests/entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
## WARNING: DO NOT modify the content of entrypoint.sh
4-
# Use ./config/static_tests/pre-entrypoint-helpers.sh or ./config/static_tests/post-entrypoint-helpers.sh
4+
# Use ./config/static_tests/pre-entrypoint-helpers.sh or ./config/static_tests/post-entrypoint-helpers.sh
55
# to load any customizations or additional configurations
66

77
## NOTE: paths may differ when running in a managed task. To ensure behavior is consistent between
@@ -22,7 +22,7 @@ pre_entrypoint() {
2222
post_entrypoint() {
2323
if [ -f ${PROJECT_PATH}/.config/static_tests/post-entrypoint-helpers.sh ]; then
2424
echo "Post-entrypoint helper found"
25-
source ${PROJECT_PATH}/.config/static_tests/post-entrypoint-helpers.sh
25+
source ${PROJECT_PATH}/.config/static_tests/post-entrypoint-helpers.sh
2626
echo "Post-entrypoint helper loaded"
2727
else
2828
echo "Post-entrypoint helper not found - skipped"

0 commit comments

Comments
 (0)