Skip to content

Commit b09df4d

Browse files
authored
Use modules.cptest.test-automation.app instead of testing.cloudposse.co (#64)
* Use modules.cptest.test-automation.app instead of testing.cloudposse.co * Update and rename fixtures.us-east-1.tfvars to fixtures.us-east-2.tfvars * Update examples_complete_test.go * Update examples_complete_test.go * Update fixtures.us-east-2.tfvars * Create lambda.yml * Added lambda * Fix tests * Fixed tests * Update fixtures.us-east-2.tfvars * Update examples_complete_test.go
1 parent b0c59b5 commit b09df4d

File tree

3 files changed

+124
-12
lines changed

3 files changed

+124
-12
lines changed

.github/workflows/lambda.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: "build-and-push-lambda"
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "*"
9+
pull_request:
10+
branches:
11+
- main
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
env:
17+
AWS_REGION: us-east-1
18+
IAM_ROLE_ARN_S3: arn:aws:iam::847349463865:role/cplive-core-ue2-public-lambda-artifacts-gha
19+
IAM_ROLE_SEESION_NAME: cloudposse/terraform-aws-ses-lambda-forwarder/ci
20+
S3_BUCKET: cplive-core-ue2-public-lambda-artifacts
21+
S3_FOLDER: terraform-aws-ses-lambda-forwarder
22+
23+
jobs:
24+
build-test-distribute:
25+
runs-on: ubuntu-latest
26+
steps:
27+
##################################################
28+
# Setup GHA Dependencies
29+
##################################################
30+
- name: Use Node.js 22.x
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: 22.x
34+
35+
- name: Install Zip
36+
run: |
37+
sudo apt-get install -y zip
38+
39+
##################################################
40+
# Checkout the repository
41+
##################################################
42+
- name: Checkout Repository
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Fetch main branch so we can compare SHA
48+
run: git fetch origin main
49+
50+
##################################################
51+
# Install App Dependencies, Build, Lint, and Test
52+
##################################################
53+
- name: Install Dependencies
54+
working-directory: lambda
55+
run: yarn install --frozen-lockfile
56+
57+
##################################################
58+
# Dynamically Create Version for Zip File
59+
##################################################
60+
- name: Metadata
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
images: dummy
65+
tags: |
66+
type=raw,value=latest,enable={{is_default_branch}}
67+
type=ref,event=pr
68+
type=semver,pattern={{version}}
69+
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
70+
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
71+
type=sha,prefix=,format=long,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
72+
73+
##################################################
74+
# Build and Upload Bossy Lambda Zip
75+
##################################################
76+
- name: Set ZIP File Name Var
77+
shell: bash
78+
run: |
79+
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
80+
echo "FILE_NAME=terraform-aws-ses-lambda-forwarder-${VERSION}.zip" >> $GITHUB_ENV
81+
82+
- name: Create Zip File
83+
shell: bash
84+
working-directory: lambda
85+
run: |
86+
zip -r "$FILE_NAME" .
87+
mv "./$FILE_NAME" "$GITHUB_WORKSPACE/$FILE_NAME"
88+
89+
- name: Configure AWS Credentials
90+
uses: aws-actions/configure-aws-credentials@v4
91+
with:
92+
aws-region: us-east-2
93+
role-to-assume: ${{ env.IAM_ROLE_ARN_S3 }}
94+
role-session-name: ${{ env.IAM_ROLE_SESSION_NAME }}
95+
96+
- name: Copy Lambda to S3
97+
shell: bash
98+
run: |
99+
aws s3 cp "./$FILE_NAME" s3://${{env.S3_BUCKET}}/${{env.S3_FOLDER}}/ --sse AES256 --region ${{ env.AWS_REGION }}

examples/complete/fixtures.us-east-1.tfvars renamed to examples/complete/fixtures.us-east-2.tfvars

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://docs.aws.amazon.com/general/latest/gr/ses.html
2-
region = "us-east-1"
2+
region = "us-east-2"
33

44
namespace = "eg"
55

@@ -14,12 +14,12 @@ forward_emails = {
1414
1515
}
1616

17-
domain = "testing.cloudposse.co"
17+
domain = "modules.cptest.test-automation.app"
1818

1919
spf = "v=spf1 include:amazonses.com -all"
2020

21-
lambda_runtime = "nodejs12.x"
21+
lambda_runtime = "nodejs22.x"
2222

23-
artifact_url = "https://artifacts.cloudposse.com/terraform-external-module-artifact/example/test.zip"
23+
artifact_url = "https://cplive-core-ue2-public-lambda-artifacts.s3.us-east-2.amazonaws.com/terraform-aws-ses-lambda-forwarder/terraform-aws-ses-lambda-forwarder-latest.zip"
2424

2525
artifact_filename = "lambda.zip"

test/src/examples_complete_test.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
package test
22

33
import (
4+
"fmt"
5+
"math/rand"
6+
"strconv"
7+
"testing"
8+
"time"
9+
410
"github.com/gruntwork-io/terratest/modules/terraform"
511
"github.com/stretchr/testify/assert"
6-
"testing"
712
)
813

914
// Test the Terraform module in examples/complete using Terratest.
1015
func TestExamplesComplete(t *testing.T) {
1116
t.Parallel()
1217

18+
rand.Seed(time.Now().UnixNano())
19+
20+
randId := strconv.Itoa(rand.Intn(100000))
21+
attributes := []string{randId}
22+
1323
terraformOptions := &terraform.Options{
1424
// The path to where our Terraform code is located
1525
TerraformDir: "../../examples/complete",
1626
Upgrade: true,
1727
// Variables to pass to our Terraform code using -var-file options
18-
VarFiles: []string{"fixtures.us-east-1.tfvars"},
28+
VarFiles: []string{"fixtures.us-east-2.tfvars"},
29+
Vars: map[string]interface{}{
30+
"attributes": attributes,
31+
},
1932
}
2033

2134
// At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -32,7 +45,7 @@ func TestExamplesComplete(t *testing.T) {
3245
// Run `terraform output` to get the value of an output variable
3346
artifactUrl := terraform.Output(t, terraformOptions, "artifact_url")
3447
// Verify we're getting back the outputs we expect
35-
assert.Equal(t, "https://artifacts.cloudposse.com/terraform-external-module-artifact/example/test.zip", artifactUrl)
48+
assert.Equal(t, "https://cplive-core-ue2-public-lambda-artifacts.s3.us-east-2.amazonaws.com/terraform-aws-ses-lambda-forwarder/terraform-aws-ses-lambda-forwarder-latest.zip", artifactUrl)
3649

3750
// Run `terraform output` to get the value of an output variable
3851
lambdaFunctionArn := terraform.Output(t, terraformOptions, "lambda_function_arn")
@@ -47,25 +60,25 @@ func TestExamplesComplete(t *testing.T) {
4760
// Run `terraform output` to get the value of an output variable
4861
lambdaIamPolicyName := terraform.Output(t, terraformOptions, "lambda_iam_policy_name")
4962
// Verify we're getting back the outputs we expect
50-
assert.Equal(t, "eg-test-lambda-forwarder-test", lambdaIamPolicyName)
63+
assert.Equal(t, fmt.Sprintf("eg-test-lambda-forwarder-test-%s", randId), lambdaIamPolicyName)
5164

5265
// Run `terraform output` to get the value of an output variable
5366
s3BucketArn := terraform.Output(t, terraformOptions, "s3_bucket_arn")
5467
// Verify we're getting back the outputs we expect
55-
assert.Equal(t, "arn:aws:s3:::eg-test-lambda-forwarder-test", s3BucketArn)
68+
assert.Equal(t, fmt.Sprintf("arn:aws:s3:::eg-test-lambda-forwarder-test-%s", randId), s3BucketArn)
5669

5770
// Run `terraform output` to get the value of an output variable
5871
sesDomainIdentityArn := terraform.Output(t, terraformOptions, "ses_domain_identity_arn")
5972
// Verify we're getting back the outputs we expect
60-
assert.Contains(t, sesDomainIdentityArn, "identity/testing.cloudposse.co")
73+
assert.Contains(t, sesDomainIdentityArn, "identity/modules.cptest.test-automation.app")
6174

6275
// Run `terraform output` to get the value of an output variable
6376
sesReceiptRuleName := terraform.Output(t, terraformOptions, "ses_receipt_rule_name")
6477
// Verify we're getting back the outputs we expect
65-
assert.Equal(t, "eg-test-lambda-forwarder-test", sesReceiptRuleName)
78+
assert.Equal(t, fmt.Sprintf("eg-test-lambda-forwarder-test-%s", randId), sesReceiptRuleName)
6679

6780
// Run `terraform output` to get the value of an output variable
6881
sesReceiptRuleSetName := terraform.Output(t, terraformOptions, "ses_receipt_rule_set_name")
6982
// Verify we're getting back the outputs we expect
70-
assert.Equal(t, "eg-test-lambda-forwarder-test", sesReceiptRuleSetName)
83+
assert.Equal(t, fmt.Sprintf("eg-test-lambda-forwarder-test-%s", randId), sesReceiptRuleSetName)
7184
}

0 commit comments

Comments
 (0)