awscc_amplify_app (Resource)

The AWS::Amplify::App resource creates Apps in the Amplify Console. An App is a collection of branches.

Example Usage

Basic App

To use awscc_amplify_app to create a basic Amplify App:

resource "awscc_amplify_app" "example" {
  name = "app"
  // replace with your repo URL - must also ensure Amplify has permissions to access the repo
  // GitHub instructions: https://docs.aws.amazon.com/amplify/latest/userguide/setting-up-GitHub-access.html
  repository = "https://github.com/example/app"

  # The default build_spec added by the Amplify Console for React.
  build_spec = <<-EOT
    version: 0.1
    frontend:
      phases:
        preBuild:
          commands:
            - yarn install
        build:
          commands:
            - yarn run build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
  EOT

  # The default rewrites and redirects added by the Amplify Console.
  custom_rules = [
    {
      source = "/<*>"
      status = "404"
      target = "/index.html"
    },
  ]
  environment_variables = [
    {
      name  = "Environment"
      value = "PROD"
    },
  ]
  tags = [
    {
      key   = "Modified By"
      value = "AWSCC"
    }
  ]
}

Repository with Tokens

When creating a new Amplify app with the repository argument, you also need to set oauth_token or access_token for authentication. For GitHub, see this AWS documentation and set access_token as follows:

resource "awscc_amplify_app" "example" {
  name       = "app"
  repository = "https://github.com/example/app"

  # GitHub personal access token
  access_token = "..."

  tags = [
    {
      key   = "Modified By"
      value = "AWSCC"
    }
  ]
}

You can omit access_token if you import an existing Amplify App created by the Amplify Console (using OAuth for authentication).

Auto Branch Creation

resource "awscc_amplify_app" "example" {
  name = "app"

  auto_branch_creation_config = {
    # Enable auto branch creation
    enable_auto_branch_creation = true
    # Enable auto build for the created branch.
    enable_auto_build = true

    # The default patterns added by the Amplify Console.
    auto_branch_creation_patterns = [
      "*",
      "*/**",
    ]
  }

  tags = [
    {
      key   = "Modified By"
      value = "AWSCC"
    }
  ]
}

Basic Authorization

resource "awscc_amplify_app" "example" {
  name = "app"

  basic_auth_config = {
    enable_basic_auth = true
    username          = "your-username"
    password          = "your-password"
  }

  tags = [
    {
      key   = "Modified By"
      value = "AWSCC"
    }
  ]
}

Rewrites and Redirects

resource "awscc_amplify_app" "example" {
  name = "app"

  custom_rules = [
    {
      # Reverse Proxy Rewrite for API requests
      # https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#reverse-proxy-rewrite
      source = "/api/<*>"
      status = "200"
      target = "https://api.example.com/api/<*>"
    },
    {
      # Redirects for Single Page Web Apps (SPA)
      # https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa
      source = "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>"
      status = "200"
      target = "/index.html"
    },
  ]

  tags = [
    {
      key   = "Modified By"
      value = "AWSCC"
    }
  ]
}

Schema

Required

Optional

Read-Only

Nested Schema for auto_branch_creation_config

Optional:

Nested Schema for auto_branch_creation_config.basic_auth_config

Optional:

Nested Schema for auto_branch_creation_config.environment_variables

Required:

Nested Schema for basic_auth_config

Optional:

Nested Schema for custom_rules

Required:

Optional:

Nested Schema for environment_variables

Required:

Nested Schema for tags

Required:

Import

Import is supported using the following syntax:

$ terraform import awscc_amplify_app.example <resource ID>