-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Terraform HCL pipeline to deploy CloudFront with S3 backend (#28
- Loading branch information
Showing
43 changed files
with
877 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as path from 'path' | ||
import {loadAndExtractCloudfrontDomain} from './helpers' | ||
|
||
const filePath = path.resolve(__dirname, '../../iac/terraform/hcl/react-ui/terraform_output.json') | ||
|
||
// Example usage | ||
const cloudfrontDomain = loadAndExtractCloudfrontDomain(filePath) | ||
const CLOUDFRONT_URL = `https://${cloudfrontDomain}` | ||
|
||
test('CloudFront distribution test', async () => { | ||
|
||
try { | ||
await page.goto(CLOUDFRONT_URL, {waitUntil: 'networkidle2'}) | ||
|
||
// Assuming your default React content has a specific string | ||
const content = await page.content() | ||
expect(content).toContain('Web site created using create-react-app') | ||
} catch (error: any) { | ||
console.error('Error during test:', error.message) | ||
throw error | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fs from "fs" | ||
import TerraformOutput from "./types" | ||
|
||
export const loadAndExtractCloudfrontDomain = (filePath: string): string | null => { | ||
try { | ||
const fileContent = fs.readFileSync(filePath, 'utf-8') | ||
const terraformOutput: TerraformOutput = JSON.parse(fileContent) | ||
// Extract cloudfront_domain_name.value | ||
const cloudfrontDomainValue = terraformOutput?.cloudfront_domain_name?.value | ||
|
||
return cloudfrontDomainValue || null | ||
} catch (error: any) { | ||
console.error('Error loading or parsing JSON file:', error.message) | ||
return null | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */ | ||
module.exports = { | ||
// Don't use a sandbox in CI, to avoid issues with permissions | ||
launch: { | ||
args: ['--no-sandbox', '--disable-setuid-sandbox'], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
"globalSetup": "jest-environment-puppeteer/setup", | ||
"globalTeardown": "jest-environment-puppeteer/teardown", | ||
"testEnvironment": "jest-environment-puppeteer" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "jest-tests", | ||
"version": "0.1.0", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"axios": "^1.6.7", | ||
"jest": "^29.7.0", | ||
"jest-puppeteer": "^10.0.0", | ||
"puppeteer": "^22.0.0", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"@types/jest-environment-puppeteer": "^5.0.6", | ||
"jest-environment-puppeteer": "^10.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"moduleResolution": "node", | ||
"isolatedModules": true, | ||
"jsx": "react" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface TerraformOutput { | ||
cloudfront_domain_name: { | ||
sensitive: boolean; | ||
type: string; | ||
value: string; | ||
}; | ||
} | ||
|
||
export default TerraformOutput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Setup NVM and Node.js | ||
. /usr/local/nvm/nvm.sh use 20 | ||
|
||
# Create AWS config/credentials | ||
make setup-aws | ||
|
||
echo "ARCHITECTURE is '$(uname -m)'" | ||
echo "AWS Version is $(aws --version)" | ||
|
||
export AWS_PROFILE=localstack | ||
export AWS_CONFIG_FILE=/root/.aws/config | ||
export AWS_SHARED_CREDENTIALS_FILE=/root/.aws/credentials | ||
|
||
# The endpoint is not getting picked up from the profile in the config file. | ||
export AWS_ENDPOINT_URL="http://localhost.localstack.cloud:4566" | ||
|
||
# Setup Terraform stacks | ||
make local-tf-create-iac-bucket | ||
make local-tf-cfs3-init | ||
make local-tf-cfs3-plan | ||
make local-tf-cfs3-apply | ||
make local-tf-cfs3-output | ||
# Test Terraform stacks | ||
make --silent local-tf-cfs3-test | ||
|
||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"action": "kill"}' \ | ||
http://localhost.localstack.cloud:4566/_localstack/health |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.