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.

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

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.

Check Machine State

Check that all machines are running as expected by doing the following:

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.

  1. In the Microsoft Azure Console navigate to: Marketplace → Networking → Application Gateway
  2. Name
    1. DMC standard is to name the gateway <stack-prefix>_<resource-groupname>_application-gateway
  3. Leave SKU size as default option
  4. Leave Instance Count as default option
  5. Set the resource group that was created using Terraform
  6. Set the location to the region of the stack was created in by Terraform
  7. Set the tier to be standard
  8. In the Subnet Configuration Section
    1. Create a new virtual network and use the default options
    2. Leave the Subnet as the defaulted option
  9. In the Frontend IP Configuration Section
    1. Choose public
    2. Create a new Public IP Address
  10. Set the Listener Configuration to HTTPS
    1. Set he port to 443
    2. Upload the .pfx SSL certificate
      1. 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:

  1. Navigate to All Resources → <Resource Group Name created by Terraform> → <Name of Application Gateway> → Backend Pools
    1. You will see two by the same name. Choose the one that is of type Application Gateway
  2. In the Backend Pool blade you should see a backend pool named appGatewayBackendPool.
    1. If not, above the blade, you should see an add button. Click on this and create a backend pool named appGatewayBackendPool
  3. 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.
  4. Above this new blade click on the save button.
    1. The saving process may take from 5-10 minutes.
  5. 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.

Amazon Web Services

Instructions coming soon