|
|
@@ -126,3 +126,73 @@ run "an_inbound_rule_with_an_empty_port_range_is_rejected" {
|
|
|
}
|
|
|
expect_failures = [var.inbound_from_tag_rules]
|
|
|
}
|
|
|
+
|
|
|
+run "default_has_no_tag_scoped_outbound_rules" {
|
|
|
+ command = plan
|
|
|
+ assert {
|
|
|
+ condition = length(output.outbound_tag_rules) == 0
|
|
|
+ error_message = "No tag-scoped outbound rule may render unless outbound_to_tag_rules lists one."
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = alltrue([
|
|
|
+ for r in digitalocean_firewall.this.outbound_rule :
|
|
|
+ length(coalesce(r.destination_tags, [])) == 0
|
|
|
+ ])
|
|
|
+ error_message = "By default no outbound rule may carry destination_tags."
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+run "outbound_to_tag_renders_only_tag_destined_rules" {
|
|
|
+ command = plan
|
|
|
+ variables {
|
|
|
+ outbound_to_tag_rules = [
|
|
|
+ { protocol = "tcp", port_range = "22" },
|
|
|
+ { protocol = "udp", port_range = "9999" },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = output.outbound_rule_count == 7
|
|
|
+ error_message = "The five defaults plus exactly the two listed tag rules must render."
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = jsonencode(output.outbound_tag_rules) == jsonencode(sort(["tcp/22/cah-baseline-nyc3", "udp/9999/cah-baseline-nyc3"]))
|
|
|
+ error_message = "Each tag-scoped outbound rule must be destined to this firewall's own tag and nothing else."
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = alltrue([
|
|
|
+ for r in digitalocean_firewall.this.outbound_rule :
|
|
|
+ length(coalesce(r.destination_tags, [])) == 0 ? true : (length(coalesce(r.destination_addresses, [])) == 0 && length(coalesce(r.destination_droplet_ids, [])) == 0 && length(coalesce(r.destination_load_balancer_uids, [])) == 0 && toset(r.destination_tags) == toset(["cah-baseline-nyc3"]))
|
|
|
+ ])
|
|
|
+ error_message = "Tag-scoped outbound rules must carry destination_tags equal to the module tag and no destination addresses."
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = jsonencode(output.outbound_rules) == jsonencode(sort([
|
|
|
+ "tcp/443/0.0.0.0/0,::/0",
|
|
|
+ "tcp/80/0.0.0.0/0,::/0",
|
|
|
+ "tcp/53/0.0.0.0/0,::/0",
|
|
|
+ "udp/53/0.0.0.0/0,::/0",
|
|
|
+ "udp/123/0.0.0.0/0,::/0",
|
|
|
+ ]))
|
|
|
+ error_message = "The address-based outbound list must be unchanged by tag-scoped rules."
|
|
|
+ }
|
|
|
+ assert {
|
|
|
+ condition = output.inbound_rule_count == 0
|
|
|
+ error_message = "Outbound tag rules must not add inbound rules."
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+run "an_outbound_tag_rule_with_an_unknown_protocol_is_rejected" {
|
|
|
+ command = plan
|
|
|
+ variables {
|
|
|
+ outbound_to_tag_rules = [{ protocol = "icmp", port_range = "22" }]
|
|
|
+ }
|
|
|
+ expect_failures = [var.outbound_to_tag_rules]
|
|
|
+}
|
|
|
+
|
|
|
+run "an_outbound_tag_rule_with_an_empty_port_range_is_rejected" {
|
|
|
+ command = plan
|
|
|
+ variables {
|
|
|
+ outbound_to_tag_rules = [{ protocol = "tcp", port_range = "" }]
|
|
|
+ }
|
|
|
+ expect_failures = [var.outbound_to_tag_rules]
|
|
|
+}
|