Terraform Infrastructure Deployment
The Digital Manufacturing Commons uses HashiCorp's Terraform to deploy its infrastructure. Below you will find instructions as to how the DMC generally uses it dmcdeploy repository as well as Terraform to deploy a working environment in both Microsoft Azure and Amazon Web Services.
Local Machine Setup
Download Terraform
In order to use Terraform to create new DMC infrastructure, you will first need to download Terraform onto your local machine. You can find a list of possible downloads on HashiCorp's website. The following link will take you to the Terraform download page.
- https://www.terraform.io/downloads.html
- Ensure that the download is Terraform version 7.13
- https://www.terraform.io/downloads.html
Next extract the file to some location on your computer.
Run terraform -v to check that the terraform version is actually v0.7.13
Download dmcdeploy Repository
In order to deploy DMC infrastructure you will need to download the dmcdeploy repository from BitBucket.
You can use the following commands to set up your dmcdeploy folder
cd ~/Desktop mkdir dmcInfrastructure cd dmcInfrastructure git clone https://bitbucket.org/DigitalMfgCommons/dmcdeploy.git cd dmcdeploy git fetch && git checkout chancock
Microsoft Azure
Terraform.tfvars file
If you are going to be deploying the DMC platform to Microsoft Azure, follow this set of instructions.
While in the dmcdeploy folder on your machine, go to the folding folder
- dmcdeploy/azure/dmcazure-experimental
Open the terraform.tfvars file and add the appropriate Ids to the corresponding fields that can be found through your Azure Portal.
- DMC will be provided these Ids.
Create Key
Using ssh-keygen, create a new key.
- At this time, your key needs to be name azu
Make note of where your key is stored as you need to reference it in the next section
Variables.tf file
While in the dmcdeploy folder on your machine, go to the folding folder
- dmcdeploy/azure/dmcazure-experimental
Open the varriable.tf file and edit the fields appropriately. The main fields to edit are the following
variable "azure_region" {
default = "_____"variable "groupname" {
default = "_____"variable "stackprefix" {
default = "_____"variable "dmcuser" {
default = "_____"variable "dmcpass" {
default = "_____"variable "azure_key_dir" {
default = "<private_key_directory_path>"variable "azure_privkey_filename" {
default = "<private_key_name>"- variable serverURL {
default = "_____"
Terraform.tfstate and Terraform.tfstate.backup file
You will need to remove two files or at least make sure two files are not in the dmcdeploy/azure/dmcazure-experimental directory. If they do exist run the following command:
- rm -rf terraform.tfstat*
- This will remove the terraform.tfstate and terrafor,tfstate.backup files from the dmcdeploy/azure/dmcazure-experimental directory
- rm -rf terraform.tfstat*
Azure Portal
On the portal make sure either that there is enough room for your new machines in the region you want to deploy to, or the machines that are currently found there.
Terraform Infrastructure Deployment
Once your files have been edited appropriately, run the following command in the dmcdeploy/azure/dmcazure-experimental folder.
- terraform plan
If everything returns without errors, run the following command to begin the deployment:
- terraform apply
- You need to make sure during the deployment time your machine has a constant internet connection and it is recommended that your machine does not go to sleep.
- terraform apply
Check Machine State
Check that all machines are running as expected by doing the following:
- Open the terraform.tfstates file to find the ip addresses and port numbers of all the machines
- DB
- pg admin
- Connect to the Database service using the terraform defined credentials
- pg admin
- ActiveMQ
- http://ip.of.active.machine:8161/admin/
- Connect to the manager using the credentials defined in the terraform configurations
- Connect to the manager using the credentials defined in the terraform configurations
- http://ip.of.active.machine:8161/admin/
- Validate
- Connect to the validate nodejs port http://<ip.of.validate.machine>:3000
- will return "validation online"
- Connect to the validate nodejs port http://<ip.of.validate.machine>:3000
- Solr
- In browser visit http://<ip.of.solr.machine>:8983/solr
- Rest
- In browser visit http://<ip.of.REST.machine>:8080/rest/companies
- DOME
- In browser visit http://<ip.of.DOME.machine>:8080/DOMEApiServicesV7
- Front
- In browser visit http://<ip.of.front.machine>
- DB
Application Gateway
Creating an Application Gateway
Once you've confirmed that all of the above machine have been set up correctly, you can either create and application gateway and configure it to talk to the frontend machine. If you already have an application gateway created you can skip this step.
- In the Microsoft Azure Console navigate to: Marketplace → Networking → Application Gateway
- Name
- DMC standard is to name the gateway <stack-prefix>_<resource-groupname>_application-gateway
- Leave SKU size as default option
- Leave Instance Count as default option
- Set the resource group that was created using Terraform
- Set the location to the region of the stack was created in by Terraform
- Set the tier to be standard
- In the Subnet Configuration Section
- Create a new virtual network and use the default options
- Leave the Subnet as the defaulted option
- In the Frontend IP Configuration Section
- Choose public
- Create a new Public IP Address
- Set the Listener Configuration to HTTPS
- Set he port to 443
- Upload the .pfx SSL certificate
- Provide the name and password for the certificate
The creation process may take between 10-15 minutes.
- While waiting, in the Azure Console, navigate to All Resources → <Resource Group Name created by Terraform> → frontVm
- Write down the public IP address of the machine.
Configure Application Gateway
Once you have created the application gateway, you can go about configuring it to the new DMC stack in Azure. To do so, do the following:
- Navigate to All Resources → <Resource Group Name created by Terraform> → <Name of Application Gateway> → Backend Pools
- You will see two by the same name. Choose the one that is of type Application Gateway
- In the Backend Pool blade you should see a backend pool named appGatewayBackendPool.
- If not, above the blade, you should see an add button. Click on this and create a backend pool named appGatewayBackendPool
- When the backend pool has been created, click on it and in the backend address field, add the public IP address of the frontend machine.
- Above this new blade click on the save button.
- The saving process may take from 5-10 minutes.
- If using a service like GoDaddy or CloudFlare, this is the time that you will need to associate the DNS record of the application gateway with that service.