Skip to content

Commit d44e178

Browse files
committed
added basic example
1 parent a5701bb commit d44e178

File tree

8 files changed

+104
-15
lines changed

8 files changed

+104
-15
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Add example usage here
1212

1313
```hcl
1414
module "example" {
15-
source = "appvia/<NAME>/aws"
16-
version = "0.0.1"
15+
source = "appvia/dns/aws"
16+
version = "1.0.0"
1717
1818
# insert variables here
1919
}

examples/basic/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
77
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
8-
| <a name="requirement_awscc"></a> [awscc](#requirement\_awscc) | >= 0.11.0 |
98

109
## Providers
1110

1211
No providers.
1312

1413
## Modules
1514

16-
No modules.
15+
| Name | Source | Version |
16+
|------|--------|---------|
17+
| <a name="module_central_dns"></a> [central\_dns](#module\_central\_dns) | appvia/dns/aws | n/a |
1718

1819
## Resources
1920

examples/basic/main.tf

+57-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,57 @@
1-
#####################################################################################
2-
# Terraform module examples are meant to show an _example_ on how to use a module
3-
# per use-case. The code below should not be copied directly but referenced in order
4-
# to build your own root module that invokes this module
5-
#####################################################################################
1+
locals {
2+
vpc_provided_dns = "10.0.0.2"
3+
}
4+
5+
module "central_dns" {
6+
source = "../../"
7+
8+
resolver_name = "central"
9+
10+
# ID of the VPC where the outbound resolver should be created.
11+
resolver_vpc_id = "vpc-0f839083ca150be0f"
12+
13+
# At least 2 subnets (in different AZs) where the outbound resolver endpoints
14+
# will be created.
15+
resolver_subnet_ids = [
16+
"subnet-05268db2ad256445e",
17+
"subnet-0e52076f0f87ba47d",
18+
]
19+
20+
# We define our resolver rules in groups. For each group we define we add the rules
21+
# defined to an AWS RAM resource share and share with the defined principals.
22+
resolver_rule_groups = {
23+
main = {
24+
# Name is optional and defaults to the key of the map if not defined.
25+
name = "MyCompany"
26+
27+
# List of principal ARNs to share the RAM share with.
28+
ram_principals = [
29+
"arn:aws:organizations::012345678910:organization/o-6doxpl2e1d",
30+
]
31+
32+
# List of rule definitions
33+
rules = [{
34+
# Domain name for which we want to forward rules. Domains specified here are inclusive
35+
# of the domain itself and all subdomains.
36+
domain = "mycompany.internal"
37+
38+
# List of IP addresses that will resolve the query for this domain. For utilising Route53
39+
# private hosted zones, this should be the Amazon provided DNS server address for the VPC.
40+
targets = [
41+
local.vpc_provided_dns,
42+
]
43+
}]
44+
}
45+
}
46+
47+
# In order to resolve DNS queries for private hosted zones that exist in other accounts
48+
# we need to associate those zones with the VPC that we're creating our resolver. You
49+
# must ensure that the zones specified below are pre-authorized to be associated with
50+
# the VPC specified in `resolver_vpc_id`.
51+
route53_zone_ids = [
52+
"Z069099416OO53SIZNSAH",
53+
"Z0104059RZRYA0EE84IM",
54+
"Z082763213W4KUUPYB6YW",
55+
"Z04370363H60F9DXTVYIU",
56+
]
57+
}

examples/basic/outputs.tf

Whitespace-only changes.

examples/basic/providers.tf

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
provider "aws" {}

examples/basic/terraform.tf

-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
terraform {
32
required_version = ">= 1.0.0"
43

@@ -7,9 +6,5 @@ terraform {
76
source = "hashicorp/aws"
87
version = ">= 5.0.0"
98
}
10-
awscc = {
11-
source = "hashicorp/awscc"
12-
version = ">= 0.11.0"
13-
}
149
}
1510
}

examples/basic/variables.tf

Whitespace-only changes.

tests/basic.tftest.hcl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
mock_provider "aws" {
2+
3+
}
4+
5+
run "basic_resolver" {
6+
command = plan
7+
8+
variables {
9+
resolver_name = "test"
10+
resolver_vpc_id = "vpc-abc123"
11+
12+
resolver_subnet_ids = [
13+
"subnet-abc123",
14+
"subnet-def456",
15+
]
16+
}
17+
18+
assert {
19+
condition = aws_route53_resolver_endpoint.this.direction == "OUTBOUND"
20+
error_message = "Endpoint direction incorrect"
21+
}
22+
23+
assert {
24+
condition = length(aws_route53_resolver_endpoint.this.protocols) == 1
25+
error_message = "Only one protocol expected to be defined"
26+
}
27+
28+
assert {
29+
condition = contains(aws_route53_resolver_endpoint.this.protocols, "Do53")
30+
error_message = "Resolver endpoint should contain Do53 protocol"
31+
}
32+
33+
assert {
34+
condition = aws_route53_resolver_endpoint.this.resolver_endpoint_type == "IPV4"
35+
error_message = "Resolver endpoint type should be IPV4"
36+
}
37+
38+
assert {
39+
condition = aws_security_group.this.name == "${var.resolver_name}-sg"
40+
error_message = "Expected security group name to have -sg suffix"
41+
}
42+
}

0 commit comments

Comments
 (0)