Make dns module resilient to dynamic values (#317)
* refactor module and fix tests * account for wildcard records * account for empty recordset names * align tests * align networking end to end examples * fix behaviour with wildcard and empty names * Update main.tf * fix dumb online edit :)
This commit is contained in:
committed by
GitHub
parent
b481d9baff
commit
5001eb49a4
@@ -32,16 +32,16 @@ variable "peer_network" {
|
||||
}
|
||||
|
||||
variable "recordsets" {
|
||||
type = list(object({
|
||||
name = string
|
||||
type = string
|
||||
type = map(object({
|
||||
ttl = number
|
||||
records = list(string)
|
||||
}))
|
||||
default = [
|
||||
{ name = "localhost", type = "A", ttl = 300, records = ["127.0.0.1"] },
|
||||
{ name = "local-host", type = "A", ttl = 300, records = ["127.0.0.2"] }
|
||||
]
|
||||
default = {
|
||||
"A localhost" = { ttl = 300, records = ["127.0.0.1"] }
|
||||
"A local-host.test.example." = { ttl = 300, records = ["127.0.0.2"] }
|
||||
"CNAME *" = { ttl = 300, records = ["localhost.example.org."] }
|
||||
"A " = { ttl = 300, records = ["127.0.0.3"] }
|
||||
}
|
||||
}
|
||||
|
||||
variable "type" {
|
||||
|
||||
@@ -21,9 +21,9 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture')
|
||||
|
||||
|
||||
def test_private(plan_runner):
|
||||
"Test private zone with two recordsets."
|
||||
"Test private zone with three recordsets."
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
assert len(resources) == 3
|
||||
assert len(resources) == 5
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_dns_record_set', 'google_dns_managed_zone'
|
||||
])
|
||||
@@ -34,13 +34,22 @@ def test_private(plan_runner):
|
||||
assert len(r['values']['private_visibility_config']) == 1
|
||||
|
||||
|
||||
def test_private_recordsets(plan_runner):
|
||||
"Test recordsets in private zone."
|
||||
_, resources = plan_runner(FIXTURES_DIR)
|
||||
recordsets = [r['values']
|
||||
for r in resources if r['type'] == 'google_dns_record_set']
|
||||
assert set(r['name'] for r in recordsets) == set([
|
||||
'localhost.test.example.',
|
||||
'local-host.test.example.',
|
||||
'*.test.example.',
|
||||
"test.example."
|
||||
])
|
||||
|
||||
|
||||
def test_private_no_networks(plan_runner):
|
||||
"Test private zone not exposed to any network."
|
||||
_, resources = plan_runner(FIXTURES_DIR, client_networks='[]')
|
||||
assert len(resources) == 3
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_dns_record_set', 'google_dns_managed_zone'
|
||||
])
|
||||
for r in resources:
|
||||
if r['type'] != 'google_dns_managed_zone':
|
||||
continue
|
||||
@@ -83,10 +92,6 @@ def test_peering(plan_runner):
|
||||
def test_public(plan_runner):
|
||||
"Test public zone with two recordsets."
|
||||
_, resources = plan_runner(FIXTURES_DIR, type='public')
|
||||
assert len(resources) == 3
|
||||
assert set(r['type'] for r in resources) == set([
|
||||
'google_dns_record_set', 'google_dns_managed_zone'
|
||||
])
|
||||
for r in resources:
|
||||
if r['type'] != 'google_dns_managed_zone':
|
||||
continue
|
||||
|
||||
@@ -24,4 +24,4 @@ def test_resources(e2e_plan_runner):
|
||||
"Test that plan works and the numbers of resources is as expected."
|
||||
modules, resources = e2e_plan_runner(FIXTURES_DIR)
|
||||
assert len(modules) == 17
|
||||
assert len(resources) == 69
|
||||
assert len(resources) == 71
|
||||
|
||||
@@ -24,4 +24,4 @@ def test_resources(e2e_plan_runner):
|
||||
"Test that plan works and the numbers of resources is as expected."
|
||||
modules, resources = e2e_plan_runner(FIXTURES_DIR)
|
||||
assert len(modules) == 14
|
||||
assert len(resources) == 46
|
||||
assert len(resources) == 48
|
||||
|
||||
@@ -24,4 +24,4 @@ def test_resources(e2e_plan_runner):
|
||||
"Test that plan works and the numbers of resources is as expected."
|
||||
modules, resources = e2e_plan_runner(FIXTURES_DIR)
|
||||
assert len(modules) == 10
|
||||
assert len(resources) == 40
|
||||
assert len(resources) == 41
|
||||
|
||||
Reference in New Issue
Block a user