dcm4chee/dcm4chee-arc-ec2-psql-acmdns.yml [695:1101]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  ArcTCP8443TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 8443
      Protocol: TCP
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  ArcTCP11112Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - ForwardConfig:
            TargetGroups:
            - TargetGroupArn: !Ref ArcTCP11112TargetGroup
          Type: forward
      LoadBalancerArn:
        Ref: LoadBalancer
      Port: 11112
      Protocol: TCP
  ArcTCP11112TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckPort: 8080
      Port: 11112
      Protocol: TCP
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  ArcTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    DependsOn:
      - RDSInstance
    Properties:
      ContainerDefinitions:
      - Command:
        - !Sub ${AWS::Region}.compute.internal
        - dcm4chee-arc-psql.local
        Essential: false
        Image: docker/ecs-searchdomain-sidecar:1.0
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: Arc_ResolvConf_InitContainer
      - DependsOn:
        - Condition: SUCCESS
          ContainerName: Arc_ResolvConf_InitContainer
        Environment:
        - Name: JAVA_OPTS
          Value: -Xms256m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=2048m
            -Djava.net.preferIPv4Stack=true -agentlib:jdwp=transport=dt_socket,address=*:8787,server=y,suspend=n
        - Name: POSTGRES_HOST
          Value: !GetAtt 'RDSInstance.Endpoint.Address'
        - Name: POSTGRES_PORT
          Value: !GetAtt 'RDSInstance.Endpoint.Port'
        - Name: POSTGRES_DB
          Value: pacsdb
        - Name: POSTGRES_PASSWORD
          Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
        - Name: POSTGRES_USER
          Value: !Ref RDSDBUserName
        - Name: STORAGE_DIR
          Value: /storage/fs1
        - Name: WILDFLY_ADMIN_PASSWORD
          Value: !Ref AdminPASSWORD
        - Name: WILDFLY_ADMIN_USER
          Value: !Ref AdminUSER
        Essential: true
        Image: dcm4che/dcm4chee-arc-psql:5.23.1
        LinuxParameters: {}
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        MountPoints:
        - ContainerPath: /storage
          SourceVolume: storage
        Name: arc
        PortMappings:
        - ContainerPort: 8080
          HostPort: 8080
          Protocol: tcp
        - ContainerPort: 8443
          HostPort: 8443
          Protocol: tcp
        - ContainerPort: 9990
          HostPort: 9990
          Protocol: tcp
        - ContainerPort: 9993
          HostPort: 9993
          Protocol: tcp
        - ContainerPort: 8787
          HostPort: 8787
          Protocol: tcp
        - ContainerPort: 11112
          HostPort: 11112
          Protocol: tcp
      Cpu: !Ref ArchiveContainerCPU
      Memory: !Ref ArchiveContainerMemory
      ExecutionRoleArn:
        Ref: ArcTaskExecutionRole
      Family: dcm4chee-arc-psql-arc
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - EC2
      TaskRoleArn: !Ref ArcTaskRole
      Volumes:
        - Name: storage
          EFSVolumeConfiguration:
            AuthorizationConfig:
              AccessPointId: !Ref StorageAccessPoint
              IAM: ENABLED
            FilesystemId: !Ref FileSystem
            TransitEncryption: ENABLED
  ArcTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
      - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  ArcTaskRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      Policies:
      - PolicyDocument:
          Statement:
          - Action:
            - elasticfilesystem:ClientMount
            - elasticfilesystem:ClientWrite
            - elasticfilesystem:ClientRootAccess
            Condition:
              StringEquals:
                elasticfilesystem:AccessPointArn:
                  Ref: StorageAccessPoint
            Effect: Allow
            Principal: {}
            Resource:
            - !GetAtt 'FileSystem.Arn'
          Version: 2012-10-17
        PolicyName: ArcStorageVolumeMountPolicy
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  ECSAutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    DependsOn:
      - StorageNFSMountTarget1
      - StorageNFSMountTarget2
    Properties:
      VPCZoneIdentifier:
        - !Ref PublicSubnet1Id
        - !Ref PublicSubnet2Id
      LaunchConfigurationName: !Ref 'ContainerInstances'
      MinSize: '1'
      MaxSize: '4'
      DesiredCapacity: !Ref EC2InstanceCount
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
    UpdatePolicy:
      AutoScalingReplacingUpdate:
        WillReplace: 'true'
  ContainerInstances:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !FindInMap [AWSRegionToAMI, !Ref 'AWS::Region', AMIID]
      SecurityGroups:
            - !Ref DefaultSecurityGroup
      InstanceType: !Ref 'InstanceType'
      IamInstanceProfile: !Ref 'EC2InstanceProfile'
      KeyName: !Ref 'KeyName'
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          echo ECS_CLUSTER=${DCM4CHEECluster} >> /etc/ecs/ecs.config
          yum install -y aws-cfn-bootstrap bzip2 unzip git jq wget telnet java-11-amazon-corretto-headless
          /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}
          amazon-linux-extras install postgresql11 -y
          curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"  
          unzip awscliv2.zip  
          ./aws/install
          git clone https://github.com/dcm4che-dockerfiles/postgres-dcm4chee.git
          password=`aws secretsmanager get-secret-value --secret-id ${RDSDatabaseSecret} --query SecretString --output text | jq -r .password`
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/10_create-psql.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/20_create-fk-index.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/30_create-case-insensitive-index.sql
          wget https://sourceforge.net/projects/dcm4che/files/dcm4che3/5.23.2/dcm4che-5.23.2-bin.zip -P /tmp
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
        - arn:aws:iam::aws:policy/AmazonS3FullAccess
        - arn:aws:iam::aws:policy/SecretsManagerReadWrite
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: /
      Roles: [!Ref 'EC2Role']

  LdapService:
    Type: AWS::ECS::Service
    DependsOn:
      - LdapTCP389Listener
    Properties:
      Cluster: !GetAtt DCM4CHEECluster.Arn
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DeploymentController:
        Type: ECS
      DesiredCount: !Ref NumberofLDAPContainers
      LaunchType: FARGATE
      LoadBalancers:
      - ContainerName: ldap
        ContainerPort: 389
        TargetGroupArn: !Ref LdapTCP389TargetGroup
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups:
            - !Ref DefaultSecurityGroup
          Subnets:
            - !Ref PublicSubnet1Id
            - !Ref PublicSubnet2Id
      PropagateTags: SERVICE
      SchedulingStrategy: REPLICA
      ServiceRegistries:
        - RegistryArn: !GetAtt LdapServiceDiscoveryEntry.Arn
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: ldap
      TaskDefinition:
        Ref: LdapTaskDefinition
  LdapTCP389Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - ForwardConfig:
            TargetGroups:
            - TargetGroupArn:
                Ref: LdapTCP389TargetGroup
          Type: forward
      LoadBalancerArn:
        Ref: LoadBalancer
      Port: 389
      Protocol: TCP
  LdapTCP389TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 389
      Protocol: TCP
      Tags:
        - Key: project
          Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  LdapTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
      - Command:
        - !Sub ${AWS::Region}.compute.internal
        - dcm4chee-arc-psql.local
        Essential: false
        Image: docker/ecs-searchdomain-sidecar:1.0
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: Ldap_ResolvConf_InitContainer
      - DependsOn:
        - Condition: SUCCESS
          ContainerName: Ldap_ResolvConf_InitContainer
        Environment:
        - Name: POSTGRES_HOST
          Value: !GetAtt 'RDSInstance.Endpoint.Address'
        - Name: POSTGRES_PORT
          Value: !GetAtt 'RDSInstance.Endpoint.Port'
        - Name: POSTGRES_DB
          Value: pacsdb
        - Name: POSTGRES_PASSWORD
          Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
        - Name: POSTGRES_USER
          Value: !Ref RDSDBUserName
        - Name: STORAGE_DIR
          Value: /storage/fs1
        Essential: true
        Image: dcm4che/slapd-dcm4chee:2.4.56-23.1
        LinuxParameters: {}
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: ldap
        PortMappings:
        - ContainerPort: 389
          HostPort: 389
          Protocol: tcp
      Cpu: !Ref LDAPContainerCPU
      Memory: !Ref LDAPContainerMemory
      ExecutionRoleArn:
        Ref: LdapTaskExecutionRole
      Family: dcm4chee-arc-psql-ldap
      NetworkMode: awsvpc
      RequiresCompatibilities:
      - FARGATE
  LdapTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
      - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: ldap


Outputs:
  HTTPEndpoint:
    Description: The HTTP endpoint for Dcm4Chee
    Value: !Join
      - ''
      - - 'http://'
        - !GetAtt LoadBalancer.DNSName
        - ':8080/dcm4chee-arc/ui2'
  HTTPSEndpoint:
    Description: The HTTPS endpoint for Dcm4Chee
    Value: !Join
      - ''
      - - 'https://'
        - !GetAtt LoadBalancer.DNSName
        - ':8443/dcm4chee-arc/ui2'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



dcm4chee/dcm4chee-arc-ec2-psql.yml [640:1046]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  ArcTCP8443TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 8443
      Protocol: TCP
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  ArcTCP11112Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - ForwardConfig:
            TargetGroups:
            - TargetGroupArn: !Ref ArcTCP11112TargetGroup
          Type: forward
      LoadBalancerArn:
        Ref: LoadBalancer
      Port: 11112
      Protocol: TCP
  ArcTCP11112TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckPort: 8080
      Port: 11112
      Protocol: TCP
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  ArcTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    DependsOn:
      - RDSInstance
    Properties:
      ContainerDefinitions:
      - Command:
        - !Sub ${AWS::Region}.compute.internal
        - dcm4chee-arc-psql.local
        Essential: false
        Image: docker/ecs-searchdomain-sidecar:1.0
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: Arc_ResolvConf_InitContainer
      - DependsOn:
        - Condition: SUCCESS
          ContainerName: Arc_ResolvConf_InitContainer
        Environment:
        - Name: JAVA_OPTS
          Value: -Xms256m -Xmx2048m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=2048m
            -Djava.net.preferIPv4Stack=true -agentlib:jdwp=transport=dt_socket,address=*:8787,server=y,suspend=n
        - Name: POSTGRES_HOST
          Value: !GetAtt 'RDSInstance.Endpoint.Address'
        - Name: POSTGRES_PORT
          Value: !GetAtt 'RDSInstance.Endpoint.Port'
        - Name: POSTGRES_DB
          Value: pacsdb
        - Name: POSTGRES_PASSWORD
          Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
        - Name: POSTGRES_USER
          Value: !Ref RDSDBUserName
        - Name: STORAGE_DIR
          Value: /storage/fs1
        - Name: WILDFLY_ADMIN_PASSWORD
          Value: !Ref AdminPASSWORD
        - Name: WILDFLY_ADMIN_USER
          Value: !Ref AdminUSER
        Essential: true
        Image: dcm4che/dcm4chee-arc-psql:5.23.1
        LinuxParameters: {}
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        MountPoints:
        - ContainerPath: /storage
          SourceVolume: storage
        Name: arc
        PortMappings:
        - ContainerPort: 8080
          HostPort: 8080
          Protocol: tcp
        - ContainerPort: 8443
          HostPort: 8443
          Protocol: tcp
        - ContainerPort: 9990
          HostPort: 9990
          Protocol: tcp
        - ContainerPort: 9993
          HostPort: 9993
          Protocol: tcp
        - ContainerPort: 8787
          HostPort: 8787
          Protocol: tcp
        - ContainerPort: 11112
          HostPort: 11112
          Protocol: tcp
      Cpu: !Ref ArchiveContainerCPU
      Memory: !Ref ArchiveContainerMemory
      ExecutionRoleArn:
        Ref: ArcTaskExecutionRole
      Family: dcm4chee-arc-psql-arc
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - EC2
      TaskRoleArn: !Ref ArcTaskRole
      Volumes:
        - Name: storage
          EFSVolumeConfiguration:
            AuthorizationConfig:
              AccessPointId: !Ref StorageAccessPoint
              IAM: ENABLED
            FilesystemId: !Ref FileSystem
            TransitEncryption: ENABLED
  ArcTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
      - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  ArcTaskRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      Policies:
      - PolicyDocument:
          Statement:
          - Action:
            - elasticfilesystem:ClientMount
            - elasticfilesystem:ClientWrite
            - elasticfilesystem:ClientRootAccess
            Condition:
              StringEquals:
                elasticfilesystem:AccessPointArn:
                  Ref: StorageAccessPoint
            Effect: Allow
            Principal: {}
            Resource:
            - !GetAtt 'FileSystem.Arn'
          Version: 2012-10-17
        PolicyName: ArcStorageVolumeMountPolicy
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  ECSAutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    DependsOn:
      - StorageNFSMountTarget1
      - StorageNFSMountTarget2
    Properties:
      VPCZoneIdentifier:
        - !Ref PublicSubnet1Id
        - !Ref PublicSubnet2Id
      LaunchConfigurationName: !Ref 'ContainerInstances'
      MinSize: '1'
      MaxSize: '4'
      DesiredCapacity: !Ref EC2InstanceCount
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
    UpdatePolicy:
      AutoScalingReplacingUpdate:
        WillReplace: 'true'
  ContainerInstances:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !FindInMap [AWSRegionToAMI, !Ref 'AWS::Region', AMIID]
      SecurityGroups:
            - !Ref DefaultSecurityGroup
      InstanceType: !Ref 'InstanceType'
      IamInstanceProfile: !Ref 'EC2InstanceProfile'
      KeyName: !Ref 'KeyName'
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          echo ECS_CLUSTER=${DCM4CHEECluster} >> /etc/ecs/ecs.config
          yum install -y aws-cfn-bootstrap bzip2 unzip git jq wget telnet java-11-amazon-corretto-headless
          /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}
          amazon-linux-extras install postgresql11 -y
          curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"  
          unzip awscliv2.zip  
          ./aws/install
          git clone https://github.com/dcm4che-dockerfiles/postgres-dcm4chee.git
          password=`aws secretsmanager get-secret-value --secret-id ${RDSDatabaseSecret} --query SecretString --output text | jq -r .password`
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/10_create-psql.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/20_create-fk-index.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/30_create-case-insensitive-index.sql
          wget https://sourceforge.net/projects/dcm4che/files/dcm4che3/5.23.2/dcm4che-5.23.2-bin.zip -P /tmp
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
        - arn:aws:iam::aws:policy/AmazonS3FullAccess
        - arn:aws:iam::aws:policy/SecretsManagerReadWrite
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: /
      Roles: [!Ref 'EC2Role']

  LdapService:
    Type: AWS::ECS::Service
    DependsOn:
      - LdapTCP389Listener
    Properties:
      Cluster: !GetAtt DCM4CHEECluster.Arn
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DeploymentController:
        Type: ECS
      DesiredCount: !Ref NumberofLDAPContainers
      LaunchType: FARGATE
      LoadBalancers:
      - ContainerName: ldap
        ContainerPort: 389
        TargetGroupArn: !Ref LdapTCP389TargetGroup
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          SecurityGroups:
            - !Ref DefaultSecurityGroup
          Subnets:
            - !Ref PublicSubnet1Id
            - !Ref PublicSubnet2Id
      PropagateTags: SERVICE
      SchedulingStrategy: REPLICA
      ServiceRegistries:
        - RegistryArn: !GetAtt LdapServiceDiscoveryEntry.Arn
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: ldap
      TaskDefinition:
        Ref: LdapTaskDefinition
  LdapTCP389Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - ForwardConfig:
            TargetGroups:
            - TargetGroupArn:
                Ref: LdapTCP389TargetGroup
          Type: forward
      LoadBalancerArn:
        Ref: LoadBalancer
      Port: 389
      Protocol: TCP
  LdapTCP389TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 389
      Protocol: TCP
      Tags:
        - Key: project
          Value: dcm4chee-arc-psql
      TargetType: ip
      VpcId: !Ref ParameterVPCId
  LdapTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
      - Command:
        - !Sub ${AWS::Region}.compute.internal
        - dcm4chee-arc-psql.local
        Essential: false
        Image: docker/ecs-searchdomain-sidecar:1.0
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: Ldap_ResolvConf_InitContainer
      - DependsOn:
        - Condition: SUCCESS
          ContainerName: Ldap_ResolvConf_InitContainer
        Environment:
        - Name: POSTGRES_HOST
          Value: !GetAtt 'RDSInstance.Endpoint.Address'
        - Name: POSTGRES_PORT
          Value: !GetAtt 'RDSInstance.Endpoint.Port'
        - Name: POSTGRES_DB
          Value: pacsdb
        - Name: POSTGRES_PASSWORD
          Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
        - Name: POSTGRES_USER
          Value: !Ref RDSDBUserName
        - Name: STORAGE_DIR
          Value: /storage/fs1
        Essential: true
        Image: dcm4che/slapd-dcm4chee:2.4.56-23.1
        LinuxParameters: {}
        LogConfiguration:
          LogDriver: awslogs
          Options:
            awslogs-group:
              Ref: LogGroup
            awslogs-region:
              Ref: AWS::Region
            awslogs-stream-prefix: dcm4chee-arc-psql
        Name: ldap
        PortMappings:
        - ContainerPort: 389
          HostPort: 389
          Protocol: tcp
      Cpu: !Ref LDAPContainerCPU
      Memory: !Ref LDAPContainerMemory
      ExecutionRoleArn:
        Ref: LdapTaskExecutionRole
      Family: dcm4chee-arc-psql-ldap
      NetworkMode: awsvpc
      RequiresCompatibilities:
      - FARGATE
  LdapTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action:
          - sts:AssumeRole
          Condition: {}
          Effect: Allow
          Principal:
            Service: ecs-tasks.amazonaws.com
        Version: 2012-10-17
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
      - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: ldap


Outputs:
  HTTPEndpoint:
    Description: The HTTP endpoint for Dcm4Chee
    Value: !Join
      - ''
      - - 'http://'
        - !GetAtt LoadBalancer.DNSName
        - ':8080/dcm4chee-arc/ui2'
  HTTPSEndpoint:
    Description: The HTTPS endpoint for Dcm4Chee
    Value: !Join
      - ''
      - - 'https://'
        - !GetAtt LoadBalancer.DNSName
        - ':8443/dcm4chee-arc/ui2'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



