Skip to content

aws-ia/terraform-aws-amplify-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

  • Conditional and Dynamic Resource Creation
  • Automatic and Manual Branch Creation Support
  • Automatic and Manual Branch Deletion Support
  • Automatic Build for Branches Support
  • Customizable Automatic Branch Creation Patterns Support
  • Pull Request Previews Support
  • CodeCommit, GitHub, GitLab support with examples
  • Related workshop for deeper explanation

Basic Usage - CodeCommit Repo with Automatic Branch Creation

// This is a template file for a basic deployment.
// Modify the parameters below with actual values
module "sample-qs" {
  // location of the module - can be local or git repo
  source = "aws-ia/amplify-app/aws"

  app_name = "my-app"
  create_codecommit_repo = true
  lookup_existing_codecommit_repo = false
  // see /examples for sample_build_spec
  path_to_build_spec = "/path/to/your/build/spec/file"

  // Auto Branch Creation
  enable_auto_branch_creation   = true
  enable_auto_branch_deletion   = true
  auto_branch_creation_patterns = ["main"]
  enable_auto_build             = true
  enable_app_pr_preview   = true
  app_framework                     = "Something bloated and hard to maintain"

  // - Custom Domain -
  create_domain_associations = false
  domain_name                = "yourdomain.com"
  domain_associations = {
    core = {
      branch_name = "main"
      prefix      = ""
    },
    www = {
      branch_name = "main"
      prefix      = "www"
    },
  }

  custom_rewrite_and_redirect = {
    // Static website rewrite/redirect
    static_site = {
      source = "/<*>"
      status = "404"
      target = "/index.html"
    },
    // Rewrite/redirect for single page apps - default if you don't specify anything else
    # single_page_app = {
    #   source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
    #   status = "200"
    #   target = "/index.html"
    # },
    // Rewrite/redirect for `yourdomain.com/app2` to `yourotherdomain.com`
    # app2 = {
    #   source = "/app2"
    #   status = "302"
    #   target = "https://yourotherdomain.com"
    # },
  }
}

Examples

Contributing

See the CONTRIBUTING.md file for information on how to contribute.

Workshop

For more information, check out my workshop Automating Deployment of AWS Amplify Apps with Terraform

Requirements

Name Version
terraform >= 1.0.7
aws >= 4.0.0, < 5.0.0
awscc >= 0.24.0

Providers

Name Version
aws >= 4.0.0, < 5.0.0

Modules

No modules.

Resources

Name Type
aws_amplify_app.sample_app resource
aws_amplify_branch.manual resource
aws_amplify_domain_association.amplify_domain_association resource
aws_codecommit_repository.codecommit_repo resource
aws_iam_role.amplify_codecommit resource
aws_iam_user.gitlab_mirroring resource
aws_iam_user_policy.gitlab_mirroring_policy resource
aws_codecommit_repository.test data source
aws_iam_policy_document.amplify_trust_relationship data source
aws_region.current data source
aws_ssm_parameter.ssm_github_access_token data source

Inputs

Name Description Type Default Required
amplify_codecommit_role_name Name for the role Amplify will use to access the CodeCommit repo string "amplify-codecommit" no
app_framework Framework for the autocreated branch. string null no
app_name The name of the Sample Amplify Application. string "sample-amplify-app" no
app_tags Tags for your Amplify App. map(string) null no
auto_branch_creation_patterns Automated branch creation glob patterns for the Amplify app. Ex. feat*/* list(any)
[
"main"
]
no
build_spec The actual content of your build_spec. Use if 'path_to_build_spec' is not defined. string null no
codecommit_repo_default_branch The default branch for the CodeCommit repo string "main" no
codecommit_repo_description The description for the CodeCommit repo string "The CodeCommit repo created during the Terraform deployment" no
codecommit_repo_name CodeCommit repo name string "codecommit_repo" no
create_codecommit_repo Conditional creation of CodeCommit repo bool false no
create_domain_associations Enables default association of your domain with the 'main' branch of the Amplify App. bool false no
custom_rewrite_and_redirect Custom rewrites and redirects for the domain associations. map(any) {} no
domain_associations The domains/subdomains you wish to associate with the Amplify App. These are mapped to git branches. map(any) {} no
domain_name The name of your domain. Ex. naruto.ninja string "example.com" no
enable_app_pr_preview Enables pull request previews for the autocreated branch. bool false no
enable_auto_branch_creation Enables automated branch creation for the Amplify app. bool false no
enable_auto_branch_deletion Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository. bool false no
enable_auto_build Enables auto-building of autocreated branches for the Amplify App. bool false no
enable_gitlab_mirroring Enables GitLab mirroring to the option AWS CodeCommit repo. bool false no
enable_performance_mode Enables performance mode for the branch. This keeps cache at Edge Locations for up to 10min after changes. bool false no
environment_variables Global environment variables for your Amplify App. These will only appear in the AWS Management Console if a git repo is connected. map(string) null no
existing_codecommit_repo_name Name of existing CodeCommit repo string null no
existing_repo_url URL for the existing repo. string null no
github_access_token Optional GitHub access token. Only required if using GitHub repo. string null no
gitlab_mirroring_iam_user_name The IAM Username for the GitLab Mirroring IAM User. string null no
gitlab_mirroring_policy_name The name of the IAM policy attached to the GitLab Mirroring IAM User string "gitlab_mirroring_policy" no
lookup_existing_codecommit_repo Conditional fetch of existing CodeCommit repo bool false no
lookup_ssm_github_access_token IMPORTANT!
Conditional data fetch of SSM parameter store for GitHub access token.
To ensure security of this token, you must manually add it via the AWS console
before using.
bool false no
manual_branches List of manual branches you wish to create. map(any) {} no
path_to_build_spec The path to the location of your build_spec file. Use if 'build_spec' is not defined. string null no
ssm_github_access_token_name The name (key) of the SSM parameter store of your GitHub access token string null no
tags Tags to apply to resources map(any)
{
"IAC_PROVIDER": "Terraform"
}
no
wait_for_verification If set to 'true', the resource will wait for the domain association status to change to 'PENDING_DEPLOYMENT' or 'AVAILABLE'. Setting this to false will skip the process. Default is set to 'false'. bool false no

Outputs

Name Description
amplify_app_arn The ARN for the Amplify App
amplify_app_default_domain The default domain for the Amplify App
amplify_app_id The App ID for the Amplify App
amplify_app_production_branch The production branch for the Amplify App
amplify_app_tags_all All tags for the Amplify App
aws_current_region The current AWS region for your session