LoginSignup
4
0

More than 1 year has passed since last update.

AWS Amplifyをterraformで管理する際の引数解説

Last updated at Posted at 2023-04-27

誰向けの記事か

・AWS Amplifyをterraformで管理しようとしている人
かつ
・公式ドキュメントをみてもイマイチ各引数の動作イメージが湧かなかった人

概要

・この記事はAWS Amplifyをterraformで管理する際、各引数が動作をするのかを解説した記事です。
・自分で構築する際、公式ドキュメントだけだと(英語なので)実際にどういった動作をするのか分からなかったので記事としてまとめました。
・全ての引数は網羅できていません、主要と思われるものだけ載せています。

詳細は公式ドキュメントを参照してください

amplify.tf

resource "aws_amplify_app" "amplify-app" {
  # Amplifyのアプリ名、AWSコンソール上などに表示される
  name = "app-name"
  # リポジトリのURL
  repository = "https://github.com/test/test_repo"
  # リポジトリのアクセスに必要なトークン、コードの読み取り権限とWebhookの作成権限が必要
  access_token = "xxxxxxxxxxxxxxxxx"

  # trueだとauto_branch_creation_patternsに一致するブランチgit側に作成された時、Amplifyに当該ブランチが連携される
  enable_auto_branch_creation = true
  # trueだとブランチがgit側から削除された時、Amplify側でも削除される
  enable_branch_auto_deletion = true
  # ブランチの正規表現パターン
  auto_branch_creation_patterns = [
    "*",
    "*/**",
  ]

  # デプロイの際に実行されるビルド設定、AWSコンソールから手動でブランチを作成した場合に使用
  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


  # 自動連携されたブランチに適応される設定
  # auto_branch_creation_patternsに一致するブランチgit側に作成され、Amplifyに連携された時に適応される
  # AWSコンソール上でブランチを連携した場合は適応されない
  auto_branch_creation_config {
    content {
      # ビルド設定、この設定が無い場合は前述のbuild_specが適応される
      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
      # trueだとブランチに更新があった時にAmplify側に自動的にビルド&デプロイされる
      enable_auto_build = true
      # tureだと自動デプロイされたブランチにBasic認証がかかる
      enable_basic_auth = true
      # Basic認証のユーザー名とパスワード
      basic_auth_credentials = base64encode("develop:develop123")
    }
  }

  # trueにすると全てのブランチにBasic認証がかかる
  enable_basic_auth = true
  # 全てのブランチにBasic認証をかける場合のユーザー名とパスワード
  basic_auth_credentials = base64encode("admin:admin1234")


  # 環境変数の設定、設定できる変数は https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html を参照
  environment_variables = {
    // ビルドに使うNode.jsのバージョン
    _LIVE_UPDATES = "[{\"name\":\"Node.js version\",\"pkg\":\"node\",\"type\":\"nvm\",\"version\":\"16.15.0\"}]"
  }

  # 通信のカスタムルール、アクセス元を判別してアクセス先の書き換えが可能、リダイレクト等に用いる
  custom_rule {
    source = "/<*>"
    status = "404"
    target = "/index.html"
  }

}


4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0