Skip to content

Commit

Permalink
test: DBTP-893: Fix ALB terraform tests (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwozencroft authored Apr 17, 2024
1 parent 889767f commit 2c7d7a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 73 deletions.
4 changes: 0 additions & 4 deletions application-load-balancer/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ terraform {
aws.domain,
]
}
time = {
source = "hashicorp/time"
version = ">=0.11.1"
}
}
}
73 changes: 8 additions & 65 deletions application-load-balancer/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
mock_provider "aws" {
alias = "prod"
}

mock_provider "aws" {
alias = "dev"
alias = "sandbox"
}

mock_provider "aws" {
alias = "sandbox"
alias = "domain"
}

override_data {
Expand Down Expand Up @@ -37,20 +33,6 @@ override_data {
name = "dom-prefix-alb.env.app.uktrade.digital"
}
}
override_data {
target = data.aws_route53_zone.domain-root-prod
values = {
count = 1
name = "dom-prefix-root-prod.env.app.uktrade.digital"
}
}
override_data {
target = data.aws_route53_zone.domain-alb-prod
values = {
count = 1
name = "dom-prefix-alb-prod.env.app.uktrade.digital"
}
}


variables {
Expand Down Expand Up @@ -256,56 +238,17 @@ run "aws_route53_record_unit_test" {
}

assert {
condition = aws_route53_record.alb-record[0].name == "dom-prefix.env.app.uktrade.digital"
error_message = "Invalid value for aws_route53_record.validation-record-san name parameter, should be: dom-prefix.env.app.uktrade.digital"
}

assert {
condition = aws_route53_record.alb-record[0].ttl == 300
error_message = "Invalid value for aws_route53_record.alb-record[0] ttl parameter, should be: 300"
}

assert {
condition = aws_route53_record.alb-record[0].type == "CNAME"
error_message = "Invalid value for aws_route53_record.alb-record[0] type parameter, should be: CNAME"
}
}

run "aws_route53_record_prod_unit_test" {
variables {
application = "prod-app"
environment = "prod"
vpc_name = "vpc-name"
config = {
domain_prefix = "dom-prefix",
cdn_domains_list = { "dev.my-application.uktrade.digital" : "my-application.uktrade.digital" },
}
}

command = plan

assert {
condition = aws_route53_record.validation-record-prod[0].ttl == 300
error_message = "Invalid value for aws_route53_record.validation-record-prod ttl parameter, should be: 300"
}

assert {
condition = aws_route53_record.validation-record-prod[1].ttl == 300
error_message = "Invalid value for aws_route53_record.validation-record-prod ttl parameter, should be: 300"
}

assert {
condition = aws_route53_record.alb-record-prod[0].name == "dom-prefix.prod-app.prod.uktrade.digital"
error_message = "Invalid value for aws_route53_record.alb-record-prod[0] name parameter, should be: dom-prefix.prod-app.prod.uktrade.digital"
condition = aws_route53_record.alb-record.name == "dom-prefix.env.app.uktrade.digital"
error_message = "Invalid value for aws_route53_record.alb-record name parameter, should be: dom-prefix.env.app.uktrade.digital"
}

assert {
condition = aws_route53_record.alb-record-prod[0].ttl == 300
error_message = "Invalid value for aws_route53_record.alb-record-prod[0] ttl parameter, should be: 300"
condition = aws_route53_record.alb-record.ttl == 300
error_message = "Invalid value for aws_route53_record.alb-record ttl parameter, should be: 300"
}

assert {
condition = aws_route53_record.alb-record-prod[0].type == "CNAME"
error_message = "Invalid value for aws_route53_record.alb-record-prod[0] type parameter, should be: CNAME"
condition = aws_route53_record.alb-record.type == "CNAME"
error_message = "Invalid value for aws_route53_record.alb-record type parameter, should be: CNAME"
}
}
5 changes: 1 addition & 4 deletions example/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ terraform {
}

provider "aws" {
region = "eu-west-2"
profile = "dev"
alias = "domain"
shared_credentials_files = ["~/.aws/config"]
alias = "domain"
}

0 comments on commit 2c7d7a0

Please sign in to comment.