-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init terratest and add first basic test
- Loading branch information
Showing
10 changed files
with
201 additions
and
6 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
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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
AWS_PROFILE=${AWS_PROFILE:-"test"} | ||
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-"us-east-1"} | ||
|
||
exec docker run \ | ||
--name terraform-cli \ | ||
--interactive \ | ||
--tty \ | ||
--rm \ | ||
--workdir /tmp/workspace/terraform \ | ||
--volume "${HOME}/.aws":/root/.aws \ | ||
--volume "$(pwd)":/tmp/workspace/terraform \ | ||
--volume "$(cd .. && pwd)":/tmp/workspace/fargate-module \ | ||
--env AWS_PROFILE="${AWS_PROFILE}" \ | ||
--env AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" \ | ||
hashicorp/terraform:0.11.11 "${@}" |
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,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
|
||
# Extract AWS credentials file so we can use AWS stuff without exporting access key/secret | ||
mkdir -p ~/.aws && echo ${AWS_CREDENTIALS_FILE} | base64 -d > ~/.aws/credentials |
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,24 @@ | ||
# Base | ||
FROM node:alpine AS base | ||
ENV HOME=/home/node | ||
WORKDIR $HOME/app | ||
RUN chown -R node:node $HOME/* | ||
USER node | ||
COPY package*.json ./ | ||
|
||
# Dependencies | ||
FROM base AS dependencies | ||
RUN npm set progress=false && npm config set depth 0 | ||
RUN npm install --only=production | ||
RUN cp -R node_modules prod_node_modules | ||
RUN npm install | ||
|
||
# Release | ||
FROM dependencies as release | ||
|
||
COPY --from=dependencies $HOME/app/prod_node_modules ./node_modules | ||
COPY . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["node", "."] |
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 @@ | ||
[ | ||
{ | ||
"portMappings": [ | ||
{ | ||
"hostPort": ${container_port}, | ||
"protocol": "tcp", | ||
"containerPort": ${container_port} | ||
} | ||
], | ||
"image": "${repository_url}:latest", | ||
"name": "${container_name}", | ||
"logConfiguration": { | ||
"logDriver": "awslogs", | ||
"options": { | ||
"awslogs-group": "${log_group}", | ||
"awslogs-region": "${region}", | ||
"awslogs-stream-prefix": "ecs" | ||
} | ||
} | ||
} | ||
] |
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,39 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/aws" | ||
"github.com/gruntwork-io/terratest/modules/random" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
) | ||
|
||
func TestBasicExample(t *testing.T) { | ||
expectedName := fmt.Sprintf("fargate-%s", strings.ToLower(random.UniqueId())) | ||
|
||
// Pick a random AWS region to test in. This helps ensure the module works in all regions. | ||
awsRegion := aws.GetRandomStableRegion(t, nil, nil) | ||
|
||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: ".", | ||
|
||
// Variables to pass to our Terraform code using -var options | ||
Vars: map[string]interface{}{ | ||
"name": expectedName, | ||
}, | ||
|
||
// Environment variables to set when running Terraform | ||
EnvVars: map[string]string{ | ||
"AWS_DEFAULT_REGION": awsRegion, | ||
}, | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
terraform.InitAndApply(t, terraformOptions) | ||
} |
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,15 @@ | ||
module github.com/strvcom/terraform-aws-fargate | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.17.14 // indirect | ||
github.com/boombuler/barcode v1.0.0 // indirect | ||
github.com/go-sql-driver/mysql v1.4.1 // indirect | ||
github.com/google/uuid v1.1.1 // indirect | ||
github.com/gruntwork-io/terratest v0.14.2 | ||
github.com/pquerna/otp v1.1.0 // indirect | ||
github.com/stretchr/testify v1.3.0 // indirect | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect | ||
golang.org/x/net v0.0.0-20190311031020-56fb01167e7d // indirect | ||
) |
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,26 @@ | ||
github.com/aws/aws-sdk-go v1.17.14 h1:IjqZDIQoLyZ48A93BxVrZOaIGgZPRi4nXt6WQUMJplY= | ||
github.com/aws/aws-sdk-go v1.17.14/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= | ||
github.com/boombuler/barcode v1.0.0 h1:s1TvRnXwL2xJRaccrdcBQMZxq6X7DvsMogtmJeHDdrc= | ||
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= | ||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | ||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | ||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/gruntwork-io/terratest v0.14.2 h1:A9YUZZlXE/syTnIVeuqhqoyVO5CUJS5Kasvyr5IUsv8= | ||
github.com/gruntwork-io/terratest v0.14.2/go.mod h1:NjUn6YXA5Skxt8Rs20t3isYx5Rl+EgvGB8/+RRXddqk= | ||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= | ||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/pquerna/otp v1.1.0 h1:q2gMsMuMl3JzneUaAX1MRGxLvOG6bzXV51hivBaStf0= | ||
github.com/pquerna/otp v1.1.0/go.mod h1:Zad1CMQfSQZI5KLpahDiSUX4tMMREnXw98IvL1nhgMk= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20190311031020-56fb01167e7d h1:vQJbQvu6+H699vOmHa20TEBI9nEqroRbMtf/9biIE3A= | ||
golang.org/x/net v0.0.0-20190311031020-56fb01167e7d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
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,9 @@ | ||
const express = require('express') | ||
const os = require('os') | ||
|
||
const hostname = os.hostname() | ||
const app = express() | ||
|
||
app.listen(3000, () => console.log(`Example app listening on port 3000! Host: ${hostname}`)) | ||
|
||
app.get('/', async (req, res) => res.json({ hostname })) |
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,33 @@ | ||
terraform { | ||
required_version = "~> 0.11.11" | ||
} | ||
|
||
provider "aws" { | ||
version = "~> 1.54.0" | ||
profile = "test" | ||
} | ||
|
||
variable "name" {} | ||
|
||
module "fargate" { | ||
source = "../fargate-module" | ||
|
||
vpc_create_nat = false | ||
|
||
name = "${var.name}" | ||
|
||
services = { | ||
api = { | ||
task_definition = "api.json" | ||
container_port = 3000 | ||
cpu = "256" | ||
memory = "512" | ||
replicas = 3 | ||
|
||
registry_retention_count = 15 | ||
logs_retention_days = 14 | ||
} | ||
} | ||
|
||
codepipeline_events_enabled = true | ||
} |