Skip to content

Commit 18ae274

Browse files
authored
add example with tests (#8)
1 parent de4c3b3 commit 18ae274

File tree

7 files changed

+152
-1
lines changed

7 files changed

+152
-1
lines changed

.github/workflows/scheduled-test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Scheduled Terraform Test
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Runs every day at midnight UTC
6+
workflow_dispatch: # Allows manual triggering
7+
8+
jobs:
9+
terratest:
10+
name: Run Terratest
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: '1.17'
21+
22+
- name: Install Terraform
23+
uses: hashicorp/setup-terraform@v1
24+
with:
25+
terraform_version: 1.1.5
26+
27+
- name: Install dependencies
28+
run: |
29+
go mod tidy
30+
31+
- name: Run Terratest
32+
run: |
33+
cd test
34+
go test -v
35+
36+
terraform-compliance:
37+
name: Run Terraform Compliance
38+
runs-on: ubuntu-latest
39+
needs: terratest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Terraform
46+
uses: hashicorp/setup-terraform@v3
47+
with:
48+
terraform_version: 0.13.1
49+
50+
- name: Terraform Init
51+
run: terraform init -backend=false
52+
working-directory: ./example
53+
54+
- name: Terraform Plan
55+
run: terraform plan -out=tfplan -input=false
56+
working-directory: ./example
57+
58+
- name: Install terraform-compliance
59+
run: |
60+
pip install terraform-compliance
61+
62+
- name: Run terraform-compliance
63+
run: terraform-compliance -p ./example/tfplan -f ./compliance/features

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ No modules.
7474
```hcl
7575
module "example-com" {
7676
source = "locus313/aws-route53/module"
77-
version = "1.0.3"
77+
version = "1.0.4"
7878
7979
enabled = true
8080
primary_domain = "example.com"

compliance/features/example.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Route 53 Compliance
2+
3+
Scenario: Ensure all A records have the correct TTL
4+
Given I have AWS Route53 Record defined
5+
When its type is "A"
6+
Then its ttl must be 3600
7+
8+
Scenario: Ensure all CNAME records have the correct TTL
9+
Given I have AWS Route53 Record defined
10+
When its type is "CNAME"
11+
Then its ttl must be 3600

example/main.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module "example-com" {
2+
source = "locus313/aws-route53/module"
3+
version = "1.0.4"
4+
5+
enabled = true
6+
primary_domain = "example.com"
7+
8+
records_wr = {
9+
"support.example.com" = "https://example.atlassian.net/servicedesk/customer/portals"
10+
}
11+
12+
records_a = {
13+
"example.com" = ["12.23.45.56"]
14+
}
15+
16+
records_aaaa = {
17+
"example.com" = ["::ffff:c17:2d38"]
18+
}
19+
20+
records_caa = {
21+
"example.com" = ["0 issue \"letsencrypt.org\""]
22+
}
23+
24+
records_cname = {
25+
"calendar.example.com" = ["ghs.googlehosted.com"]
26+
"docs.example.com" = ["ghs.googlehosted.com"]
27+
"ftp.example.com" = ["example.com"]
28+
"mail.example.com" = ["ghs.googlehosted.com"]
29+
"sites.example.com" = ["ghs.googlehosted.com"]
30+
"www.example.com" = ["example.com"]
31+
}
32+
33+
records_mx = {
34+
"example.com" = ["10 aspmx.l.google.com","20 alt1.aspmx.l.google.com","30 alt2.aspmx.l.google.com","40 aspmx2.googlemail.com","50 aspmx3.googlemail.com"]
35+
}
36+
37+
records_txt = {
38+
"example.com" = ["v=spf1 include:_spf.google.com ~all"]
39+
"google._domainkey.example.com" = ["v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3gtOkCHXv+kDJBpIkr1lq1Ywd4B8FJGPceSv9s7yhUtCk8pKwifLmSKWNEyOvuK5oxIms+4Vc9Pu46bi/wehi5zJynzhkOrzYXdOX6+m4Nb8NbFWr0zZqsM+pDGmYzRjeczY/+txXnOegcbxL+967bIRisnlH2CRD91h1t0NJwsvvN23T5MAMaeJr726piDdE\"\"C6P2nF1apYbGXp0DZGz/RvtpCGjASjlpejA8I/xLclZOBn4Ir9pk8gajRSG48D21UKJ3d+PFzYEj9X5n1p1i2trjCqkdyCzU+f3vTUxma5F7fQncKYIeRJwVNbmR03IYfGuicCu13hnVP36aT5yuQIDAQAB"]
40+
}
41+
42+
records_ns = {
43+
"clusters.example.com" = ["ns-128.awsdns-16.com","ns-1533.awsdns-63.org","ns-1554.awsdns-02.co.uk","ns-956.awsdns-55.net"]
44+
"envs.example.com" = ["ns-1103.awsdns-09.org","ns-1587.awsdns-06.co.uk","ns-378.awsdns-47.com","ns-693.awsdns-22.net"]
45+
}
46+
}

example/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "zone_id" {
2+
description = "Zone ID of Route53 zone"
3+
value = module.example-com[0].this_route53_zone_zone_id
4+
}
5+
6+
output "name_servers" {
7+
description = "Name servers of Route53 zone"
8+
value = module.example-com[0].this_route53_zone_name_servers
9+
}

example/provider.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}

test/terraform_module_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test
2+
3+
import (
4+
"testing"
5+
"github.com/gruntwork-io/terratest/modules/terraform"
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestTerraformRoute53Module(t *testing.T) {
10+
terraformOptions := &terraform.Options{
11+
TerraformDir: "../example",
12+
}
13+
14+
defer terraform.Destroy(t, terraformOptions)
15+
terraform.InitAndApply(t, terraformOptions)
16+
17+
zoneID := terraform.Output(t, terraformOptions, "zone_id")
18+
assert.NotEmpty(t, zoneID)
19+
}

0 commit comments

Comments
 (0)