Skip to content

Commit

Permalink
Merge pull request #37 from trussworks/169682491-more-terratests
Browse files Browse the repository at this point in the history
Add terratests for all supported services
  • Loading branch information
jsclarridge authored Nov 15, 2019
2 parents b9e386b + 44ebbec commit 24eb0e6
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pre_commit_tests: ensure_pre_commit ## Run pre-commit tests

.PHONY: test
test: pre_commit_tests
go test -count 1 -v -timeout 90m ./test/...
go test -short -count 1 -v -timeout 90m ./test/...

.PHONY: clean
clean:
Expand Down
28 changes: 28 additions & 0 deletions examples/alb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
allow_alb = "true"
}

resource "aws_lb" "test_lb" {
name = var.test_name
internal = false
load_balancer_type = "application"
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
prefix = "alb"
enabled = true
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.test_name
cidr = "10.0.0.0/16"
azs = var.vpc_azs
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
}
11 changes: 11 additions & 0 deletions examples/alb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
9 changes: 5 additions & 4 deletions examples/cloudtrail/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.logs_bucket
s3_bucket_name = var.test_name
region = var.region
}

module "aws_cloudtrail" {
source = "trussworks/cloudtrail/aws"
version = "~> 2"
s3_bucket_name = module.aws_logs.aws_logs_bucket
source = "trussworks/cloudtrail/aws"
version = "~> 2"
s3_bucket_name = module.aws_logs.aws_logs_bucket
cloudwatch_log_group_name = var.test_name
}
2 changes: 1 addition & 1 deletion examples/cloudtrail/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

Expand Down
99 changes: 99 additions & 0 deletions examples/combined/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
}

resource "aws_lb" "test_alb" {
name = var.test_name
internal = false
load_balancer_type = "application"
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
prefix = "alb"
enabled = true
}
}

module "aws_cloudtrail" {
source = "trussworks/cloudtrail/aws"
version = "~> 2"
s3_bucket_name = module.aws_logs.aws_logs_bucket
cloudwatch_log_group_name = var.test_name
}

module "config" {
source = "trussworks/config/aws"
version = "~> 2"
config_name = var.test_name
config_logs_bucket = module.aws_logs.aws_logs_bucket
config_logs_prefix = "config"
}

resource "aws_elb" "test_elb" {
name = var.test_name
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
bucket_prefix = "elb"
enabled = true
}

listener {
instance_port = 8000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}

resource "aws_lb" "test_nlb" {
name = var.test_name
internal = false
load_balancer_type = "network"
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
prefix = "nlb"
enabled = true
}
}

resource "aws_redshift_cluster" "test_redshift" {
count = var.test_redshift ? 1 : 0
cluster_identifier = var.test_name
node_type = "dc2.large"
cluster_type = "single-node"
master_username = "testredshiftuser"
master_password = "TestRedshiftpw123"
skip_final_snapshot = "true"

logging {
bucket_name = module.aws_logs.aws_logs_bucket
s3_key_prefix = "redshift"
enable = true
}
}

resource "aws_s3_bucket" "log_source_bucket" {
bucket = "${var.test_name}-source"
acl = "private"

logging {
target_bucket = module.aws_logs.aws_logs_bucket
target_prefix = "log/"
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.test_name
cidr = "10.0.0.0/16"
azs = var.vpc_azs
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
}
16 changes: 16 additions & 0 deletions examples/combined/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_azs" {
type = list(string)
}

variable "test_redshift" {
type = bool
default = true
}
15 changes: 15 additions & 0 deletions examples/config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
allow_config = "true"
config_logs_prefix = "config"
}

module "config" {
source = "trussworks/config/aws"
version = "~> 2"
config_name = var.test_name
config_logs_bucket = module.aws_logs.aws_logs_bucket
config_logs_prefix = "config"
}
7 changes: 7 additions & 0 deletions examples/config/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "test_name" {
type = "string"
}

variable "region" {
type = "string"
}
33 changes: 33 additions & 0 deletions examples/elb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
allow_elb = "true"
}

resource "aws_elb" "test_elb" {
name = var.test_name
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
bucket_prefix = "elb"
enabled = true
}

listener {
instance_port = 8000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.test_name
cidr = "10.0.0.0/16"
azs = var.vpc_azs
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
}
11 changes: 11 additions & 0 deletions examples/elb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
28 changes: 28 additions & 0 deletions examples/nlb/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
allow_nlb = "true"
}

resource "aws_lb" "test_lb" {
name = var.test_name
internal = false
load_balancer_type = "network"
subnets = module.vpc.public_subnets

access_logs {
bucket = module.aws_logs.aws_logs_bucket
prefix = "nlb"
enabled = true
}
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.test_name
cidr = "10.0.0.0/16"
azs = var.vpc_azs
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
}
11 changes: 11 additions & 0 deletions examples/nlb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
21 changes: 21 additions & 0 deletions examples/redshift/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
allow_redshift = "true"
}

resource "aws_redshift_cluster" "test_redshift" {
cluster_identifier = var.test_name
node_type = "dc2.large"
cluster_type = "single-node"
master_username = "testredshiftuser"
master_password = "TestRedshiftpw123"
skip_final_snapshot = "true"

logging {
bucket_name = module.aws_logs.aws_logs_bucket
s3_key_prefix = "redshift"
enable = true
}
}
7 changes: 7 additions & 0 deletions examples/redshift/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}
15 changes: 15 additions & 0 deletions examples/s3/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.test_name
region = var.region
}

resource "aws_s3_bucket" "log_source_bucket" {
bucket = "${var.test_name}-source"
acl = "private"

logging {
target_bucket = module.aws_logs.aws_logs_bucket
target_prefix = "log/"
}
}
7 changes: 7 additions & 0 deletions examples/s3/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}
2 changes: 1 addition & 1 deletion examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.logs_bucket
s3_bucket_name = var.test_name
region = var.region
}
2 changes: 1 addition & 1 deletion examples/simple/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

Expand Down
Loading

0 comments on commit 24eb0e6

Please sign in to comment.