実践CloudFormation FSx編

続き！！

まずは作っていきましょう

## その１

![スクリーンショット 2020-10-06 3.04.42.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/253981/db37eca3-060f-8969-f4bb-69bbd665a701.png)

FSx.yamlファイルを使います。

## その２

![スクリーンショット 2020-10-06 3.06.13.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/253981/8b66d3ba-34c6-2b22-10d8-0cd29e071806.png)

PJPrefixのみをhandsonという名前に変更して次へ

そのままスタックの作成へ・・・

そして事前に作っていたものがこちら

![スクリーンショット 2020-10-06 3.32.40.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/253981/f9871b1d-99dc-3249-35fa-2980a5593c62.png)

ここも結構時間がかかります！！

ソースコードはこちら

今回はドキュメントをみながら解説できればと思います。
[ドキュメント](https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-fsx-filesystem.html)

```yaml
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  PJPrefix:
    Description: Enter a prefix of this system.
    Type: String
    Default: "test"
    AllowedPattern: "[a-zA-Z][a-zA-Z0-9][ -~]*"
    ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
  StorageCapacity:
    Description: "Storage Capacity"
    Type: "Number"
    Default: 32
    MinValue: 32
    MaxValue: 65536
    ConstraintDescription: must be at least 32Gib to 65536Gib.
  WeeklyMaintenanceStartTime:
    Description: "Weekly Maintenance Time"
    Type: String
    Default: "2:20:30"
    AllowedPattern: "^[1-7]:([0-1][0-9]|2[0-3]):[0-5][0-9]$"
    ConstraintDescription: "d:HH:MM d = 1~7 HH = 00~23 MM = 00~59"
  DailyAutomaticBackupStartTime:
    Description: "Daily backup start time"
    Type: String
    Default: "16:30"
    AllowedPattern: "^([0-1][0-9]|2[0-3]):[0-5][0-9]$"
    ConstraintDescription: "HH:MM HH = 00~23 MM = 00~59"
  AutomaticBackupRetentionDays:
    Description: "Backup Retention Period"
    Type: Number
    Default: 7
    MinValue: 0
    MaxValue: 35
    ConstraintDescription: The number of days to keep the automatic backup. The default is to keep the backup for seven days. Setting this value to 0 disables the creation of automatic backups. The maximum retention period for a backup is 35 days.

Resources:
  WindowsSelfManagedADFileSystemWithAllConfigs:
    Type: "AWS::FSx::FileSystem"
    Properties:
      FileSystemType: "WINDOWS"
      StorageCapacity: !Ref StorageCapacity
      StorageType: "SSD"
      SubnetIds:
        - { "Fn::ImportValue": !Sub "${PJPrefix}-private-subnet-a" } # VPCを合わせるPrivate
        - { "Fn::ImportValue": !Sub "${PJPrefix}-private-subnet-c" }
      SecurityGroupIds:
        - { "Fn::ImportValue": !Sub "${PJPrefix}-fsx-sg" }
      Tags:
        - Key: Name
          Value: !Sub ${PJPrefix}-file-server
      WindowsConfiguration:
        ActiveDirectoryId: { "Fn::ImportValue": !Sub "${PJPrefix}-windows-ad" }
        ThroughputCapacity: 16
        WeeklyMaintenanceStartTime: !Ref WeeklyMaintenanceStartTime
        DailyAutomaticBackupStartTime: !Ref DailyAutomaticBackupStartTime
        AutomaticBackupRetentionDays: !Ref AutomaticBackupRetentionDays
        DeploymentType: "MULTI_AZ_1"
        PreferredSubnetId: { "Fn::ImportValue": !Sub "${PJPrefix}-private-subnet-a" } # ADのサブネットをVPC合わせる
        CopyTagsToBackups: false

Outputs:
  WindowsSelfManagedADFileSystemWithAllConfigs:
    Description: WindowsSelfManagedADFileSystem
    Value: !Ref WindowsSelfManagedADFileSystemWithAllConfigs
    Export:
      Name: !Sub "${PJPrefix}-fsx"

```

[WorkSpaces編](https://qiita.com/kazumasamatsumo/private/0d2e2991bf674a894103)