Skip to content

Commit a7117f3

Browse files
authored
Initial version 0.0.1 (#29)
Terraform Cloud Agent on Amazon ECS cluster * Feature : bring your own ECS cluster * Feature : single execution mode * Feature : Fargate Spot
1 parent 24e3539 commit a7117f3

31 files changed

+547
-100
lines changed

.config/.checkov.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
download-external-modules: False
22
evaluate-variables: true
3-
file:
4-
- 'tf.json'
3+
directory:
4+
- ./
55
framework:
6-
- terraform_plan
6+
- terraform
77
skip-check:
88
- CKV2_GCP*
99
- CKV_AZURE*
1010
- CKV2_AZURE*
11-
repo-root-for-plan-enrichment:
12-
- '.'
1311
summary-position: bottom
1412
output: 'cli'
1513
compact: True
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
66
echo "Executing Post-Entrypoint Helpers"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
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+
#********** TFC Env Vars *************
9+
echo "Load env vars"
10+
export AWS_DEFAULT_REGION=us-west-2
11+
export TFE_TOKEN=`aws secretsmanager get-secret-value --secret-id abp/hcp/token | jq -r ".SecretString"`
12+
13+
#********** Get tfvars from SSM *************
14+
echo "Get *.tfvars from SSM parameter"
15+
aws ssm get-parameter \
16+
--name "/abp/hcp/functional/terraform_test.tfvars" \
17+
--with-decryption \
18+
--query "Parameter.Value" \
19+
--output "text" \
20+
--region "us-west-2" > ./tests/terraform.auto.tfvars
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"
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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plan.out.json
44

55
# Local .terraform directories
66
**/.terraform/*
7+
**/.terraform
78

89
# .tfstate files
910
*.tfstate

.header.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
# Terraform Module Project
1+
# Terraform Cloud Agent on Amazon ECS
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+
This solution creates self-hosted HashiCorp Cloud Platform (HCP) Terraform agent on Amazon ECS cluster. HCP Terraform allows you to manage isolated, private, or on-premises infrastructure using self-hosted HCP Terraform agents. The agent polls HCP Terraform or HCP Terraform Enterprise for any changes to your configuration and executes the changes locally, so you do not need to allow public ingress traffic to your resources. Agents allow you to control infrastructure in private environments without modifying your network perimeter.
44

5-
## Readme Content
5+
## Architecture
66

7-
This file will contain any instructional information about this module.
7+
![Terraform Cloud Agent on Amazon ECS architecture](/assets/architecture.png)
8+
9+
## Prerequisites
10+
11+
To use this module you need to have the following:
12+
13+
1. [HashiCorp Cloud Platform (HCP) Terraform](https://www.hashicorp.com/products/terraform) subscription
14+
2. Terraform API token with permission to create Terraform agent pool
15+
3. AWS account and credentials to provision resources as mentioned below.
16+
4. VPC with private subnets
17+
18+
## Getting Started
19+
20+
Please refer to the [examples](./examples/basic) on how to get started.

.project_automation/functional_tests/entrypoint.sh

+12-8
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"
@@ -32,12 +32,16 @@ post_entrypoint() {
3232
#********** Pre-entrypoint helper *************
3333
pre_entrypoint
3434

35-
#********** Checkov Analysis *************
36-
echo "Running Checkov Analysis"
37-
terraform init
38-
terraform plan -out tf.plan
39-
terraform show -json tf.plan > tf.json
40-
checkov --config-file ${PROJECT_PATH}/.config/checkov.yml
35+
#********** Functional Test *************
36+
/bin/bash ${PROJECT_PATH}/.project_automation/functional_tests/functional_tests.sh
37+
if [ $? -eq 0 ]
38+
then
39+
echo "Functional test completed"
40+
EXIT_CODE=0
41+
else
42+
echo "Functional test failed"
43+
EXIT_CODE=1
44+
fi
4145

4246
#********** Post-entrypoint helper *************
4347
post_entrypoint

.project_automation/functional_tests/functional_tests.sh

+1-1
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"

.project_automation/static_tests/entrypoint.sh

+2-2
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"

CODEOWNERS

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
* @aws-ia/aws-ia
1+
gautam.baghel@hashicorp.com
2+
dan.barr@hashicorp.com
3+
manuchn@amazon.com
4+
wellsiau@amazon.com

CONTRIBUTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For best practices and information on developing with Terraform, see the [I&A Mo
88

99
## Contributing Code
1010

11-
In order to contibute code to this repository, you must submit a *[Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)*. To do so, you must *[fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo)* this repostiory, make your changes in your forked version and submit a *Pull Request*.
11+
In order to contribute code to this repository, you must submit a *[Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)*. To do so, you must *[fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo)* this repository, make your changes in your forked version and submit a *Pull Request*.
1212

1313
## Writing Documentation
1414

@@ -20,7 +20,7 @@ README.md is automatically generated by pulling in content from other files. For
2020

2121
Pull Requests (PRs) submitted against this repository undergo a series of static and functional checks.
2222

23-
> :exclamation: Note: Failures during funtional or static checks will prevent a pull request from being accepted.
23+
> :exclamation: Note: Failures during functional or static checks will prevent a pull request from being accepted.
2424
2525
It is a best practice to perform these checks locally prior to submitting a pull request.
2626

@@ -32,15 +32,15 @@ It is a best practice to perform these checks locally prior to submitting a pull
3232
- Checkov
3333
- Terratest
3434

35-
> :bangbang: The readme.md file will be created after all checks have completed successfuly, it is recommended that you install terraform-docs locally in order to preview your readme.md file prior to publication.
35+
> :bangbang: The README.md file will be created after all checks have completed successfully, it is recommended that you install terraform-docs locally in order to preview your readme.md file prior to publication.
3636
3737
## Install the required tools
3838

3939
Prerequisites:
4040

4141
- [Python](https://docs.python.org/3/using/index.html)
4242
- [Pip](https://pip.pypa.io/en/stable/installation/)
43-
- [golang](https://go.dev/doc/install) (for macos you can use `brew`)
43+
- [golang](https://go.dev/doc/install) (for macOS you can use `brew`)
4444
- [tflint](https://github.com/terraform-linters/tflint)
4545
- [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/)
4646
- [Markdown Lint](https://github.com/markdownlint/markdownlint)

0 commit comments

Comments
 (0)