/terraform-aws-amplify

Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks.

Primary LanguageHCLApache License 2.0Apache-2.0

Terraform AWS AMPLIFY

Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks.

Terraform Licence tfsec static-checks


We eat, drink, sleep and most importantly love DevOps. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy Bigger problems are always solved by breaking them into smaller manageable problems. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller connected yet manageable pieces within the infrastructure.

This module is basically combination of Terraform open source and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.

We have fifty plus terraform modules. A few of them are comepleted and are available for open source usage while a few others are in progress.

Prerequisites

This module has a few dependencies:

Examples

IMPORTANT: Since the master branch used in source varies based on new modifications, we suggest that you use the release versions here.

Simple Example

Here is an example of how you can use this module in your inventory structure:

module "amplify" {
 source = "../"
 name        = "amplify"
 environment = "test"
 label_order = ["name", "environment"]
 amplify_enabled        = true
 environment_name       = "prod"
 domain_name            = ["newloop.eu", "newloop.dk"]
 amplify_repository     =  "https://github.com/clouddrove-sandbox/terraform-aws-amplify"
 access_token           = "ghxxxxxm06Sd3KqkafBVu0xzcxcxcv0EA8AK"
 amplify_branch_name    = "main"
 sub_domain_prefix_name = "scan"
 deployment_artifacts   = "app-example-deployment"
 stack_name             = "amplify-app-example"
 branch_framework       = "React"
 branch_stage           = "PRODUCTION"
 branch_environment_variables = {
 ENV = "test"
 }
 amplify_app_environment_variables = {
 REACT_APP_API_SERVER = ""
 }
 custom_rules = [
 {
 source = "/01/<p01>/21/<p21>"
 status = "302"
 target = "/?p01=<p01>&p21=<p21> "
 }
 ]
}

Inputs

Name Description Type Default Required
access_token Personal access token for a third-party source string "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" no
amplify_app_environment_variables The environment variables for the Amplify app map(string) {} no
amplify_enabled Flag to control the amplify creation. bool true no
amplify_repository The repository for the Amplify app string "https://github.com/clouddrove-sandbox/terraform-aws-amplify-app" no
auto_branch_creation_config The automated branch creation configuration for the Amplify app
object({
basic_auth_credentials = optional(string)
build_spec = optional(string)
enable_auto_build = optional(bool)
enable_basic_auth = optional(bool)
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
framework = optional(string)
pull_request_environment_name = optional(string)
stage = optional(string)
})
null no
auto_branch_creation_patterns The automated branch creation glob patterns for the Amplify app list(string) [] no
backend_enable Enables backend environment creation for the Amplify app bool false no
branches n/a
object({
branch_name = string
framework = optional(string)
display_name = optional(string)
description = optional(string)
stage = optional(string)
enable_auto_build = optional(bool)
ttl = optional(number)
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
})
n/a yes
build_spec The build specification (build spec) for the Amplify app.
If not provided then it will use the amplify.yml at the root of your project / branch.
string null no
custom_rules The custom rules to apply to the Amplify App
list(object({
condition = optional(string)
source = string
status = optional(string)
target = string
}))
[] no
deployment_artifacts Name of deployment artifacts. string "app-example-deployment" no
description The description for the Amplify app string null no
domain_name Domain name for the domain association. list(any) [] no
enable_auto_branch_creation Enables automated branch creation for the Amplify app bool false no
enable_basic_auth Enables basic authorization for the Amplify app.
This will apply to all branches that are part of this app.
bool false no
enable_branch_auto_build Enables auto-building of branches for the Amplify App bool true no
enable_branch_auto_deletion Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository bool false no
environment Environment (e.g. prod, dev, staging). string "" no
environment_name Amplify environment name for the pull request. string "prod" no
label_order Label order, e.g. name,application. list(any) [] no
managedby ManagedBy, eg 'CloudDrove' string "hello@clouddrove.com" no
name Name (e.g. app or cluster). string "" no
oauth_token The OAuth token for a third-party source control system for the Amplify app.
The OAuth token is used to create a webhook and a read-only deploy key.
The OAuth token is not stored.
string null no
platform The platform or framework for the Amplify app string "WEB" no
stack_name AWS CloudFormation stack name of a backend environment. string "amplify-app-example" no
sub_domain_prefix_name Prefix setting for the subdomain. string "scam" no
ttl Content Time To Live (TTL) for the website in seconds. number null no

Outputs

Name Description
arn Amplify App ARN
default_domain Amplify App domain (non-custom)
name Amplify App name

Testing

In this module testing is performed with terratest and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a GO environment in your system.

You need to run the following command in the testing folder:

  go test -run Test

Feedback

If you come accross a bug or have any feedback, please log it in our issue tracker, or feel free to drop us an email at hello@clouddrove.com.

If you have found it worth your time, go ahead and give us a ★ on our GitHub!

About us

At CloudDrove, we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.

We are The Cloud Experts!


We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.