Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Automated testing #90

Merged
merged 97 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
0303d45
make optional
zack-is-cool Feb 27, 2023
3688232
update readme
zack-is-cool Feb 27, 2023
511c64a
update env vars
zack-is-cool Feb 27, 2023
6b2eb9b
unable to iterate over tuple if it doesn't exist
zack-is-cool Feb 27, 2023
9272dcb
default null
zack-is-cool Feb 27, 2023
ec7d861
parameterize instance type
zack-is-cool Feb 27, 2023
32532cd
refactor
zack-is-cool Feb 27, 2023
4e1d1f9
add
zack-is-cool Feb 27, 2023
b4bbb2d
parameterize instance type
zack-is-cool Feb 27, 2023
8cf4025
parameterize instance type
zack-is-cool Feb 27, 2023
4c28773
update readme
zack-is-cool Feb 27, 2023
5d27d2c
Merge branch 'main' into playground
zack-is-cool Feb 27, 2023
32f679b
parameterize
zack-is-cool Feb 27, 2023
72b735f
add parameters to example
zack-is-cool Feb 27, 2023
5c26e30
add backend.tf.example
zack-is-cool Feb 27, 2023
5ae1bf7
update lockfile thing
zack-is-cool Feb 27, 2023
b7bfb5e
add backend.tf.example
zack-is-cool Feb 27, 2023
a26795a
DRYify admin username parameters
zack-is-cool Feb 27, 2023
dbcc5bf
update variables
zack-is-cool Feb 27, 2023
7ee5151
DRYify input vars
zack-is-cool Feb 27, 2023
10cea7f
add -foce-copy
zack-is-cool Feb 27, 2023
97b0ede
Remove variable, do not need defaults at the moment
zack-is-cool Feb 28, 2023
c8e2dbd
added cluster_name
zack-is-cool Feb 28, 2023
87b6062
update readmes
zack-is-cool Feb 28, 2023
0edbd56
updating self-managed/managed readmes
JaseKoonce Feb 28, 2023
6e5df2e
fix some pah and var logic
zack-is-cool Feb 28, 2023
158b102
update readme
zack-is-cool Feb 28, 2023
675975c
ignore build dir
zack-is-cool Feb 28, 2023
70a3ab3
update readme
zack-is-cool Feb 28, 2023
52229cf
Merge branch 'playground' of https://github.com/defenseunicorns/iac i…
zack-is-cool Feb 28, 2023
2a41a14
Empty commit
zack-is-cool Mar 1, 2023
10f936c
testing sign
zack-is-cool Mar 1, 2023
b7dec8a
testing sign again
zack-is-cool Mar 1, 2023
c1bf4b3
testing sign again again
zack-is-cool Mar 1, 2023
6bf825e
update readme
zack-is-cool Feb 27, 2023
2b37ea9
update env vars
zack-is-cool Feb 27, 2023
b84529e
unable to iterate over tuple if it doesn't exist
zack-is-cool Feb 27, 2023
e819380
default null
zack-is-cool Feb 27, 2023
8fa20a4
parameterize instance type
zack-is-cool Feb 27, 2023
77cdc7d
refactor
zack-is-cool Feb 27, 2023
cd33f2c
add
zack-is-cool Feb 27, 2023
157fa19
parameterize instance type
zack-is-cool Feb 27, 2023
ec0087f
parameterize instance type
zack-is-cool Feb 27, 2023
a252147
update readme
zack-is-cool Feb 27, 2023
88d0ccc
Move the tfstate-backend module to its own repo (#77)
RothAndrew Feb 21, 2023
8ca53c1
Update README.md (#78)
ntwkninja Feb 23, 2023
f046f8d
Use new remote tfstate-backend module (and delete the one in this rep…
RothAndrew Feb 23, 2023
4c865c6
eks output fix (#83)
ntwkninja Feb 24, 2023
0bed8b6
parameterize
zack-is-cool Feb 27, 2023
91876ae
add parameters to example
zack-is-cool Feb 27, 2023
f712b79
add backend.tf.example
zack-is-cool Feb 27, 2023
911fd74
update lockfile thing
zack-is-cool Feb 27, 2023
ca31abd
add backend.tf.example
zack-is-cool Feb 27, 2023
a06b039
DRYify admin username parameters
zack-is-cool Feb 27, 2023
3313478
update variables
zack-is-cool Feb 27, 2023
8abc801
DRYify input vars
zack-is-cool Feb 27, 2023
747a519
add -foce-copy
zack-is-cool Feb 27, 2023
41c82b9
Remove variable, do not need defaults at the moment
zack-is-cool Feb 28, 2023
3a47231
added cluster_name
zack-is-cool Feb 28, 2023
b3429b1
update readmes
zack-is-cool Feb 28, 2023
369b502
fix some pah and var logic
zack-is-cool Feb 28, 2023
91d151d
update readme
zack-is-cool Feb 28, 2023
1fb2bd7
update readme
zack-is-cool Feb 28, 2023
61ef01a
updating self-managed/managed readmes
JaseKoonce Feb 28, 2023
666a05f
Empty commit
zack-is-cool Mar 1, 2023
abd3122
testing sign
zack-is-cool Mar 1, 2023
50fe0f1
testing sign again
zack-is-cool Mar 1, 2023
cd531a9
testing sign again again
zack-is-cool Mar 1, 2023
8a4e27c
Merge branch 'playground' of https://github.com/defenseunicorns/iac i…
zack-is-cool Mar 1, 2023
37c10e8
wip
RothAndrew Mar 1, 2023
5f8ddf8
wip
RothAndrew Mar 2, 2023
0a5b6d5
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 2, 2023
bcf3ccd
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 6, 2023
98d4476
wip
RothAndrew Mar 6, 2023
3a87b45
wip
RothAndrew Mar 6, 2023
dc09757
wip
RothAndrew Mar 6, 2023
7a26cd2
wip
RothAndrew Mar 6, 2023
3719517
wip
RothAndrew Mar 6, 2023
b068ba9
wip
RothAndrew Mar 6, 2023
18f42ea
wip
RothAndrew Mar 7, 2023
567ad70
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 7, 2023
841ed36
wip
RothAndrew Mar 7, 2023
a3ae040
wip
RothAndrew Mar 7, 2023
a0953ef
wip
RothAndrew Mar 7, 2023
a4d0588
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 13, 2023
0dda038
wip
RothAndrew Mar 13, 2023
7721af9
wip
RothAndrew Mar 13, 2023
37e4398
wip
RothAndrew Mar 13, 2023
cbb148f
wip
RothAndrew Mar 13, 2023
0c8ba4c
wip
RothAndrew Mar 13, 2023
fb5ad10
wip
RothAndrew Mar 13, 2023
e6044ad
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 13, 2023
6923c0c
Merge branch 'main' into feature/add-a-test
RothAndrew Mar 13, 2023
564d4bf
wip
RothAndrew Mar 13, 2023
062bc8f
var.policy_content should never be null, default is empty string
zack-is-cool Mar 14, 2023
61d0404
change back to checking for null
RothAndrew Mar 14, 2023
bde99a2
add validation
RothAndrew Mar 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
.DS_Store

# Local .terraform directories
**/.terraform/*
.terraform/
*.terraform.*

# except .terraform.lock.hcl
!.terraform.lock.hcl

# .tfstate files
*.tfstate
*.tfstate.*
Expand All @@ -24,6 +21,10 @@ crash.*.log
*.tfvars
*.tfvars.json

# Except ones that we do want to commit because they are used for automated tests
!examples/complete/fixtures.common.tfvars
!examples/complete/fixtures.insecure.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ linters:
disable:
- exhaustivestruct
- exhaustruct
- gci
- goerr113
- gofumpt
- goimports
- gomnd
- lll
- nlreturn
Expand Down
3 changes: 2 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
adr-tools 3.0.0
awscli 2.11.0
checkov 2.3.3
golang 1.19.5
golangci-lint 1.50.1
pre-commit 3.0.1
terraform 1.3.7
terraform 1.3.9
terraform-docs 0.16.0
tflint 0.44.1
tfsec 1.28.1
Expand Down
41 changes: 32 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# The version of the build harness container to use
BUILD_HARNESS_REPO := ghcr.io/defenseunicorns/not-a-build-harness/not-a-build-harness
BUILD_HARNESS_VERSION := 0.0.4
BUILD_HARNESS_VERSION := 0.0.8

.DEFAULT_GOAL := help

# Optionally add the "-it" flag for docker run commands if the env var "CI" is not set (meaning we are on a local machine and not in github actions)
TTY_ARG :=
ifndef CI
TTY_ARG := -it
endif

# Silent mode by default. Run `make VERBOSE=1` to turn off silent mode.
ifndef VERBOSE
.SILENT:
Expand All @@ -18,25 +24,42 @@ help: ## Show a list of all targets
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1:\3/p' \
| column -t -s ":"

.PHONY: _test-all
_test-all:
mkdir -p .cache/go
mkdir -p .cache/go-build
mkdir -p .cache/tmp
echo "Running automated tests. This will take several minutes. At times it does not log anything to the console. If you interrupt the test run you will need to log into AWS console and manually delete any orphaned infrastructure."
docker run $(TTY_ARG) --rm -v "${PWD}:/app" -v "${PWD}/.cache/tmp:/tmp" -v "${PWD}/.cache/go:/root/go" -v "${PWD}/.cache/go-build:/root/.cache/go-build" --workdir "/app/test/e2e" -e GOPATH=/root/go -e GOCACHE=/root/.cache/go-build -e REPO_URL -e GIT_BRANCH -e AWS_REGION -e AWS_DEFAULT_REGION -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_SECURITY_TOKEN -e AWS_SESSION_EXPIRATION -e SKIP_SETUP -e SKIP_TEST -e SKIP_TEARDOWN $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION) bash -c 'asdf install && go test -v $(EXTRA_TEST_ARGS) ./...'

.PHONY: test
test: ## Run all automated tests. Requires access to an AWS account. Costs real money.
go test -v -timeout 2h ./...
$(MAKE) _test-all EXTRA_TEST_ARGS="-timeout 2h"

.PHONY: test-complete-insecure
test-complete-insecure: ## Run one test (TestExamplesCompleteInsecure). Requires access to an AWS account. Costs real money.
$(MAKE) _test-all EXTRA_TEST_ARGS="-timeout 2h -run TestExamplesCompleteInsecure"

.PHONY: test-complete-secure
test-complete-secure: ## Run one test (TestExamplesCompleteSecure). Requires access to an AWS account. Costs real money.
#$(MAKE) _test-all EXTRA_TEST_ARGS="-timeout 2h -run TestExamplesCompleteSecure"
echo "TestExamplesCompleteSecure is still being worked on. For now feel free to use the complete-self-managed-nodegroup example."

.PHONY: docker-save-build-harness
docker-save-build-harness: ## Pulls the build harness docker image and saves it to a tarball
@mkdir -p .cache/docker
@docker pull $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION)
@docker save -o .cache/docker/build-harness.tar $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION)
mkdir -p .cache/docker
docker pull $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION)
docker save -o .cache/docker/build-harness.tar $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION)

.PHONY: docker-load-build-harness
docker-load-build-harness: ## Loads the saved build harness docker image
@docker load -i .cache/docker/build-harness.tar
docker load -i .cache/docker/build-harness.tar

.PHONY: run-pre-commit-hooks
run-pre-commit-hooks: ## Run all pre-commit hooks. Returns nonzero exit code if any hooks fail. Uses Docker for maximum compatibility
@mkdir -p .cache/pre-commit
@docker run --rm -v "${PWD}:/app" --workdir "/app" -e "PRE_COMMIT_HOME=/app/.cache/pre-commit" $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION) pre-commit run -a --show-diff-on-failure
mkdir -p .cache/pre-commit
docker run $(TTY_ARG) --rm -v "${PWD}:/app" --workdir "/app" -e "PRE_COMMIT_HOME=/app/.cache/pre-commit" $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION) bash -c 'asdf install && pre-commit run -a --show-diff-on-failure'

.PHONY: fix-cache-permissions
fix-cache-permissions: ## Fixes the permissions on the pre-commit cache
@docker run --rm -v "${PWD}:/app" --workdir "/app" -e "PRE_COMMIT_HOME=/app/.cache/pre-commit" $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION) chmod -R a+rx .cache
docker run $(TTY_ARG) --rm -v "${PWD}:/app" --workdir "/app" -e "PRE_COMMIT_HOME=/app/.cache/pre-commit" $(BUILD_HARNESS_REPO):$(BUILD_HARNESS_VERSION) chmod -R a+rx .cache
40 changes: 40 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Examples

This directory contains examples of how to use the various modules in this repository.

## How to Deploy

### Prerequisites

- *Nix operating system (Linux, macOS, WSL2)
- AWS CLI environment variables
- At minimum: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and either `AWS_REGION` or `AWS_DEFAULT_REGION`
- Preferred: the above plus `AWS_SESSION_TOKEN`, `AWS_SECURITY_TOKEN`, and `AWS_SESSION_EXPIRATION`
> If the account is set up to require MFA, you'll be required to have the session stuff. We recommend that you use [aws-vault](https://github.com/99designs/aws-vault). Friends don't let friends use unencrypted AWS creds.
- `docker`
- `make`
- various standard CLI tools that usually come with running on *Nix (grep, sed, etc)

### Deploy

We'll be using our automated tests to stand up environments. They use [Terratest](https://github.com/gruntwork-io/terratest). Each test is based on one of examples in the `examples` directory. For example, if you want to stand up the "complete" example in "insecure" mode, you'll run the `test-complete-insecure` target.

```shell
export SKIP_TEARDOWN=1
unset SKIP_SETUP
unset SKIP_TEST
make <TheTargetYouWantToRun>
```
> `SKIP_TEARDOWN` tells Terratest to skip running the test stage called "TEARDOWN", which is the stage that destroys the environment. We want things to stay up, so we set this variable. We also make sure `SKIP_SETUP` and `SKIP_TEST` are unset.

> Run `make help` to see all the available targets. Any of them can be used to stand up an environment with different parameters. Do not run `make test` directly, as it will run all the tests in parallel and is not compatible with `SKIP_TEARDOWN`.

### Destroy

```shell
unset SKIP_TEARDOWN
export SKIP_SETUP=1
export SKIP_TEST=1
make <TheTargetYouWantToRun>
```
> Since we're tearing down this time, we don't want `SKIP_TEARDOWN` to be set. Instead, we are setting `SKIP_SETUP` and `SKIP_TEST` to skip the setup and test stages.
28 changes: 14 additions & 14 deletions examples/complete-managed-nodegroup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ module "bastion" {
volume_size = "20"
encrypted = true
}
name = var.bastion_name
vpc_id = module.vpc.vpc_id
subnet_id = module.vpc.private_subnets[0]
aws_region = var.region
access_log_bucket_name = "${var.bastion_name}-access-logs"
bucket_name = "${var.bastion_name}-session-logs"
ssh_user = var.bastion_ssh_user
ssh_password = var.bastion_ssh_password
assign_public_ip = false # var.assign_public_ip
enable_log_to_s3 = true
enable_log_to_cloudwatch = true
vpc_endpoints_enabled = true
tenancy = var.bastion_tenancy
zarf_version = var.zarf_version
name = var.bastion_name
vpc_id = module.vpc.vpc_id
subnet_id = module.vpc.private_subnets[0]
aws_region = var.region
access_log_bucket_name_prefix = "${var.bastion_name}-access-logs"
session_log_bucket_name_prefix = "${var.bastion_name}-session-logs"
ssh_user = var.bastion_ssh_user
ssh_password = var.bastion_ssh_password
assign_public_ip = false # var.assign_public_ip
enable_log_to_s3 = true
enable_log_to_cloudwatch = true
vpc_endpoints_enabled = true
tenancy = var.bastion_tenancy
zarf_version = var.zarf_version
tags = {
Function = "bastion-ssm"
}
Expand Down
28 changes: 14 additions & 14 deletions examples/complete-self-managed-nodegroup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ module "bastion" {
volume_size = "20"
encrypted = true
}
name = var.bastion_name
vpc_id = module.vpc.vpc_id
subnet_id = module.vpc.private_subnets[0]
aws_region = var.region
access_log_bucket_name = "${var.bastion_name}-access-logs"
bucket_name = "${var.bastion_name}-session-logs"
ssh_user = var.bastion_ssh_user
ssh_password = var.bastion_ssh_password
assign_public_ip = false # var.assign_public_ip
enable_log_to_s3 = true
enable_log_to_cloudwatch = true
vpc_endpoints_enabled = true
tenancy = var.bastion_tenancy
zarf_version = var.zarf_version
name = var.bastion_name
vpc_id = module.vpc.vpc_id
subnet_id = module.vpc.private_subnets[0]
aws_region = var.region
access_log_bucket_name_prefix = "${var.bastion_name}-access-logs"
session_log_bucket_name_prefix = "${var.bastion_name}-session-logs"
ssh_user = var.bastion_ssh_user
ssh_password = var.bastion_ssh_password
assign_public_ip = false # var.assign_public_ip
enable_log_to_s3 = true
enable_log_to_cloudwatch = true
vpc_endpoints_enabled = true
tenancy = var.bastion_tenancy
zarf_version = var.zarf_version
tags = {
Function = "bastion-ssm"
}
Expand Down
Loading