Skip to content
Snippets Groups Projects
beta.ordbok.uib.no_stack.yaml 5.08 KiB
AWSTemplateFormatVersion: '2010-09-09'

Description: >
  Script to create S3 bucket, DNS (Route53) and Cloudfront distribution.

###############################################################################
Parameters:
###############################################################################

  DomainName:
    Type: String
    Description: The domain name.
    Default: 'ordbok.aws.uib.no'
    AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)
    ConstraintDescription: must be a valid DNS zone name
    
  DomainPrefix:
    Type: String
    Default: beta
    
  PriceClass:
    Type: String
    Description: The CloudFront distribution price class
    Default: 'PriceClass_100'
    AllowedValues:
      - 'PriceClass_100'
      #- 'PriceClass_200'
      #- 'PriceClass_All'
    
  CertificateArn:
    Type: String
    Default: ''

    
Conditions:
  UseDomain: !Not [!Or [!Equals [!Ref DomainName, ''], !Equals [!Ref CertificateArn, '']]]
  
###############################################################################
Resources:
###############################################################################

  DNS:
    Type: "AWS::Route53::RecordSet"
    Condition: UseDomain
    Properties:
      HostedZoneConfig:
        Comment: !Join ['', ['Hosted zone for ', !Ref 'DomainName']]
      HostedZoneName: !Join ['.', [!Ref DomainName, '']]
      Name: !Join ['.', [!Ref DomainPrefix, !Ref DomainName, '']]
      Type: A
      AliasTarget:
        HostedZoneId: xxxxxxxxxxx
        DNSName: !GetAtt Distribution.DomainName
      HostedZoneTags:
      - Key: Application
        Value: beta.ordbok.uib.no
      Tags:
        - Key: Application
          Value: !Ref DomainName
        
  WebBucket:
    Type: "AWS::S3::Bucket"
    Properties:
      BucketName: !Sub "${AWS::StackName}.aws.uib.no"
      VersioningConfiguration:
        Status: Enabled
      Tags:
        - Key: Application
          Value: !Ref DomainName