AWSTemplateFormatVersion: '2010-09-09'
Description: >-
  Version two. Identical to order-platform.yaml except that a notification
  topic has been added. Applying this with update-stack changes only what
  differs, rather than recreating the stack.

Parameters:
  EnvName:
    Type: String
    Default: dev
    AllowedValues: [dev, staging, prod]
    Description: Name every resource after this, so environments cannot collide.

Resources:
  ReceiptsBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub "orders-${EnvName}-receipts"

  OrdersTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Sub "orders-${EnvName}"
      AttributeDefinitions:
        - AttributeName: id
          AttributeType: S
      KeySchema:
        - AttributeName: id
          KeyType: HASH
      BillingMode: PAY_PER_REQUEST

  OrderQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Sub "orders-${EnvName}-queue"

  # The only addition. Everything above is unchanged, so an update leaves
  # those three resources exactly as they are.
  NotificationTopic:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: !Sub "orders-${EnvName}-notifications"

Outputs:
  BucketName:
    Description: Where receipts are written
    Value: !Ref ReceiptsBucket

  TableArn:
    Description: ARN of the orders table
    Value: !GetAtt OrdersTable.Arn

  QueueName:
    Description: Queue holding unprocessed orders
    Value: !Ref OrderQueue

  TopicArn:
    Description: Topic that fans out order notifications
    Value: !Ref NotificationTopic
