Skip to content

Commit d9adbe7

Browse files
committed
chore: added additional unit tests
1 parent ccddccc commit d9adbe7

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
340340
| <a name="input_enable_default_route_table_association"></a> [enable\_default\_route\_table\_association](#input\_enable\_default\_route\_table\_association) | Indicates the transit gateway default route table should be associated with the subnets | `bool` | `true` | no |
341341
| <a name="input_enable_default_route_table_propagation"></a> [enable\_default\_route\_table\_propagation](#input\_enable\_default\_route\_table\_propagation) | Indicates the transit gateway default route table should be propagated to the subnets | `bool` | `true` | no |
342342
| <a name="input_enable_dns_request_logging"></a> [enable\_dns\_request\_logging](#input\_enable\_dns\_request\_logging) | Enable logging of DNS requests | `bool` | `false` | no |
343-
| <a name="input_enable_dynamodb_endpoint"></a> [enable\_dynamodb\_endpoint](#input\_enable\_dynamodb\_endpoint) | Enable DynamoDB VPC Gateway endpoint | `bool` | `false` | no |
343+
| <a name="input_enable_dynamodb_endpoint"></a> [enable\_dynamodb\_endpoint](#input\_enable\_dynamodb\_endpoint) | Enable DynamoDB VPC Gateway endpoint | `bool` | `true` | no |
344344
| <a name="input_enable_private_endpoints"></a> [enable\_private\_endpoints](#input\_enable\_private\_endpoints) | Indicates the network should provision private endpoints | `list(string)` | `[]` | no |
345345
| <a name="input_enable_route53_resolver_rules"></a> [enable\_route53\_resolver\_rules](#input\_enable\_route53\_resolver\_rules) | Automatically associates any shared route53 resolver rules with the VPC | `bool` | `true` | no |
346-
| <a name="input_enable_s3_endpoint"></a> [enable\_s3\_endpoint](#input\_enable\_s3\_endpoint) | Enable S3 VPC Gateway endpoint | `bool` | `false` | no |
346+
| <a name="input_enable_s3_endpoint"></a> [enable\_s3\_endpoint](#input\_enable\_s3\_endpoint) | Enable S3 VPC Gateway endpoint | `bool` | `true` | no |
347347
| <a name="input_enable_ssm"></a> [enable\_ssm](#input\_enable\_ssm) | Indicates we should provision SSM private endpoints | `bool` | `false` | no |
348348
| <a name="input_enable_transit_gateway_appliance_mode"></a> [enable\_transit\_gateway\_appliance\_mode](#input\_enable\_transit\_gateway\_appliance\_mode) | Indicates the network should be connected to a transit gateway in appliance mode | `bool` | `false` | no |
349349
| <a name="input_enable_transit_gateway_subnet_natgw"></a> [enable\_transit\_gateway\_subnet\_natgw](#input\_enable\_transit\_gateway\_subnet\_natgw) | Indicates if the transit gateway subnets should be connected to a nat gateway | `bool` | `false` | no |

examples/basic/main.tf

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ module "vpc" {
1313
source = "../.."
1414

1515
availability_zones = 3
16-
enable_ssm = true
17-
ipam_pool_id = "ipam-pool-id"
16+
enable_ssm = false # enable SSM for private subnets
17+
ipam_pool_id = null # "ipam-pool-id" # optional
1818
name = "operations"
1919
private_subnet_netmask = 24
20-
public_subnet_netmask = 24
20+
public_subnet_netmask = 0
2121
tags = local.tags
2222
vpc_cidr = "10.100.0.0/21"
2323

2424
private_subnet_tags = {
2525
"kubernetes.io/cluster/operations" = "owned"
2626
"kubernetes.io/role/elb" = "1"
2727
}
28-
29-
public_subnet_tags = {
30-
"kubernetes.io/cluster/operations" = "owned"
31-
"kubernetes.io/role/internal-elb" = "1"
32-
}
3328
}

tests/module.tftest.hcl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,72 @@ mock_provider "aws" {
88
]
99
}
1010
}
11+
12+
mock_data "aws_region" {
13+
defaults = {
14+
name = "eu-west-1"
15+
}
16+
}
17+
18+
mock_data "aws_caller_identity" {
19+
defaults = {
20+
account_id = "1234567890"
21+
}
22+
}
1123
}
1224

1325
run "basic" {
1426
command = plan
1527

1628
variables {
1729
name = "test-vpc"
30+
enable_ssm = true
1831
private_subnet_netmask = 24
1932
tags = {
2033
"Environment" = "test"
2134
"GitRepo" = "https://github.com/appvia/terraform-aws-network"
2235
"Terraform" = "true"
2336
}
2437
}
38+
39+
assert {
40+
condition = module.vpc != null
41+
error_message = "Module should not be null"
42+
}
43+
44+
assert {
45+
condition = aws_vpc_endpoint.vpe_endpoints["ec2messages"] != null && aws_vpc_endpoint.vpe_endpoints["ec2messages"].service_name == "com.amazonaws.eu-west-1.ec2messages"
46+
error_message = "ec2messages endpoint should be created"
47+
}
48+
49+
assert {
50+
condition = aws_vpc_endpoint.vpe_endpoints["ssm"] != null && aws_vpc_endpoint.vpe_endpoints["ssm"].service_name == "com.amazonaws.eu-west-1.ssm"
51+
error_message = "ssm endpoint should be created"
52+
}
53+
54+
assert {
55+
condition = aws_vpc_endpoint.vpe_endpoints["ssmmessages"] != null && aws_vpc_endpoint.vpe_endpoints["ssmmessages"].service_name == "com.amazonaws.eu-west-1.ssmmessages"
56+
error_message = "ssmmessages endpoint should be created"
57+
}
58+
59+
assert {
60+
condition = aws_vpc_endpoint.dynamodb[0] != null && aws_vpc_endpoint.dynamodb[0].service_name == "com.amazonaws.eu-west-1.dynamodb"
61+
error_message = "dynamodb endpoint should be created"
62+
}
63+
64+
assert {
65+
condition = aws_vpc_endpoint.s3[0] != null && aws_vpc_endpoint.s3[0].service_name == "com.amazonaws.eu-west-1.s3"
66+
error_message = "s3 endpoint should be created"
67+
}
68+
69+
assert {
70+
condition = aws_vpc_endpoint.dynamodb[0].vpc_endpoint_type == "Gateway"
71+
error_message = "dynamodb endpoint should be created"
72+
}
73+
74+
assert {
75+
condition = aws_vpc_endpoint.s3[0].vpc_endpoint_type == "Gateway"
76+
error_message = "s3 endpoint should be created"
77+
}
2578
}
2679

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ variable "nacl_rules" {
191191
variable "enable_s3_endpoint" {
192192
description = "Enable S3 VPC Gateway endpoint"
193193
type = bool
194-
default = false
194+
default = true
195195
}
196196

197197
variable "enable_dynamodb_endpoint" {
198198
description = "Enable DynamoDB VPC Gateway endpoint"
199199
type = bool
200-
default = false
200+
default = true
201201
}

0 commit comments

Comments
 (0)