This is a Terraform configuration that sets up a Docker Container on a VM instaces, with a configurable amount of VM instances. Those VM's are running in existing VPC.
How to install terraform you can find at this link - https://www.terraform.io/downloads
How to install google cloud sdk shell you can find at this link - https://cloud.google.com/sdk/docs/install-sdk
If you don't have account, you may get a free GCP account. In the setup will be used free f1.micro instances.
https://cloud.google.com/resource-manager/docs/creating-managing-projects
Run the following command in gcloud cli -
export GOOGLE_APPLICATION_CREDENTIALS={{path}}
path - the path in your local computer to the google cloud SDK folder.
That give the ability to connect terraform to GCP.
In the file variables.tf update to your VM instances information. project-id, region, instance-image, machine type.
Note: the machine type has been choosen to the smallest machine.
This command sets up the environment.
terraform init
After all the configuration files are ready, you can do check if there are no mistakes.
terraform plan
This command will show either syntax errors or list of resources will be created. After you can run:
terraform apply
After terraform apply completes, the website URL will be printed to the shell.
This command will build and run all resources in the *.tf files.
That's it. Now you have fully functioned docker container in GCP.
If you want to terminate instances and destroy the configuration you may call:
terraform destroy
SSH can only be accessed from the developer IP address.
Run the command in shell to connect the VM instancs.
ssh -i your_ssh_key your_gcp_username@external_IP
The google_compute_firewall which is responsibole of the VM instace firewall is allow HTTP trafic from any IP address.
Container that sending api request to superget api and analyze the data.
NGINX is a popular lightweight web application that is used for developing server-side applications, the container recive http request and forwad them to webapp container.
Vault Container is a tool for securely accessing secrets, in this case is API key.
Container that stored processed information from webapp.
The URL website will print to the shell when the command terraform apply is finish.
In addition, the URL can be found also in GCP -> Compute Engine -> VM instance at the section of external IP.