Provision Server
This article will show the Terraform workflow for provisioning the server for Rails on EC2.
Step 1 : Install Terraform
You can install Terraform using brew on Mac.
These steps are tested on Terraform v1.8.1.
Step 2 : Format the Template
Go to the terraform folder in hivegrid.dev project. Format the Terraform template:
Step 3 : Validate the Template
Run:
Step 4 : Provision the Instance
Run:
The output will have the values for the static public IP address, AWS account ID and Rails secret key name. The IP is needed to deploy using Capistrano and map the IP address to domain name in your domain registrar for Caddy SSL playbook to work. The account ID is useful if you have multiple AWS accounts and you want to make sure the resources are created in the expected AWS account. In the next step, we will use the Rails secret key to download the PEM file.
Step 5 : Download PEM File
In the terminal, run:
Go to javascript folder and run:
You must have nodejs installed on your machine. This will output the command to use for SSH connection to the server.
Step 6 : Connect to the Server
Replace the IP address with the IP of the static IP address from output of Terraform apply. You must run ssh command from the javascript directory. The pem file is stored inside that directory when you run the key downloader javascript program.