Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
420 commits
Select commit Hold shift + click to select a range
aee2abd
Refactoring
benfortuna Mar 14, 2019
d777694
Provision an S3 bucket configured as a static website with an optiona…
Mar 13, 2019
16e3000
Refactoring
Mar 13, 2019
ceaad89
Added lambda for automated key rotation
Mar 20, 2019
e906f54
Ignore build artefacts
benfortuna Mar 25, 2019
4b9f214
Update README.md
benfortuna Apr 17, 2019
f1eb512
Update README.md
benfortuna Apr 18, 2019
d2a0301
Update README.md
benfortuna Apr 18, 2019
73af2be
Update README.md
benfortuna Apr 18, 2019
2ebaa74
Update README.md
benfortuna Apr 18, 2019
6184f9f
Include power users in key rotation group by default
Mar 20, 2019
ce4cc0d
Provide roles for IAM management
Mar 20, 2019
1479efc
Lambda layers support
Mar 27, 2019
b700530
Chime notifications (webhooks) support
Mar 27, 2019
2d10c07
Added cloudfront blueprint
Apr 9, 2019
b0de150
Support for lambda@edge to rewrite urls with plus (+) so they aren't …
Apr 15, 2019
910606e
Updated docs
May 4, 2019
cd415a9
Added blueprint roles for segregation of duties
May 4, 2019
6ece256
Merge remote-tracking branch 'origin/develop' into feature/accelerators
May 4, 2019
b3de7cf
Merge pull request #29 from micronode/feature/accelerators
benfortuna May 4, 2019
5f3298a
Updated docs
May 5, 2019
3a6038f
Merge pull request #38 from micronode/feature/accelerators
benfortuna May 5, 2019
8aa6498
Support for DynamoDB management including table creation, import and …
May 6, 2019
bae4dcc
Support removal of stale EC2 images (AMIs)
May 6, 2019
508f945
Support management of ECR repositories
May 6, 2019
248fa69
Support for automatic disabling of old API access keys
May 7, 2019
030cae6
Added letsencrypt and cloudwatch agent
May 7, 2019
f72d969
Support public and private routing
May 7, 2019
5125f01
Use template files for vhost configuration
May 7, 2019
701afc5
Refactoring
May 7, 2019
517cc90
Support creation of route53 zones, records and aliases
May 7, 2019
aa647bc
Support ecs cluster creation
May 7, 2019
4875afe
Refactoring
May 7, 2019
5f0b415
Support creation of vpc resources
May 7, 2019
3f20718
Refactoring
May 7, 2019
bc62309
Support for enhanced rds functions (cycle and snapshot)
May 7, 2019
3da8a5f
Support s3 bucket and notificaton creation
May 7, 2019
b2a3e51
Support rds instance and cluster provisioning
May 7, 2019
1e914c2
Merge pull request #39 from micronode/feature/accelerators
benfortuna May 7, 2019
5c860d5
Moved legacy stuff
May 8, 2019
6ecddaa
Refactoring
May 9, 2019
3a0c5fb
Apply principle of least privilege through assume role for terraform …
May 10, 2019
444ccf8
Refactoring
May 10, 2019
58ff540
Updated docs
May 10, 2019
c1982af
Use templates for user data
May 10, 2019
924828c
Simplify environment lookup
May 10, 2019
30c0671
Support for log group management
May 10, 2019
21c4f34
Register for service discovery
May 10, 2019
66bd78e
Install chrony for ec2 time sync
May 10, 2019
efabd4c
Enable bastion by default
May 10, 2019
38250b0
Deploy bastion in default (public) vpc
May 10, 2019
0b55aed
Refactoring
May 10, 2019
7a5f5eb
Refactoring
May 10, 2019
e048079
Added blueprint skeleton
May 10, 2019
d59106f
Added blueprint skeleton
May 10, 2019
3d0e2c3
Added blueprint skeleton
May 10, 2019
4be9733
Added blueprint skeleton
May 10, 2019
9410037
Added blueprint skeleton
May 10, 2019
9770f97
Refactoring
May 10, 2019
b4ed57f
Refactoring
May 10, 2019
4a794be
Refactoring
May 13, 2019
c1977db
Refactoring
May 13, 2019
d43c5b5
Updated docs
May 15, 2019
cdc8bd3
Refactoring
May 15, 2019
03f9766
Refactoring
May 15, 2019
592b6d3
Added sample manifests for common architectures
May 15, 2019
a6c2108
Added tools for common lambda layers
May 16, 2019
b0b2fca
Merge pull request #42 from micronode/feature/accelerators
benfortuna May 16, 2019
0213a92
Added manifests execution script
May 16, 2019
35e6ce3
Use argparse for improved options support
May 17, 2019
1568061
Support mounting additional volumes for blueprint inputs
May 17, 2019
5a7bd3d
Added manifest examples
May 17, 2019
f51b748
Support additional overrides for blueprint inputs
May 17, 2019
5b40806
Support overriding default ssh key
May 17, 2019
3d19c09
Support vpc lookup using tags
May 19, 2019
261127c
Added fqdn for easier reference in scripts
May 21, 2019
8314d9b
Use CNAME as likely to change often
May 21, 2019
65c70cc
Added fqdn for easier reference in scripts
May 21, 2019
d7ed016
Fixed formatting
May 21, 2019
acfc0c1
Added solr blueprint
May 21, 2019
d83be03
Merge pull request #44 from micronode/feature/accelerators
benfortuna May 21, 2019
aa9edc0
Update README.md
benfortuna May 21, 2019
3914d35
Destroy constellations in reverse order
May 22, 2019
df6d443
Include proxy in pip command
May 22, 2019
6005a89
Support http proxy
May 22, 2019
c2cf4ed
Define required constellations for bedrock blueprints
May 22, 2019
909af84
Include required roles
May 22, 2019
53282af
Automatic layer build
May 22, 2019
04b3bb9
Set default manifest action
May 22, 2019
bf20894
Added script to apply actions on individual blueprints
May 22, 2019
80e199a
Use local backend to provision s3 bucket for terraform state
May 22, 2019
00614cd
Use name rather than id for consistency
May 22, 2019
e1f05d6
Update README.md
benfortuna May 23, 2019
8462b2e
Support override/optional ssh key
May 23, 2019
2ad1d4c
Merge pull request #45 from micronode/feature/accelerators
benfortuna May 28, 2019
b567964
Applied canonical formatting
May 28, 2019
8a779c4
Renamed manifest tool
May 30, 2019
33bd1f4
Freeze dependencies and run as non-root user
May 30, 2019
1faf63a
Support terraform canonical formatting
May 30, 2019
3d50650
Freeze dependencies
May 30, 2019
70da1d8
Use environment variables to set common configuration
May 31, 2019
bbcf329
Use AWS env vars for configuration
Jun 14, 2019
d872041
Upgrade to terraform 0.12
Jun 17, 2019
22fd80b
Simplified terraform backend config
Jun 27, 2019
d3c27b2
Simplified terraform backend config
Jun 27, 2019
51d0c90
Use more specific var names to avoid conflict with other blueprints
Jun 27, 2019
d2b9adb
Package for pypi
Jun 27, 2019
2700372
Package for pypi
Jun 28, 2019
adf6ba1
Run as root to support consistent access to host filesystem (note all…
Jul 1, 2019
fcc1e0e
Support additional args for terraform plan
Jul 1, 2019
9a4cad9
Added region var to support fine-grained policies
Jul 1, 2019
960da4e
Use environment variables to set common configuration
Jul 1, 2019
4a636ff
Support additional args for terraform init
Jul 1, 2019
e8d00d7
Added policy for terraform state
Jul 1, 2019
4a65c11
Added ecs service codedeploy
Jul 12, 2019
adeaf41
Support network mode config
Jul 12, 2019
2b13018
Support overriding the terraform state bucket
Jul 12, 2019
01cc2bb
Formatting
Jul 12, 2019
c9597d0
Support overriding the terraform state bucket
Jul 20, 2019
df88cac
Update README.md
benfortuna Jul 22, 2019
10b4eed
Added openstack support
Jul 27, 2019
8891319
Consolidate args variable
Jul 27, 2019
4c34bca
Manage lock with dynamodb
Jul 27, 2019
64ebc31
Merge remote-tracking branch 'origin/develop' into feature/accelerators
Jul 29, 2019
17123ab
Clean up script
Aug 6, 2019
281d512
Added s3cmd to support bucket object acl changes (required for Digita…
Aug 6, 2019
dd32550
Refactoring bastion blueprints
Aug 6, 2019
b5ccb1e
Refactoring cdn blueprints
Aug 6, 2019
e95dcc6
Added domain blueprint for digitalocean
Aug 6, 2019
57f78ce
Added blueprint for object storage file sync
Aug 6, 2019
5a766f8
Support digitalocean blueprints
Aug 6, 2019
58c2808
Refactoring
Aug 7, 2019
408fdd6
Support for global vars. Stop container gracefully
Aug 14, 2019
04544f7
Added block and object storage on digitalocean
Aug 20, 2019
1e68a37
Docker refactoring
Oct 7, 2019
c165f49
Template refactoring
Oct 7, 2019
ab956c0
Refactoring
benfortuna Oct 13, 2019
9389c42
Merge branch 'feature/accelerators' of github.com:micronode/bedrock i…
Oct 13, 2019
2974b18
Refactoring
Oct 13, 2019
56c17c3
Refactoring
Oct 13, 2019
4eb6aab
Updated to support multiple instances
Oct 14, 2019
f38149b
Refactoring
Oct 16, 2019
7e2fb12
Added floating ip support
Oct 16, 2019
8ddef12
Added letsencrypt support
Oct 16, 2019
08f771d
Added ssl certificate
Oct 16, 2019
f8f38a3
Support additional terraform actions
Oct 16, 2019
e255319
Added json result output
Oct 16, 2019
bcfdd7c
Merge pull request #60 from micronode/feature/accelerators
benfortuna Oct 16, 2019
f7c8db3
Use git tag for labeling docker images
Oct 21, 2019
0320331
Support configuring multiple docker tags
Oct 21, 2019
b1fc4fb
Use git tag for labeling docker images
Oct 21, 2019
f7f79e8
Use git tag for labeling docker images
Oct 21, 2019
ada5713
Apply MIT license
Oct 22, 2019
a70e345
Updated package name
Oct 22, 2019
663a6fd
Documentation
Oct 22, 2019
e8bfafc
Updated package name
Oct 22, 2019
d0f0fd3
Added pypi deployment
Oct 22, 2019
93c6b30
Refactoring
Oct 22, 2019
232d415
Refactoring
Oct 22, 2019
9e7aed5
Use dynamic version from environment
Oct 22, 2019
0ab882b
Use dynamic version from environment
Oct 22, 2019
127ab3b
Use dynamic version from environment
Oct 22, 2019
e53b49f
Added pypi deployment
Oct 22, 2019
368da4b
Updated deployment config
Oct 22, 2019
2602c77
Fixed package build
Oct 22, 2019
9d46d47
Ignore build artefacts
Oct 22, 2019
97303e1
Refactoring
Oct 28, 2019
9b7c9cd
Refactoring
Oct 28, 2019
dcd5feb
Refactoring
Oct 29, 2019
135683d
Refactoring
Oct 29, 2019
ccaa16c
Convenience script for assume role
Feb 27, 2020
03ab3af
Clean up code
Mar 31, 2020
5eaab9a
Support automatic import of images from external registry
Apr 1, 2020
891aa6f
Fixed assume role for blueprint admins
Apr 1, 2020
f65a5ba
Add path to all bedrock IAM roles
Apr 1, 2020
53ee498
Bind docker socket to support docker-based blueprints
Apr 1, 2020
0679328
Use consistent flag for cli file references
Apr 1, 2020
3894327
Relocated cli tool
Apr 1, 2020
8a9e125
Relocated cli tool
Apr 1, 2020
3ed2ad5
Add path to all bedrock IAM roles
Apr 1, 2020
96c97e0
Refactoring
Apr 1, 2020
2a1a71c
Support validation on build
Apr 7, 2020
f4d66c7
Refactoring
Apr 7, 2020
2099f27
Configurable role path
Apr 7, 2020
56d80e1
More fine-grained pass role
Apr 7, 2020
0836374
Consolidate iam policies
Apr 7, 2020
77cc3e7
Added role description
Apr 8, 2020
83765f3
Added role policy description
Apr 8, 2020
41b4aba
Refactoring
Apr 8, 2020
fbfbdd4
Support app mesh and cluster without a load balancer
Apr 9, 2020
31d5181
Added spotfleet cluster support
Apr 10, 2020
6ad7b69
Refactoring
Apr 21, 2020
c16e30e
Clean up
Apr 21, 2020
ca7ad12
Added persistent volume support
Apr 21, 2020
bc9c2d2
Run terraform in Docker for portability and consistency with blueprin…
May 8, 2020
0d92459
Refactored to use public modules
May 13, 2020
e8cc7e5
Refactored to use public modules
May 27, 2020
8b65cd4
Added mkdocs
Jul 23, 2020
b981951
Added mkdocs
Jul 23, 2020
acb2ac2
Refactoring
Jul 23, 2020
9c03b9a
Manage organizations in Terraform Cloud
Aug 4, 2020
2536ebf
Refactored to figurate module
Aug 11, 2020
f6d165a
Update README.md
benfortuna Oct 19, 2020
e0c5a76
Provision tenancy DNS with Cloudmap
Nov 20, 2020
10b6a02
Added tenancy defaults for storage, montoring and access
Nov 23, 2020
fc26ae5
Create docker-image.yml
benfortuna Nov 30, 2020
4c40af4
Merge remote-tracking branch 'origin/develop' into feature/accelerators
Nov 30, 2020
b45578b
Refactoring
Nov 30, 2020
1398517
Merge remote-tracking branch 'origin/develop' into feature/accelerators
Nov 30, 2020
634ff2c
Build ecr-repository
Nov 30, 2020
f43e9c9
Build ecr-repository
Nov 30, 2020
092ab3c
Build ecr-repository
Nov 30, 2020
bf28a6c
Build ecs-task-definition
Nov 30, 2020
44ccfe6
Added publish workflow
Dec 4, 2020
85c71aa
CLI moved to separate project
Dec 4, 2020
49def27
Ignore terraform generated artefacts
Dec 4, 2020
828e9aa
Merge pull request #65 from micronode/feature/accelerators
benfortuna Dec 4, 2020
b8b8f3f
Create docker-publish-gh.yml
benfortuna Dec 12, 2020
b88e820
Remove test stage
Dec 12, 2020
5c22615
Remove test stage
Dec 12, 2020
a432cc1
Use make for build
Dec 12, 2020
23aeb01
Use make for build
Dec 12, 2020
30fb5f0
Use make for build
Dec 12, 2020
2517185
Use make for build
Dec 12, 2020
f76ad65
Reorganise directory structure
Dec 27, 2020
15f281c
Reorganise directory structure
Dec 27, 2020
c8de476
Updated docker provider
Jan 21, 2021
0f11d63
Updated docker provider
Jan 21, 2021
0d93a14
Reorganise directory structure
Jan 21, 2021
650c6e9
Reorganise directory structure
Jan 21, 2021
f460059
Added support for s3 and terraform cloud backends
Mar 20, 2021
447b6b0
Added support for s3 and terraform cloud backends
Mar 20, 2021
6d6db6c
Added support for s3 and terraform cloud backends
Mar 20, 2021
960c8c8
Added support for s3 and terraform cloud backends
Mar 20, 2021
ac39262
Added support for tfe auth policy
Mar 20, 2021
b963a1e
Added support for tfe auth policy
Mar 20, 2021
08e46e7
Refactoring
Mar 20, 2021
b24b35f
Refactoring
Mar 20, 2021
3ee39f2
Added support for digital ocean firewalls
Mar 20, 2021
fe895aa
Added support for digital ocean firewalls
Mar 20, 2021
b1fedb9
Refactoring
Mar 21, 2021
9abe65e
Refactoring
Mar 21, 2021
88d0a62
Refactoring
Mar 21, 2021
a7815fa
Refactoring
Mar 21, 2021
af6ea34
Incorporate docker build configurations in CLI build tool
Jul 12, 2021
0f0d9ec
Incorporate docker build configurations in CLI build tool
Jul 12, 2021
0f3a426
Refactoring
Feb 4, 2022
bc5c658
Removed accidental build artefacts
Feb 4, 2022
364ab79
Merge remote-tracking branch 'origin/feature/refactor-blueprints' int…
Feb 4, 2022
b28421e
Refactoring
Feb 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 4 additions & 7 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ on:
branches: [ develop ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build aws/ecr-repository
run: cd blueprints/aws/ecr-repository && DOCKER_TAGS=$(date +%s),latest make build
- name: Build aws/ecs-task-definition
run: cd blueprints/aws/ecs-task-definition && DOCKER_TAGS=$(date +%s),latest make build
- name: Build aws/ecr
run: cd aws-ecr && DOCKER_TAGS=$(date +%s),latest make build
- name: Build aws/ecs
run: cd aws-ecs && DOCKER_TAGS=$(date +%s),latest make build
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish-gh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:

#docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
#docker push $IMAGE_ID:$VERSION
cd blueprints/aws/ecr-repository && make push
cd aws-ecr && make push
8 changes: 4 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Log into registry
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USER }} --password-stdin

- name: Publish aws/ecr-repository
run: cd blueprints/aws/ecr-repository && make push
- name: Publish aws/ecr
run: cd aws-ecr && make push

- name: Publish aws/ecs-task-definition
run: cd blueprints/aws/ecs-task-definition && make push
- name: Publish aws/ecs
run: cd aws-ecs && make push
18 changes: 18 additions & 0 deletions aws-batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# AWS Batch role configuration

Purpose: Provision IAM roles in AWS.

Rationale: Bedrock blueprints use IAM roles to restrict the privileges of the provisioner.

This script will create roles that has the following privileges:

* Access for managing Batch jobs specific to this blueprint
* Access to read/write Terraform state associated with the account

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| assume\_role\_account | AWS account ID for the role to assume into | string | - | yes |
| region | AWS default region | string | - | yes |

7 changes: 7 additions & 0 deletions aws-batch/job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| assume\_role\_account | AWS account ID for the role to assume into | string | - | yes |
| region | AWS default region | string | - | yes |

4 changes: 4 additions & 0 deletions aws-batch/job/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_batch_job_definition" "" {
name = ""
type = ""
}
44 changes: 44 additions & 0 deletions aws-batch/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* # AWS Batch role configuration
*
* Purpose: Provision IAM roles in AWS.
*
* Rationale: Bedrock blueprints use IAM roles to restrict the privileges of the provisioner.
*
* This script will create roles that has the following privileges:
*
* * Access for managing Batch jobs specific to this blueprint
* * Access to read/write Terraform state associated with the account
*/
data "aws_caller_identity" "current" {}

data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]

principals {
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
type = "AWS"
}
}
}

resource "aws_iam_role" "batch_admin" {
name = "bedrock-awsbatch-admin"
assume_role_policy = "${data.aws_iam_policy_document.assume_role_policy.json}"
}

resource "aws_iam_role_policy_attachment" "ec2_access" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2FullAccess"
role = "${aws_iam_role.batch_admin.name}"
}

resource "aws_iam_role_policy_attachment" "iam_passrole" {
policy_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/bedrock-cloudformation-passrole"
role = "${aws_iam_role.batch_admin.id}"
}

resource "aws_iam_role_policy_attachment" "ec2_instance_profile_fullaccess" {
policy_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/bedrock-ec2-instance-profile-fullaccess"
role = "${aws_iam_role.batch_admin.id}"
}
File renamed without changes.
13 changes: 13 additions & 0 deletions aws-chime/notification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# AWS Lambda function configuration

Deploy a lambda function.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| assume\_role\_account | AWS account ID for the role to assume into | string | - | yes |
| lambda\_path | The root path to lambda function source | string | `lambda` | no |
| region | AWS default region | string | - | yes |
| webhook\_url | Chime webhook URL | string | - | yes |

21 changes: 21 additions & 0 deletions aws-chime/notification/lambda/ChimeNotification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

import requests

webhook_url = os.environ['WebhookUrl']


def lambda_handler(event, context):
notify(webhook_url, get_message(event))


def get_message(event):
if 'Records' in event:
return event['Records'][0]['Sns']['Subject']

return event['Message']


def notify(url, content):
print(f"Publishing notification: {content}")
requests.post(url=url, json={'Content': content})
35 changes: 35 additions & 0 deletions aws-chime/notification/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* # AWS Lambda function configuration
*
* Deploy a lambda function.
*/
data "archive_file" "chime_notification" {
output_path = "chime_notification.zip"
type = "zip"
source_dir = "${var.lambda_path}"
}

data "aws_iam_role" "chime_notification" {
name = "bedrock-chime-notification-role"
}

resource "aws_lambda_function" "chime_notification" {
function_name = "ChimeNotification"
handler = "ChimeNotification.lambda_handler"
filename = "${data.archive_file.chime_notification.output_path}"
role = "${data.aws_iam_role.chime_notification.arn}"
runtime = "python3.6"
source_code_hash = "${data.archive_file.chime_notification.output_base64sha256}"
layers = ["arn:aws:lambda:ap-southeast-2:976651329757:layer:python-requests:2"]

environment {
variables {
WebhookUrl = "${var.webhook_url}"
}
}
}

resource "aws_cloudwatch_log_group" "chime_notification" {
name = "/aws/lambda/${aws_lambda_function.chime_notification.function_name}"
retention_in_days = 30
}
8 changes: 8 additions & 0 deletions aws-chime/notification/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "lambda_path" {
description = "The root path to lambda function source"
default = "lambda"
}

variable "webhook_url" {
description = "Chime webhook URL"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
provider "aws" {
version = ">= 2.7.0"
assume_role {
role_arn = "arn:aws:iam::${var.assume_role_account}:role/bedrock-nginx-admin"
role_arn = "arn:aws:iam::${var.assume_role_account}:role/bedrock-chime-admin"
}
}

Expand Down
16 changes: 16 additions & 0 deletions aws-cloudfront/distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| access\_log\_bucket | An S3 bucket used as a target for access logs | string | `` | no |
| aliases | A list of associated domain names that reference the distribution | list | `<list>` | no |
| assume\_role\_account | AWS account ID for the role to assume into | string | - | yes |
| bucket\_name | Name of target S3 bucket | string | - | yes |
| default\_root\_object | The default page when accessing the root URL of the distribution | string | `index.html` | no |
| default\_ttl | Default time-to-live (TTL) for objects in cache | string | `86400` | no |
| enabled | Indicates if distribution is enabled | string | `false` | no |
| error\_page | Error page returned for 404 errors | string | - | yes |
| hosted\_zone | Route53 zone for alias domain names | string | - | yes |
| price\_class | Specifies the edge locations based on price class | string | `PriceClass_100` | no |
| region | AWS default region | string | - | yes |

108 changes: 108 additions & 0 deletions aws-cloudfront/distribution/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
data "aws_caller_identity" "current" {}

data "aws_s3_bucket" "access_log" {
bucket = replace(var.access_log_bucket, "/\\A\\z/", format("%s-access-logs", data.aws_caller_identity.current.account_id))
}

data "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
}

data "aws_route53_zone" "primary" {
name = "${var.hosted_zone}."
}

//Function must live in us-east-1 and Terraform can't lookup across regions
//data "aws_lambda_function" "url_rewrite" {
// function_name = "CloudFrontRewrite"
//}

resource "aws_cloudfront_distribution" "distribution" {
enabled = var.enabled
price_class = var.price_class
default_root_object = var.default_root_object

custom_error_response {
error_code = 404
response_page_path = var.error_page
response_code = 404
}

aliases = var.aliases

origin = {
domain_name = data.aws_s3_bucket.bucket.bucket_domain_name
origin_id = "S3-${data.aws_s3_bucket.bucket.bucket}"
}

default_cache_behavior = {
viewer_protocol_policy = "allow-all"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]

forwarded_values = {
cookies = {
forward = "none"
}

query_string = false
}

target_origin_id = "S3-${data.aws_s3_bucket.bucket.bucket}"
default_ttl = var.default_ttl
}

ordered_cache_behavior {
path_pattern = "*+*"
viewer_protocol_policy = "allow-all"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]

forwarded_values = {
cookies = {
forward = "none"
}

query_string = false
}

target_origin_id = "S3-${data.aws_s3_bucket.bucket.bucket}"
default_ttl = var.default_ttl

lambda_function_association {
event_type = "viewer-request"
lambda_arn = "arn:aws:lambda:us-east-1:${data.aws_caller_identity.current.account_id}:function:CloudFrontRewrite:1"
include_body = false
}
}

logging_config {
bucket = data.aws_s3_bucket.access_log.bucket_domain_name
prefix = "cloudfront-${data.aws_s3_bucket.bucket.bucket}/"
}

restrictions {
geo_restriction {
restriction_type = "none"
}
}

viewer_certificate {
cloudfront_default_certificate = true

// minimum_protocol_version = "TLSv1.2_2018"
}
}

resource "aws_route53_record" "www" {
count = length(var.aliases)
zone_id = data.aws_route53_zone.primary.zone_id
name = element(var.aliases, count.index)
type = "CNAME"

alias {
evaluate_target_health = false
name = aws_cloudfront_distribution.distribution.id
zone_id = data.aws_route53_zone.primary.zone_id
}
}
16 changes: 16 additions & 0 deletions aws-cloudfront/distribution/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "aws" {
version = ">= 2.7.0"
region = "${var.region}"

assume_role {
role_arn = "arn:aws:iam::${var.assume_role_account}:role/bedrock-cloudfront-admin"
}
}

variable "region" {
description = "AWS default region"
}

variable "assume_role_account" {
description = "AWS account ID for the role to assume into"
}
16 changes: 16 additions & 0 deletions aws-cloudfront/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "aws" {
version = ">= 2.7.0"
region = "${var.region}"

assume_role {
role_arn = "arn:aws:iam::${var.assume_role_account}:role/bedrock-ec2-admin"
}
}

variable "region" {
description = "AWS default region"
}

variable "assume_role_account" {
description = "AWS account ID for the role to assume into"
}
12 changes: 12 additions & 0 deletions aws-cloudfront/rewrite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AWS Lambda function configuration

Deploy a lambda function.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| assume\_role\_account | AWS account ID for the role to assume into | string | - | yes |
| lambda\_path | The root path to lambda function source | string | `lambda` | no |
| region | AWS default region | string | - | yes |

5 changes: 5 additions & 0 deletions aws-cloudfront/rewrite/lambda/CloudFrontRewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
request.uri = request.uri.replace(/\+/g, '%2B');
callback(null, request);
};
6 changes: 6 additions & 0 deletions aws-cloudfront/rewrite/lambda/CloudFrontRewrite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re

def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']
request.uri = re.sub(r"\+", "%2B", request.uri)
return request
Loading