-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add awspec tests and supporting components (#6)
* Tests and fixtures for ALB components using awspec and test kitchen * S3 log bucket and policy rendering for logging now in place * root_principle_id added and referenced through a map for s3 bucket policy * string lists moved to native list types * default region removed * Restructured project templates to alb dir to add testing. This is a breaking change so upping major version. * Redundant examples dir removed * Updated documentation * All PR feedback addressed
- Loading branch information
1 parent
a2fbc68
commit 7842de9
Showing
19 changed files
with
343 additions
and
256 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
*.tfvars* | ||
*.tfvars | ||
*.tfstate* | ||
.terraform | ||
**/Gemfile.lock | ||
**/inspec.lock | ||
*.gem | ||
.kitchen/ | ||
.kitchen.local.yml | ||
Gemfile.lock |
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 @@ | ||
--- | ||
driver: | ||
name: terraform | ||
|
||
provisioner: | ||
name: terraform | ||
directory: test/fixtures | ||
variable_files: | ||
- test/fixtures/terraform.tfvars | ||
|
||
platforms: | ||
- name: aws | ||
|
||
verifier: | ||
name: awspec | ||
# - name: terraform | ||
# format: doc | ||
# groups: | ||
# - name: local_tests | ||
# controls: | ||
# - local_alb | ||
|
||
suites: | ||
- name: default | ||
verifier: | ||
name: awspec | ||
patterns: | ||
- test/integration/default/local_alb.rb |
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,3 +1,9 @@ | ||
ruby '2.4.0' | ||
|
||
source 'https://rubygems.org/' do | ||
gem 'kitchen-terraform', '~> 0.6' | ||
gem 'test-kitchen' | ||
gem 'kitchen-terraform' | ||
gem 'awspec' | ||
gem 'kitchen-verifier-awspec' | ||
gem 'parseconfig' | ||
end |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Id": "Policy1429136655940", | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "Stmt1429136633762", | ||
"Action": [ | ||
"s3:PutObject" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "arn:aws:s3:::${log_bucket}/${log_prefix}/AWSLogs/${account_id}/*", | ||
"Principal": { | ||
"AWS": [ | ||
"${principle_account_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 |
---|---|---|
@@ -1,24 +1,84 @@ | ||
### ALB resources with a switch - logging enabled/disabled | ||
### ALB resources | ||
|
||
resource "aws_alb" "alb_loging" { | ||
# TODO: | ||
# support not logging | ||
|
||
data "template_file" "bucket_policy" { | ||
template = "${file("${path.module}/bucket_policy.json")}" | ||
|
||
vars { | ||
log_bucket = "${var.log_bucket}" | ||
log_prefix = "${var.log_prefix}" | ||
account_id = "${var.aws_account_id}" | ||
principle_account_id = "${lookup(var.principle_account_id, var.aws_region)}" | ||
} | ||
} | ||
|
||
resource "aws_alb" "main" { | ||
name = "${var.alb_name}" | ||
subnets = ["${split(",", var.subnets)}"] | ||
security_groups = ["${split(",", var.alb_security_groups)}"] | ||
subnets = ["${var.subnets}"] | ||
security_groups = ["${var.alb_security_groups}"] | ||
internal = "${var.alb_is_internal}" | ||
|
||
access_logs { | ||
bucket = "${var.log_bucket}" | ||
prefix = "${var.log_prefix}" | ||
} | ||
} | ||
|
||
count = "${var.log_bucket != "" && var.log_prefix != "" ? 1 : 0}" | ||
resource "aws_s3_bucket" "log_bucket" { | ||
bucket = "${var.log_bucket}" | ||
policy = "${data.template_file.bucket_policy.rendered}" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_alb" "alb_nologing" { | ||
name = "${var.alb_name}" | ||
subnets = ["${split(",", var.subnets)}"] | ||
security_groups = ["${split(",", var.alb_security_groups)}"] | ||
internal = "${var.alb_is_internal}" | ||
resource "aws_alb_target_group" "target_group" { | ||
name = "${var.alb_name}-tg" | ||
port = "${var.backend_port}" | ||
protocol = "${upper(var.backend_protocol)}" | ||
vpc_id = "${var.vpc_id}" | ||
|
||
health_check { | ||
interval = 30 | ||
path = "${var.health_check_path}" | ||
port = "traffic-port" | ||
healthy_threshold = 3 | ||
unhealthy_threshold = 3 | ||
timeout = 5 | ||
protocol = "${var.backend_protocol}" | ||
} | ||
|
||
stickiness { | ||
type = "lb_cookie" | ||
cookie_duration = "${var.cookie_duration}" | ||
enabled = "${ var.cookie_duration == 1 ? false : true}" | ||
} | ||
} | ||
|
||
resource "aws_alb_listener" "front_end_http" { | ||
load_balancer_arn = "${aws_alb.main.arn}" | ||
port = "80" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
target_group_arn = "${aws_alb_target_group.target_group.id}" | ||
type = "forward" | ||
} | ||
|
||
count = "${trimspace(element(split(",", var.alb_protocols), 1)) == "HTTP" || trimspace(element(split(",", var.alb_protocols), 2)) == "HTTP" ? 1 : 0}" | ||
} | ||
|
||
resource "aws_alb_listener" "front_end_https" { | ||
load_balancer_arn = "${aws_alb.main.arn}" | ||
port = "443" | ||
protocol = "HTTPS" | ||
certificate_arn = "${var.certificate_arn}" | ||
ssl_policy = "ELBSecurityPolicy-2015-05" | ||
|
||
default_action { | ||
target_group_arn = "${aws_alb_target_group.target_group.id}" | ||
type = "forward" | ||
} | ||
|
||
count = "${(var.log_bucket == "" || var.log_prefix == "") ? 1 : 0}" | ||
count = "${trimspace(element(split(",", var.alb_protocols), 1)) == "HTTPS" || trimspace(element(split(",", var.alb_protocols), 2)) == "HTTPS" ? 1 : 0}" | ||
} |
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,24 +1,19 @@ | ||
# this approach is not working just yet | ||
output "arn" { | ||
value = "${coalesce(aws_alb.alb_loging.arn, aws_alb.alb_nologing.arn) }" | ||
|
||
/*value = "${aws_alb.alb_loging.arn}"*/ | ||
output "alb_id" { | ||
value = "${aws_alb.main.id}" | ||
} | ||
|
||
output "dns_name" { | ||
value = "${aws_alb.alb_loging.dns_name}" | ||
|
||
/*value = "${coalesce(list("aws_alb.alb_loging.dns_name", "aws_alb.alb_nologing.dns_name")) }"*/ | ||
output "alb_dns_name" { | ||
value = "${aws_alb.main.dns_name}" | ||
} | ||
|
||
output "id" { | ||
value = "${aws_alb.alb_loging.id}" | ||
|
||
/*value = "${coalesce(list("aws_alb.alb_loging.dns_name", "aws_alb.alb_nologing.dns_name")) }"*/ | ||
output "alb_zone_id" { | ||
value = "${aws_alb.main.zone_id}" | ||
} | ||
|
||
output "zone_id" { | ||
value = "${aws_alb.alb_loging.zone_id}" | ||
output "target_group_arn" { | ||
value = "${aws_alb_target_group.target_group.arn}" | ||
} | ||
|
||
/*value = "${coalesce(list("aws_alb.alb_loging.dns_name", "aws_alb.alb_nologing.dns_name")) }"*/ | ||
output "principle_account_id" { | ||
value = "${lookup(var.principle_account_id, var.aws_region)}" | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.