Parameters:
  myVPC:
      Description: VPC used to deploy our resources below
      Type: AWS::EC2::VPC::Id
  PublicSubnet:
      Description: Subnet to be used for our Web Server
      Type: AWS::EC2::Subnet::Id
  AMItoUse:
      Description: AMI to use for our base image
      Type: String
Resources:
  myWebAccessSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
        GroupDescription: Allow http to our test host
        VpcId:
          Ref: myVPC
        SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        SecurityGroupEgress:
        - IpProtocol: -1
          FromPort: -1
          ToPort: -1
          CidrIp: 0.0.0.0/0
  myWebServerInstance: 
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t3.micro
      ImageId: !Ref AMItoUse
      NetworkInterfaces: 
        - AssociatePublicIpAddress: "true"
          DeviceIndex: "0"
          GroupSet: 
            - Ref: "WebAccessSecurityGroup"
          SubnetId: 
            Ref: "PublicSubnet"
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash
          yum update -y
          yum install -y httpd
          systemctl start httpd
          systemctl enable httpd