# Perforce Instance with Replica in AWS with Terraform ## Requirements * Terraform * AWS Account IAM user setup with policies * IAMUserChangePassword * STSFullAccess * AmazonEC2FullAccess * SSH Keypair Suggest you have appropriate entries in ~/.aws/config and ~/.aws/credentials ## Initialise Terraform ```bash terraform init ``` ## Create the Stack Then, provision resources with: ```bash terraform plan -var-file=env/dev/eu-west-1.tfvars ``` Note it is possible to have multiple workspaces, e.g. dev and prod. To actually create: ```bash terraform apply -var-file=env/dev/eu-west-1.tfvars ``` ## Outputs If you want to know the endpoints of resources created by this stack (e.g. EFS), run: ```bash terraform output ``` (all outputs are defined in outputs.tf) ## SSH Access Get one of the two public DNS records via: ```bash terraform output ``` And then connect via SSH: ```bash ssh -i private/id_rsa ec2-user@[publicDnsRecord] ``` Please note that the SSH public keys such as files/id_rsa.pub will be used to configure the SSH access for user ec2-user on the VMs. You can add multiple public keys to this folder as desired. ## Update hosts information for Ansible This will use "terraform output" to get IP addresses etc and will update the 2 files: - hosts - sdp/hosts.yaml ```bash ./update_hosts.py ``` ## Review Ansible configuration files These are in the sdp directory: * passwords.yaml * mkdirs.1.cfg (as used by SDP) * hosts.yaml (updated as above) The following ssh keys are installed for perforce user account on both boxes and SSH is configured to allow ssh between master and replica without password prompt. This key pair can be regenerated so you can replace these files (but must be without a password): * private/id_rsa * private/id_rsa.pub ## Run Ansible to format and mount filesystems ```bash ansible-playbook -i hosts sdp/filesystems.yaml ``` ## Run Ansible to install SDP and replica ```bash ansible-playbook -i hosts sdp/install_sdp.yaml ansible-playbook -i hosts sdp/create_replica.yaml ``` Then check you have access: ```bash p4 -p :1666 -u perforce pull -lj ``` You will be prompted for password which has been created from entry in file sdp/passwords.yaml ## Destroy the created Stack Make sure the instances have been stopped. You will not be able to destroy them otherwise. Then, run: ```bash tf destroy -var-file env/dev/eu-west-1.tfvars ```