> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-Deploy テンプレートファイルの仕様

GS2-Deploy のテンプレートファイルの仕様に関する情報




GS2-Deployでスタックを作成する際に使用するテンプレートファイルの書式仕様です。
JSON形式、もしくはYAML形式で記述できます。

## セクションの種類

テンプレートは以下のセクションで構成されます。

| セクション | 必須 | 説明 |
| --------- | --- | --- |
| GS2TemplateFormatVersion | ✓ | テンプレートの形式を指定します。現在は　2019-05-01　のみ定義できます。 |
| Description | | テンプレートに関する説明等の記入ができます。 |
| Globals | | Alias属性（文字列の置き換え指定）の定義を行うセクションです。 |
| Resources | ✓ | スタックに含める、GS2の各サービスのリソースを定義します。 |
| Outputs | | マネージメントコンソールで表示する出力値を定義します。 |



**YAML**
```yaml
GS2TemplateFormatVersion: "2019-05-01"
Description: GS2-Account initialize template Version 2021-12-03

Globals:
  Alias:
    AccountNamespaceName: game-0001
    KeyNamespaceAccountAuthentication: account-encryption-key-namespace
    KeyAccountAuthentication: account-encryption-key
    GatewayNamespaceName: gateway-0001

Resources:
  GatewayNamespace:
    Type: GS2::Gateway::Namespace
    Properties:
      Name: ${GatewayNamespaceName}

  KeyNamespaceAccountAuthentication:
    Type: GS2::Key::Namespace
    Properties:
      Name: ${KeyNamespaceAccountAuthentication}

  KeyAccountAuthentication:
    Type: GS2::Key::Key
    Properties:
      NamespaceName: ${KeyNamespaceAccountAuthentication}
      Name: ${KeyAccountAuthentication}
    DependsOn:
      - KeyNamespaceAccountAuthentication

  AccountNamespace:
    Type: GS2::Account::Namespace
    Properties:
      Name: ${AccountNamespaceName}

Outputs:
  AccountNamespaceName: !GetAttr AccountNamespace.Item.Name
  KeyAccountAuthenticationKeyId: !GetAttr KeyAccountAuthentication.Item.KeyId
  GatewayNamespaceName: !GetAttr GatewayNamespace.Item.Name
```


### Globals

#### Alias

指定の文字列でResourcesセクション、Outputsセクションにある文字列の置き換えを行います。
左辺の文字列を `${...}` のように${}で囲んだ部分を、右辺の文字列で置き換えます。

置き換え指定の例: ${AccountNamespaceName}


**YAML**
```yaml
Globals:
  Alias:
    AccountNamespaceName: game-0001
```


### Resources

生成するリソースの定義を行います。Type属性、Properties属性 を持ち、必要であれば DependsOn属性を持ちます。


**YAML**
```yaml
Resources:
  KeyNamespaceAccountAuthentication:  # リソース定義の名前
    Type: GS2::Key::Namespace  # リソースの指定
    Properties:
      Name: ${KeyNamespaceAccountAuthentication}

  KeyAccountAuthentication:  # リソース定義の名前
    Type: GS2::Key::Key  # リソースの指定
    Properties:
      NamespaceName: ${KeyNamespaceAccountAuthentication}
      Name: ${KeyAccountAuthentication}
    DependsOn:  # 依存するリソース定義の名前の指定
      - KeyNamespaceAccountAuthentication  # KeyNamespaceAccountAuthentication の生成に依存

  AccountNamespace:  # リソース定義の名前
    Type: GS2::Account::Namespace  # リソースの指定
    Properties:
      Name: ${AccountNamespaceName}
```


#### Type

サービスに対し生成を行うリソースの指定。
各サービスの GS2-Deploy/CDK リファレンス ページ のエンティティ名を指定します。

例: `Type: GS2::Account::Namespace`

#### Properties

リソースの生成時にプロパティ値に与える値を指定します。

#### DependsOn

リソースが他のリソースに続けて作成されるように、依存しているリソースの名前を指定します。

### Outputs

値を保持し、後ほどマネージメントコンソールなどを通して値を確認できるようにする出力値を定義します。


**YAML**
```yaml
Outputs:
  AccountNamespaceName: !GetAttr AccountNamespace.Item.Name
  KeyAccountAuthenticationKeyId: !GetAttr KeyAccountAuthentication.Item.KeyId
  GatewayNamespaceName: !GetAttr GatewayNamespace.Item.Name
```


## 関数

GS2-Deploy のテンプレート内では関数が使用できます。

### !GetAttr

`!GetAttr` タグを使用することで各リソースの生成結果のプロパティ値を取得することができます。


**YAML**
```yaml
AccountNamespace:
Type: GS2::Account::Namespace
Properties:
Name: ${AccountNamespaceName}
Outputs:
AccountNamespaceName: !GetAttr AccountNamespace.Item.Name
```


この例では、`AccountNamespace`　で　`GS2::Account::Namespace`　を指定していますので, GS2-Account で `Namespace` が生成されます。
その結果が `AccountNamespace` に取得され、 `AccountNamespace.Item` に NameSpaceモデル が入っています。
`!GetAttr AccountNamespace.Item.Name` で、ネームスペース名が取得できます。

また、`!GetAttr` タグには予約語として以下が割り当てられており、値の取得が可能です。

| キー値 | 型 | 説明 |
| -- | -- | --- |
| Gs2::Region | string | リージョンの種類 |
| Gs2::OwnerId | string | オーナーID |

### !Join

`!Join` タグは、続く配列の文字列の連結を行います。区切り記号（デリミタ）が指定できます。

フォーマット: `！Join [ 区切り記号の指定, [連結する文字列のリスト] ]`


**YAML**
```yaml
  QueueNamespace:
    Type: GS2::JobQueue::Namespace
    Properties:
      Name: ${QueueNamespaceName}
      PushNotification:
        GatewayNamespaceId: !Join
          - ':'
          - - 'grn'
            - 'gs2'
            - !GetAttr Gs2::Region
            - !GetAttr Gs2::OwnerId
            - 'gateway'
            - ${GatewayNamespaceName}
```





