Skip to content

Commit

Permalink
Standardize test resource names
Browse files Browse the repository at this point in the history
  • Loading branch information
jsclarridge committed Nov 14, 2019
1 parent aa745c8 commit 44ebbec
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 105 deletions.
5 changes: 3 additions & 2 deletions examples/alb/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
allow_alb = "true"
}

resource "aws_lb" "test_lb" {
name = var.test_name
internal = false
load_balancer_type = "application"
subnets = module.vpc.public_subnets
Expand All @@ -20,7 +21,7 @@ resource "aws_lb" "test_lb" {
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.vpc_name
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"]
Expand Down
6 changes: 1 addition & 5 deletions examples/alb/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_name" {
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
25 changes: 15 additions & 10 deletions examples/combined/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.logs_bucket
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
Expand All @@ -17,20 +18,22 @@ resource "aws_lb" "test_alb" {
}

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
}

module "config" {
source = "trussworks/config/aws"
version = "~> 2"

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 {
Expand All @@ -48,6 +51,7 @@ resource "aws_elb" "test_elb" {
}

resource "aws_lb" "test_nlb" {
name = var.test_name
internal = false
load_balancer_type = "network"
subnets = module.vpc.public_subnets
Expand All @@ -61,7 +65,7 @@ resource "aws_lb" "test_nlb" {

resource "aws_redshift_cluster" "test_redshift" {
count = var.test_redshift ? 1 : 0
cluster_identifier = "tf-redshift-cluster"
cluster_identifier = var.test_name
node_type = "dc2.large"
cluster_type = "single-node"
master_username = "testredshiftuser"
Expand All @@ -76,7 +80,8 @@ resource "aws_redshift_cluster" "test_redshift" {
}

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

logging {
target_bucket = module.aws_logs.aws_logs_bucket
Expand All @@ -87,7 +92,7 @@ resource "aws_s3_bucket" "log_source_bucket" {
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.vpc_name
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"]
Expand Down
6 changes: 1 addition & 5 deletions examples/combined/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_name" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
Expand Down
8 changes: 4 additions & 4 deletions examples/config/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module "aws_logs" {
source = "../../"
s3_bucket_name = var.logs_bucket
s3_bucket_name = var.test_name
region = var.region
allow_config = "true"
config_logs_prefix = "config"
}

module "config" {
source = "trussworks/config/aws"
version = "~> 2"

source = "trussworks/config/aws"
version = "~> 2"
config_name = var.test_name
config_logs_bucket = module.aws_logs.aws_logs_bucket
config_logs_prefix = "config"
}
2 changes: 1 addition & 1 deletion examples/config/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
5 changes: 3 additions & 2 deletions examples/elb/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
allow_elb = "true"
}

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

access_logs {
Expand All @@ -25,7 +26,7 @@ resource "aws_elb" "test_elb" {
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.vpc_name
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"]
Expand Down
6 changes: 1 addition & 5 deletions examples/elb/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_name" {
type = string
}

variable "vpc_azs" {
type = list(string)
}
5 changes: 3 additions & 2 deletions examples/nlb/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
allow_nlb = "true"
}

resource "aws_lb" "test_lb" {
name = var.test_name
internal = false
load_balancer_type = "network"
subnets = module.vpc.public_subnets
Expand All @@ -20,7 +21,7 @@ resource "aws_lb" "test_lb" {
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2"
name = var.vpc_name
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"]
Expand Down
6 changes: 1 addition & 5 deletions examples/nlb/variables.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
variable "logs_bucket" {
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "vpc_name" {
type = string
}

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

resource "aws_redshift_cluster" "test_redshift" {
cluster_identifier = "tf-redshift-cluster"
cluster_identifier = var.test_name
node_type = "dc2.large"
cluster_type = "single-node"
master_username = "testredshiftuser"
Expand Down
2 changes: 1 addition & 1 deletion examples/redshift/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
5 changes: 3 additions & 2 deletions examples/s3/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
}

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

logging {
target_bucket = module.aws_logs.aws_logs_bucket
Expand Down
2 changes: 1 addition & 1 deletion examples/s3/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
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
12 changes: 5 additions & 7 deletions test/terraform_aws_logs_alb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ import (
func TestTerraformAwsLogsAlb(t *testing.T) {
t.Parallel()

expectedLogsBucket := fmt.Sprintf("terratest-aws-logs-alb-%s", strings.ToLower(random.UniqueId()))
vpcName := fmt.Sprintf("terratest-vpc-alb-%s", strings.ToLower(random.UniqueId()))
testName := fmt.Sprintf("terratest-aws-logs-%s", strings.ToLower(random.UniqueId()))
awsRegion := "us-west-2"
vpcAzs := aws.GetAvailabilityZones(t, awsRegion)[:3]

terraformOptions := &terraform.Options{
TerraformDir: "../examples/alb/",
Vars: map[string]interface{}{
"region": awsRegion,
"vpc_azs": vpcAzs,
"logs_bucket": expectedLogsBucket,
"vpc_name": vpcName,
"region": awsRegion,
"vpc_azs": vpcAzs,
"test_name": testName,
},
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
Expand All @@ -33,6 +31,6 @@ func TestTerraformAwsLogsAlb(t *testing.T) {

defer terraform.Destroy(t, terraformOptions)
// Empty logs_bucket before terraform destroy
defer aws.EmptyS3Bucket(t, awsRegion, expectedLogsBucket)
defer aws.EmptyS3Bucket(t, awsRegion, testName)
terraform.InitAndApply(t, terraformOptions)
}
11 changes: 6 additions & 5 deletions test/terraform_aws_logs_cloudtrail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ func TestTerraformAwsLogsCloudtrail(t *testing.T) {
// Running this test in parallel with other tests in the module
// often causes issues when attempting to empty and delete the bucket.

expectedLogsBucket := fmt.Sprintf("terratest-aws-logs-cloudtrail-%s", strings.ToLower(random.UniqueId()))
testName := fmt.Sprintf("terratest-aws-logs-%s", strings.ToLower(random.UniqueId()))
awsRegion := "us-west-2"

terraformOptions := &terraform.Options{
TerraformDir: "../examples/cloudtrail/",
Vars: map[string]interface{}{
"region": awsRegion,
"logs_bucket": expectedLogsBucket,
"region": awsRegion,
"test_name": testName,
},
EnvVars: map[string]string{
"AWS_DEFAULT_REGION": awsRegion,
},
}

defer terraform.Destroy(t, terraformOptions)
// Empty logs_bucket before terraform destroy
defer aws.EmptyS3Bucket(t, awsRegion, expectedLogsBucket)
// Empty and delete logs_bucket before terraform destroy
defer aws.DeleteS3Bucket(t, awsRegion, testName)
defer aws.EmptyS3Bucket(t, awsRegion, testName)
terraform.InitAndApply(t, terraformOptions)
}
Loading

0 comments on commit 44ebbec

Please sign in to comment.