Parameters:
  ANumber:
    Type: Number
    Default: 1
Transform: 'AWS::LanguageExtensions'
Resources:
  CapacityReservation:
    Type: AWS::EC2::CapacityReservation
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ""]
      InstanceCount: 1
      InstanceType: t2.micro
      InstancePlatform: Linux/UNIX
  SsmParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: !GetAtt CapacityReservation.InstanceCount      # #/Value: expected type: String, found: Integer
  DocDBCluster:
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
    Type: AWS::DocDB::DBCluster
    Properties:
      BackupRetentionPeriod: 1
  TestCluster:
    Type: AWS::ECS::Cluster
  TestFargateExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy

  TestFargateTaskRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
  TestLogGroup:
    Type: AWS::Logs::LogGroup
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
  TestTaskDefinitionWithGetAtt:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Image: nginx:1.27.3-alpine3.20
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !GetAtt 'TestLogGroup.Arn'
              awslogs-region: !Ref 'AWS::Region'
              awslogs-stream-prefix: test-service
          Name: TestContainerDefinition
          PortMappings:
            - ContainerPort: 80
      Cpu: '256'
      ExecutionRoleArn: !GetAtt 'TestFargateExecutionRole.Arn'
      Memory: '512'
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      TaskRoleArn: !GetAtt 'TestFargateTaskRole.Arn'
Outputs:
  Value:
    Value: 1 # OK
  Sub:
    Value: !Sub ["${InstanceCount}", {"InstanceCount": 1}] # OK
  RefWithParameter:
    Value: !Ref ANumber # OK
  SubWithParameter:
    Value: !Sub "${ANumber}"  # OK
  SubWithGetAtt:
    Value: !Sub ["${InstanceCount}", {"InstanceCount": {"Fn::GetAtt": ["CapacityReservation", "InstanceCount"]}}] # Template error: every value of the context object of every Fn::Sub object must be a string or a function that returns a string
  Ipv4NetmaskLength:
    Value: !GetAtt CapacityReservation.InstanceCount # Template format error: Every Value member must be a string.
  String:
    Value: !Sub "${CapacityReservation.InstanceCount}"  # Template error: variable CapacityReservation.InstanceCount in Fn::Sub expression does not resolve to a string
  Join:
    Value: !Join [ "", [1]]  # OK
  JoinWithGetAtt:
    Value: !Join [ "", [!GetAtt CapacityReservation.InstanceCount]]  # Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.
  Boolean:
    Value: true # OK
  BooleanGetAtt:
    Value: !GetAtt CapacityReservation.EphemeralStorage  # Template format error: Every Value member must be a string.
  Length:
    Value: {Fn::Length: [1, 2, 3]} # OK
  DocDBClusterPort:
    Value: !GetAtt DocDBCluster.Port # OK
