Skip to content

Commit 74e0906

Browse files
authored
Merge pull request #1 from wellsiau-aws/ws-abp-setup
WIP: Migrate to ABP platform repo
2 parents 836b34e + 3ce95a5 commit 74e0906

Some content is hidden

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

75 files changed

+3364
-115
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ crash.log
1717
# control as they are data points which are potentially sensitive and subject
1818
# to change depending on the environment.
1919
#
20-
*.tfvars
20+
./*.tfvars
2121

2222
# Ignore override files as they are usually used to override resources locally and so
2323
# are not checked in

.header.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,73 @@
1-
# Terraform Module Project
1+
# terraform-runtask-iam-access-analyzer
22

3-
:no_entry_sign: Do not edit this readme.md file. To learn how to change this content and work with this repository, refer to CONTRIBUTING.md
3+
Use this module to integrate Terraform Cloud Run Tasks with AWS IAM Access Analyzer for policy validation.
44

5-
## Readme Content
6-
This file will contain any instructional information about this module.
5+
![Diagram](./diagram/RunTask-EventBridge.png)
6+
7+
## Prerequisites
8+
9+
To use this module you need have the following:
10+
11+
1. AWS account and credentials
12+
2. Terraform Cloud with Run Task entitlement (Business subscription or higher)
13+
14+
## Usage
15+
16+
* Build and package the Lambda files
17+
18+
```
19+
make all
20+
```
21+
22+
* Refer to the [module_workspace](./examples/module_workspace/README.md) for steps to deploy this module in Terraform Cloud.
23+
24+
* After you deployed the [module_workspace](./examples/module_workspace/README.md), navigate to your Terraform Cloud organization, go to Organization Settings > Integrations > Run tasks to find the newly created Run Task.
25+
26+
* You can use this run task in any workspace where you have standard IAM resource policy document. Refer to the [demo_workspace](./examples/demo_workspace/README.md) for more details.
27+
28+
## Limitations
29+
30+
1. Does not provide verbose error / warning messages in Run Task console. In the future, we will explore possibility to provide verbose logging.
31+
32+
2. Does not support Terraform [computed resources](https://www.terraform.io/plugin/sdkv2/schemas/schema-behaviors).
33+
34+
For example, the tool will report no IAM policy found for the following Terraform template. The policy json string is a computed resource. The plan output doesn't contain information of IAM policy document.
35+
36+
```
37+
resource "aws_s3_bucket" "b" {
38+
bucket = "my-tf-test-bucket"
39+
40+
tags = {
41+
Name = "My bucket"
42+
Environment = "Dev"
43+
}
44+
}
45+
46+
resource "aws_iam_policy" "policy" {
47+
name = "test-policy"
48+
description = "A test policy"
49+
50+
policy = jsonencode({
51+
Version = "2012-10-17"
52+
Statement = [
53+
{
54+
Action = [
55+
"s3:GetObject",
56+
]
57+
Effect = "Allow"
58+
Resource = "${aws_s3_bucket.b.id}"
59+
}
60+
]
61+
})
62+
}
63+
```
64+
65+
## Best practice
66+
67+
* **Do not** re-use the Run Tasks URL across different trust-boundary (organizations, accounts, team). We recommend you to deploy separate Run Task deployment per trust-boundary.
68+
69+
* **Do not** use Run Tasks URL from untrusted party, remember that Run Tasks execution sent Terraform plan output to the Run Task endpoint. Only use trusted Run Tasks URL.
70+
71+
* Enable the AWS WAF setup by setting variable `deploy_waf` to `true` (additional cost will apply). This will add WAF protection to the Run Tasks URL endpoint.
72+
73+
* We recommend you to setup additional CloudWatch alarm to monitor Lambda concurrency and WAF rules.
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash -e
22

33
## NOTE: paths may differ when running in a managed task. To ensure behavior is consistent between
44
# managed and local tasks always use these variables for the project and project type path
55
PROJECT_PATH=${BASE_PATH}/project
66
PROJECT_TYPE_PATH=${BASE_PATH}/projecttype
77

8+
echo "Starting Funtional Tests"
9+
810
cd ${PROJECT_PATH}
911

12+
#********** TFC Env Vars *************
13+
export AWS_DEFAULT_REGION=us-east-1
14+
export TFE_TOKEN=`aws secretsmanager get-secret-value --secret-id abp/tfc/token | jq -r ".SecretString"`
15+
export TF_TOKEN_app_terraform_io=`aws secretsmanager get-secret-value --secret-id abp/tfc/token | jq -r ".SecretString"`
16+
17+
#********** MAKEFILE *************
18+
echo "Build the lambda function packages"
19+
make all
20+
1021
#********** Checkov Analysis *************
11-
echo "Running Checkov Analysis"
22+
echo "Running Checkov Analysis on root module"
23+
checkov --directory . --skip-path examples --framework terraform
24+
25+
echo "Running Checkov Analysis on terraform plan"
1226
terraform init
13-
terraform plan -out tf.plan
27+
terraform plan -out tf.plan -var-file .project_automation/functional_tests/functional_test.tfvars
1428
terraform show -json tf.plan > tf.json
1529
checkov
1630

1731
#********** Terratest execution **********
1832
echo "Running Terratest"
33+
export GOPROXY=https://goproxy.io,direct
1934
cd test
2035
rm -f go.mod
2136
go mod init github.com/aws-ia/terraform-project-ephemeral
2237
go mod tidy
2338
go install github.com/gruntwork-io/terratest/modules/terraform
2439
go test -timeout 45m
2540

26-
#********** Terratest execution **********
41+
#********** CLEANUP *************
42+
echo "Cleaning up all temp files and artifacts"
2743
cd ${PROJECT_PATH}
28-
echo "Building readme.md file"
29-
UPDATE_BRANCH="ephemeral_readme-updates"
30-
31-
export GH_DEBUG=1
32-
REMOTE=$(git remote -v | awk '{print $2}' | head -n 1)
33-
git remote remove origin
34-
git remote add origin ${REMOTE}
35-
git fetch --all
36-
37-
git push origin -d $UPDATE_BRANCH || true
38-
git checkout -b "$UPDATE_BRANCH"
39-
terraform-docs --lockfile=false ./
40-
41-
if [ -n "${BASE_PATH}" ]
42-
then
43-
git add . --all
44-
git commit -m "(automated) Updates from project type"
45-
git push -f --set-upstream origin $UPDATE_BRANCH
46-
gh pr create --title "Updates from functional tests " --body "_This is an automated PR incorporating updates to this project's readme.md file. Please review and either approve/merge or reject as appropriate_"
47-
else
48-
echo "Local build mode (skipping git commit)"
49-
fi
44+
make clean
45+
46+
echo "End of Functional Tests"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tfc_org = "wellsiau-org"
2+
aws_region = "us-east-1"

.project_automation/static_tests/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ RUN wget -O /tmp/tflint-ruleset-aws.zip https://github.com/terraform-linters/tfl
2121
RUN curl -s https://raw.githubusercontent.com/aquasecurity/tfsec/master/scripts/install_linux.sh | bash
2222

2323
RUN gem install mdl
24+
25+
ENV TERRAFORM_DOCS_VERSION=v0.16.0
26+
RUN wget https://github.com/terraform-docs/terraform-docs/releases/download/${TERRAFORM_DOCS_VERSION}/terraform-docs-${TERRAFORM_DOCS_VERSION}-linux-amd64.tar.gz && \
27+
tar -C /usr/local/bin -xzf terraform-docs-${TERRAFORM_DOCS_VERSION}-linux-amd64.tar.gz && chmod +x /usr/local/bin/terraform-docs

.project_automation/static_tests/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
PROJECT_PATH=${BASE_PATH}/project
66
PROJECT_TYPE_PATH=${BASE_PATH}/projecttype
77

8+
echo "Starting Static Tests"
9+
810
cd ${PROJECT_PATH}
911
terraform init
1012
terraform validate
@@ -14,4 +16,8 @@ tflint
1416

1517
tfsec .
1618

17-
mdl .header.md
19+
mdl .header.md
20+
21+
terraform-docs --lockfile=false ./
22+
23+
echo "End of Static Tests"

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ go test -timeout 45m
9696
```
9797
# from the root of the repository
9898
terraform-docs --lockfile=false ./
99-
```
99+
```

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
TOPTARGETS := all clean build
2+
3+
SUBDIRS := $(wildcard lambda/*/.)
4+
BASE = $(shell /bin/pwd)
5+
6+
$(TOPTARGETS): $(SUBDIRS)
7+
8+
$(SUBDIRS):
9+
$(MAKE) -C $@ $(MAKECMDGOALS) $(ARGS) BASE="${BASE}"
10+
11+
.PHONY: $(TOPTARGETS) $(SUBDIRS)
12+
13+
clean:
14+
rm -f .terraform.lock.hcl
15+
rm -rf .terraform
16+
rm -rf ./lambda/*.zip
17+
rm -f ./test/go.mod
18+
rm -f ./test/go.sum
19+
rm -f tf.json
20+
rm -f tf.plan

NOTICE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ Licensed under the Apache License, Version 2.0 (the "License"). You may not use
55
http://aws.amazon.com/apache2.0/
66

77
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
9+
**********************
10+
THIRD PARTY COMPONENTS
11+
**********************
12+
This software includes third party software subject to the following copyrights:
13+
14+
@yaml/pyyaml under the Massachusetts Institute of Technology (MIT) license

0 commit comments

Comments
 (0)