Resources:
  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t2.micro
      ImageId: ami-089fe97bc00bff7cc # AMI Debian
      KeyName: universeBlender
      Tags:
        - Key: Name
          Value: UniverseBlender
        - Key: Owner
          Value: Jeffrey Miller
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash
          mkdir /root/.ssh/
          cp -f /home/admin/.ssh/authorized_keys /root/.ssh/
          apt update
          apt install -y vsftpd python3 python3-pip sqlite3 python3-waitress git jq curl
          python3 -m pip install flask flask-sqlalchemy
          useradd -m flask
          usermod -L flask
          echo "flask      ALL=(ALL)     NOPASSWD: /home/flask/jeffrey_miller_flask_ftp/scripts/create_user.sh" >> /etc/sudoers
          echo "flask      ALL=(ALL)     NOPASSWD: /home/flask/jeffrey_miller_flask_ftp/scripts/delete_user.sh" >> /etc/sudoers
          sed -i "s/\#write_enable=YES/write_enable=YES/" /etc/vsftpd.conf
          systemctl restart vsftpd
          echo 'AllowUsers root admin' >> /etc/ssh/sshd_config
          systemctl reload sshd
          chmod 700 /home/flask/
          mkdir -p /home/flask/.ssh/
          echo "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn\nNhAAAAAwEAAQAAAYEAnlzqNZmPvhD3O7QV5zQl3+zEcuzhYVUOvMzY5xE9gIL4cRPFkdqp\nJJyrFo0/Sde+10iLDkfcS0w3wj6G32P55rHpDyMD7CuVP5ChvZO9rjXT4UQoOruukpndCO\nrS3o2O5i0VZg/WzKLLHjGwG7qwaMrYVr+TtQnvKUw5FYbcW+w+6kEda7G1d/t16npzkZ6R\nDT3zgGaGOZK+m02AeTxQhrVgnykbbliUTzSO7TXCHMqSw+1OtSBixeltyR+J34napkntiv\nL3KVpyCmlL/lXTSxhha/V1FeML9PMlAnNV6FZNMdJqpRtjed+r1keV1/oThvBBIDA1k2Ww\nbcRWOc9UeivHGi1TLXa7egDO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' > /root/.ssh/git
          chmod 700 /root/.ssh/git
          echo "Host *" >> /root/.ssh/config
          echo "IdentityFile ~/.ssh/git" >> /root/.ssh/config
          ssh-keyscan github.com >> /root/.ssh/known_hosts
          git clone git@github.com:crisosphinx/jeffrey_miller_flask_ftp.git /home/flask/jeffrey_miller_flask_ftp
          cp /home/flask/jeffrey_miller_flask_ftp/flask-ftp.service /etc/systemd/user/
          chmod a+r /etc/systemd/user/flask-ftp.service
          systemctl enable /etc/systemd/user/flask-ftp.service
          systemctl daemon-reload
          systemctl start flask-ftp.service
          chown -R flask:flask /home/flask
