Deploying MarkLogic in AWS with Terraform
21 May 2020 08:55 AM
|
|
SummaryTerraform from HashiCorp is a deployment tool that many organizations use to manage their infrastructure as code. It is platform agnostic, allowing for the deployment and configuration of on-site physical infrastructure, as well as cloud infrastructure such as AWS, Azure, VSphere and more. Terraform uses the Hashicorp Configuration Language (HCL) to allow for concise descriptions of infrastructure. HCL is JSON compatible language, and was designed to be both human and machine friendly. This powerful tool can be used to deploy a MarkLogic Cluster to AWS using the MarkLogic CloudFormation Template. The MarkLogic CloudFormation Template is the preferred method recommended by MarkLogic for building out MarkLogic clusters within AWS. Setting Up TerraformFor the purpose of this example, I will assume that you have already installed Terraform, the AWS CLI and you have configured the credentials. You will also need to have a working directory that has been initialized using Terraform ProvidersTerraform uses Providers to provide access to different resources. The Provider is responsible for understanding API interactions and exposing resources. The AWS Provider is used to provide access to AWS resources. Terraform ResourcesResources are the most important part of the Terraform language. Resource blocks describe one or more infrastructure objects, like compute instances and virtual networks. The aws_cloudformation_stack resource, allows Terraform to create a stack from a CloudFormation template. Choosing a TemplateMarkLogic provides two templates for creating a managed cluster in AWS.
I've chosen to deploy my cluster to an VPC. When deploying to an existing VPC, you will need to gather the VPC ID, as well as the Subnet IDs for the public and private subnets.
Defining VariablesThe MarkLogic CF Template takes a number of input variables, including the region, availability zones, instance types, EC2 keys, encryption keys, licenses and more. We have to define our variables so they can be used as part of the resource. Variables in HCL can be declared in a separate file, which allows for deployment flexibility. For instance, you can create a Development resource and a Production resource, but using different variable files. Here is a snippet from our variables file:
In the snippet above, you'll notice that we've defined the availability_zone_names as a list. The MarkLogic CloudFormation template won't take a list as an input, so later we will join the list items into a string for the template to use. This also applies to any of the other lists defined in the variable files. Using the CloudFormation ResourceSo now we need to define the resource in HCL, that will allow us to deploy a CloudFormation template to create a new stack. The first thing we need to do, is tell Terraform which provider we will be using, defining some default options:
Next, we need to define the `
Deploying the ClusterNow that we have defined our variables and our resources, it's time for the actual deployment.
This will show us the work that Terraform is going to attempt to perform, along with the settings that have been defined so far. Once we confirm that things look correct, we can go ahead and apply the resource. Now we can check the AWS Console to see our stack And we can also use the ELB to login to the Admin UI Wrapping UpWe have now deployed a 3 node cluster to an existing VPC using Terraform. The cluster is now ready to have our Data Hub, or other application installed. | |
|