-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Integration tests | ||
|
||
This directory contains integration tests for our apps. Tests are written using the [terraform test framework](https://developer.hashicorp.com/terraform/language/tests) | ||
|
||
To run the full test suite, run: | ||
|
||
``` | ||
terraform init | ||
terraform test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
data "aws_region" "current" {} | ||
|
||
resource "aws_cloudformation_stack" "this" { | ||
name = var.name | ||
template_body = file("../.aws-sam/build/${var.app}/${data.aws_region.current.name}/packaged.yaml") | ||
parameters = var.parameters | ||
capabilities = var.capabilities | ||
} | ||
|
||
output "stack" { | ||
value = aws_cloudformation_stack.this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
cat << EOF | ||
{ | ||
"error": "it failed!" | ||
} | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "external" "check" { | ||
program = var.program | ||
query = var.query | ||
working_dir = var.working_dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "result" { | ||
value = data.external.check.result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
variable "program" { | ||
description = <<-EOF | ||
A list of strings, whose first element is the program to run and whose | ||
subsequent elements are optional command line arguments to the program. | ||
Terraform does not execute the program through a shell, so it is not | ||
necessary to escape shell metacharacters nor add quotes around arguments | ||
containing spaces. | ||
EOF | ||
type = list(string) | ||
nullable = false | ||
} | ||
|
||
variable "query" { | ||
description = <<-EOF | ||
A map of string values to pass to the external program as the query | ||
arguments. If not supplied, the program will receive an empty object as its | ||
input. | ||
EOF | ||
type = map(string) | ||
default = {} | ||
nullable = false | ||
} | ||
|
||
variable "working_dir" { | ||
description = "Working directory of the program" | ||
type = string | ||
default = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Exit if any of the intermediate steps fail | ||
set -e | ||
|
||
# Extract "foo" and "baz" arguments from the input into | ||
# FOO and BAZ shell variables. | ||
# jq will ensure that the values are properly quoted | ||
# and escaped for consumption by the shell. | ||
eval "$(jq -r '@sh "FOO=\(.foo) BAZ=\(.baz)"')" | ||
|
||
# Placeholder for whatever data-fetching logic your script implements | ||
FOOBAZ="$FOO $BAZ" | ||
|
||
# Safely produce a JSON object containing the result value. | ||
# jq will ensure that the value is properly quoted | ||
# and escaped to produce a valid JSON string. | ||
jq -n --arg foobaz "$FOOBAZ" '{"foobaz":$foobaz}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_version = "~> 1.6" | ||
required_providers { | ||
external = { | ||
source = "hashicorp/external" | ||
version = "~> 2.3" | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
run "setup" { | ||
module { | ||
source = "./tests/setup" | ||
} | ||
} | ||
|
||
run "install_forwarder" { | ||
variables { | ||
name = run.setup.id | ||
app = "forwarder" | ||
parameters = { | ||
DataAccessPointArn = run.setup.source.arn | ||
DestinationUri = "s3://${run.setup.source.alias}" | ||
} | ||
capabilities = [ | ||
"CAPABILITY_NAMED_IAM", | ||
"CAPABILITY_AUTO_EXPAND", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo "tes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
resource "random_pet" "run" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_s3_bucket" "source" { | ||
bucket = "${random_pet.run.id}-source" | ||
} | ||
|
||
resource "aws_s3_bucket" "destination" { | ||
bucket = "${random_pet.run.id}-destination" | ||
} | ||
|
||
resource "aws_s3_access_point" "source" { | ||
bucket = aws_s3_bucket.source.id | ||
name = random_pet.run.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "id" { | ||
value = random_pet.run.id | ||
description = "Random test identifier" | ||
} | ||
|
||
output "source" { | ||
value = aws_s3_access_point.source | ||
description = "S3 bucket where files are copied from" | ||
} | ||
|
||
output "destination" { | ||
value = aws_s3_bucket.destination | ||
description = "S3 bucket where files are copied to" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = "~> 1.6" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.3" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 3.5.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
run "setup" { | ||
module { | ||
source = "./tests/setup" | ||
} | ||
} | ||
|
||
run "check" { | ||
module { | ||
source = "./tests/check" | ||
} | ||
|
||
variables { | ||
program = ["./scripts/test.sh", run.setup.id ] | ||
} | ||
|
||
assert { | ||
condition = output.result.error == "" | ||
error_message = "Failed to test thing" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
variable "name" { | ||
description = "Stack name" | ||
type = string | ||
} | ||
|
||
variable "app" { | ||
description = "App name" | ||
type = string | ||
} | ||
|
||
variable "parameters" { | ||
description = "Stack parameters" | ||
type = map(string) | ||
} | ||
|
||
variable "capabilities" { | ||
description = "Stack capabilities" | ||
type = list(string) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_version = "~> 1.6" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.3" | ||
} | ||
} | ||
} | ||
|
||
|