Skip to content

Commit f6f9346

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#12)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent 2a9cdc4 commit f6f9346

32 files changed

+1052
-201
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*.tfstate
66
*.tfstate.*
77

8-
# .tfvars files
9-
*.tfvars
10-
118
**/node_modules/*
129
**/package-lock.json
1310

1411
.build-harness
1512
build-harness
1613

1714
*.zip
15+
16+
*.iml
17+
.idea

.travis.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2018 Cloud Posse LLC
189+
Copyright 2018-2019 Cloud Posse LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 196 additions & 62 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-ses-lambda-forwarder
1818

1919
# Badges to display
2020
badges:
21-
- name: "Build Status"
22-
image: "https://travis-ci.org/cloudposse/terraform-aws-ses-lambda-forwarder.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-aws-ses-lambda-forwarder"
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ses-lambda-forwarder?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5defd0c4158ef27f981fe4dd"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ses-lambda-forwarder.svg"
2626
url: "https://github.com/cloudposse/terraform-aws-ses-lambda-forwarder/releases/latest"
@@ -43,26 +43,31 @@ introduction: |-
4343
4444
For example, an email sent by `John Doe <[email protected]>` to `[email protected]` will be transformed to:
4545
```
46-
46+
4747
4848
```
4949
50-
To override this behavior, set a verified `fromEmail` address (e.g., `[email protected]`) in the config
50+
To override this behavior, set a verified `fromEmail` address (e.g., `[email protected]`) in the config
5151
object and the header will look like this.
5252
```
5353
From: John Doe <[email protected]>
5454
5555
```
5656
57-
__NOTE__: SES only allows receiving email sent to addresses within verified domains. For more information,
57+
__NOTE__: SES only allows receiving email sent to addresses within verified domains. For more information,
5858
see: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-domains.html
5959
```
6060
61-
Initially SES users are in a sandbox environment that has a number of limitations. See:
61+
Initially SES users are in a sandbox environment that has a number of limitations. See:
6262
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/limits.html
6363
6464
# How to use this project
6565
usage: |-
66+
67+
For a complete example, see [examples/complete](examples/complete).
68+
69+
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
70+
6671
```hcl
6772
variable "relay_email" {
6873
default = "[email protected]"
@@ -80,19 +85,21 @@ usage: |-
8085
description = "Emails forward map"
8186
}
8287
83-
module "ses" {
84-
source = "git::https://github.com/cloudposse/terraform-aws-ses-lambda-forwarder.git?ref=tags/0.1.0"
85-
86-
namespace = "${var.namespace}"
87-
name = "${var.ses_name}"
88-
stage = "${var.stage}"
88+
module "ses_lambda_forwarder" {
89+
source = "git::https://github.com/cloudposse/terraform-aws-ses-lambda-forwarder.git?ref=master"
8990
90-
region = "${var.ses_region}"
91+
namespace = var.namespace
92+
stage = var.stage
93+
name = var.name
94+
delimiter = var.delimiter
95+
attributes = var.attributes
96+
tags = var.tags
9197
92-
relay_email = "${var.relay_email}"
93-
domain = "${var.parent_domain_name}"
98+
region = var.region
99+
domain = var.domain
94100
95-
forward_emails = "${var.forward_emails}"
101+
relay_email = var.relay_email
102+
forward_emails = var.forward_emails
96103
}
97104
```
98105
@@ -108,4 +115,8 @@ include:
108115
# Contributors to this project
109116
contributors:
110117
- name: "Igor Rodionov"
111-
github: "goruha"
118+
github: "goruha"
119+
- name: "Erik Osterman"
120+
github: "osterman"
121+
- name: "Andriy Knysh"
122+
github: "aknysh"

codefresh/test.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- unset AWS_PROFILE
75+
- unset AWS_DEFAULT_PROFILE
76+
- unset AWS_MFA_PROFILE
77+
- make -C test/src

docs/targets.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
```
33
Available targets:
44
5-
help This help screen
5+
help Help screen
66
help/all Display help for all targets
7+
help/short This help short screen
78
lint Lint terraform code
89
910
```

docs/terraform.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
1-
21
## Inputs
32

43
| Name | Description | Type | Default | Required |
54
|------|-------------|:----:|:-----:|:-----:|
6-
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
5+
| artifact_filename | Artifact filename | string | `lambda.zip` | no |
6+
| artifact_url | URL template for the remote artifact | string | `https://artifacts.cloudposse.com/$$${module_name}/$$${git_ref}/$$${filename}` | no |
7+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
78
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
89
| domain | Root domain name | string | - | yes |
9-
| forward_emails | Emails forward map | map | `<map>` | no |
10+
| forward_emails | Map of forward emails | map(list(string)) | `<map>` | no |
11+
| lambda_runtime | Lambda runtime | string | `nodejs8.10` | no |
1012
| name | Application or solution name (e.g. `app`) | string | `ses` | no |
11-
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
12-
| region | AWS Region the SES should reside in | string | `us-west-2` | no |
13+
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | `` | no |
14+
| region | AWS Region the SES should reside in | string | - | yes |
1315
| relay_email | Email that used to relay from | string | - | yes |
1416
| spf | DNS SPF record value | string | `v=spf1 include:amazonses.com -all` | no |
15-
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
16-
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
17+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
18+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
19+
20+
## Outputs
21+
22+
| Name | Description |
23+
|------|-------------|
24+
| artifact_base64sha256 | Base64 encoded SHA256 hash of the artifact file |
25+
| artifact_file | Full path to the locally downloaded artifact |
26+
| artifact_git_ref | Git commit hash corresponding to the artifact |
27+
| artifact_url | URL corresponding to the artifact |
28+
| lambda_function_arn | Lamnda Function ARN |
29+
| lambda_function_source_code_size | The size in bytes of the Lambda Function .zip file |
30+
| lambda_function_version | Latest published version of the Lambda Function |
31+
| lambda_iam_policy_arn | Lamnda IAM Policy ARN |
32+
| lambda_iam_policy_id | Lamnda IAM Policy ID |
33+
| lambda_iam_policy_name | Lamnda IAM Policy name |
34+
| s3_bucket_arn | Lamnda IAM Policy ARN |
35+
| s3_bucket_domain_name | Lamnda IAM Policy ARN |
36+
| s3_bucket_id | Lamnda IAM Policy name |
37+
| ses_domain_identity_arn | The ARN of the domain identity |
38+
| ses_domain_identity_verification_arn | The ARN of the domain identity |
39+
| ses_receipt_rule_name | The name of the SES receipt rule |
40+
| ses_receipt_rule_set_name | The name of the SES receipt rule set |
1741

domain.tf

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
data "aws_route53_zone" "default" {
2-
name = "${var.domain}"
3-
comment = "Root DNS Zone"
2+
name = var.domain
43
}
54

65
resource "aws_route53_record" "default" {
7-
zone_id = "${data.aws_route53_zone.default.zone_id}"
6+
zone_id = data.aws_route53_zone.default.zone_id
87
name = "_amazonses.${aws_ses_domain_identity.default.id}"
98
type = "TXT"
109
ttl = "600"
11-
records = ["${aws_ses_domain_identity.default.verification_token}"]
10+
records = [aws_ses_domain_identity.default.verification_token]
1211
}
1312

1413
# Add Route53 MX record
1514
resource "aws_route53_record" "mx" {
16-
zone_id = "${data.aws_route53_zone.default.zone_id}"
17-
name = "${aws_ses_domain_identity.default.id}"
15+
zone_id = data.aws_route53_zone.default.zone_id
16+
name = aws_ses_domain_identity.default.id
1817
type = "MX"
1918
ttl = "600"
2019
records = ["10 inbound-smtp.${var.region}.amazonaws.com"]
21-
22-
# Change to the region in which `aws_ses_domain_identity.example` is created
20+
# Change to the region in which `aws_ses_domain_identity.default` is created
2321
}
2422

2523
# Add Route53 TXT record for SPF
2624
resource "aws_route53_record" "txt" {
27-
zone_id = "${data.aws_route53_zone.default.zone_id}"
28-
name = "${aws_ses_domain_identity.default.id}"
25+
zone_id = data.aws_route53_zone.default.zone_id
26+
name = aws_ses_domain_identity.default.id
2927
type = "TXT"
3028
ttl = "600"
31-
records = ["${var.spf}"]
29+
records = [var.spf]
3230
}
3331

3432
resource "aws_ses_domain_identity" "default" {
35-
domain = "${var.domain}"
33+
domain = var.domain
3634
}
3735

3836
resource "aws_ses_domain_identity_verification" "default" {
39-
domain = "${aws_ses_domain_identity.default.id}"
37+
domain = aws_ses_domain_identity.default.id
4038

41-
depends_on = ["aws_route53_record.default"]
39+
depends_on = [aws_route53_record.default]
4240
}

examples/complete/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
**/node_modules/*
9+
**/package-lock.json
10+
11+
.build-harness
12+
build-harness
13+
14+
*.zip
15+
16+
*.iml
17+
.idea

0 commit comments

Comments
 (0)