Cmpute.io is now a part of Cisco. Learn More

About Cisco

Install CMPUTE plugin

How to install CMPUTE plugin for Terraform

In this post we will demonstrate how to create a cost-efficient Auto-Scaling in AWS using batchly Terraform plugin.

This post assumes that you already have a batchly account, and that you have connected your AWS account with batchly .

Download the binary file terraform-provider-batchly.

Please download the proper binary file for your operating system and architecture and put it somewhere on your filesystem:

  • linux_amd64 (supported on terraform version 0.8.0 to 0.8.7 and above)

  • darwin_amd64 (supported on terraform version 0.8.0 to 0.8.7 and above)

  • windows_amd64 (supported on terraform version 0.8.0 to 0.8.7 and above)

Configure Terraform to be able to find the binary file:

If you are on a Unix-like system, create a file named .terraformrc in your home directory:

~/.terraformrc

If you are on a Windows system, create a file named terraform.rc in the %APPDATA% directory:

%APPDATA%/terraform.rc

Edit the file and add the following content:

                providers
                {
                    batchly = "/path/to/terraform-provider-batchly"
                }

Create a new Terraform template and configure the batchly provider.

Please read the documentation for more details.

                provider "batchly" 
                { 
                tenant_url = "${var.tenant_url}" 
                api_key = "${var.api_key}" 
                secret_key = "${var.secret_key}"  
                }

For Example: <customer.cmpute.net>/<customer.cmpute.io>

To create a new batchly Auto Scaling resource.

Note : If you are using a template to create autoscaling group which you intend to use later to create autoscaling group job in batchly suspend it by adding the following line in your template :

Create ASG group

                resource "aws_autoscaling_group" "web-asg" 
                {
                ….
                suspended_processes = ["Launch", "Terminate", "ReplaceUnhealthy", "AZRebalance", "AlarmNotification", "ScheduledActions"]
                ….
                }

And add the following option in batchly template :

                resource "batchly_aws_asg_group" "workers" 
                { …
                depends_on = ["aws_autoscaling_group.web-asg"]
                …
                }

Please read the documentation for more details for creating batchly ASG job.

                # Create an batchly asg group

                resource "batchly_aws_asg_group" "workers" 
                {
                    name = "app_name"
                    account_resource_id = "A-XXXXXXX"
                    region = "us-east-1"
                    asg_name = "asg_name"
                    restrict_instance_type = true
                    minOnDemandCount = 1
                    replace_unhealthy_instances = true
                    restore_on_stop = true
                }

Once you have everything setup correctly, you can execute your Terraform file and apply the changes. It should trigger an API call to batchly , and create an ASG job.

To create a new batchly ami resource.

Please read the documentation for more details for creating batchly AMI job.

                # Create an batchly ami group

                resource "batchly_aws_ami_group" "worker" {
                    name = "app_name"
                    account_resource_id = "A-XXXXXXX"
                    region = "us-east-1"
                    restrict_instance_type = true
                    minOnDemandCount = 0
                    minCount = 1
                    maxCount = 2
                    desired = 2
                    instance_type = "m4.large"
                    health_grace_period = 300
                    replace_unhealthy_instances = false
                    associate_public_ip = false

                    launch_specifications {
                        image_id = "ami-xxxxxxx"
                        key_pair = "pemfile_name"
                        security_group_ids = ["sg-xxxxxxxx"]
                    load_balancers = ["elb_name"]
                    target_arns = ["target_arn_name"]
                    }

                    scaling_policy {
                    policy_name = "Policy 1"
                    policy_type = "ScaleUp"
                    metric_name = "CPUUtilization"
                    statistic = "average"
                    unit = "percent"
                    threshold = 80
                    adjustment = 1
                    namespace = "AWS/EC2"
                    period = 300
                    evaluation_periods = 2
                    cooldown = 300
                    }
                }

Once you have everything setup correctly, you can execute your Terraform file and apply the changes. It should trigger an API call to batchly , and create an ami job.

To create a new batchly EB resource.

Please read the documentation for more details for creating batchly EB job.

                # Create an batchly eb group

                resource "batchly_aws_eb_group" "workers" 
                {
                    name = "app_name"
                    account_resource_id = "A-XXXXXXX"
                    region = "us-east-1"
                    eb_env_id = "e-yzehhjwwwq"
                    restrict_instance_type = true
                    minOnDemandCount = 0
                    minCount = 1
                    maxCount = 2
                    desired = 2
                    health_grace_period = 300
                    replace_unhealthy_instances = false
                }

To create a new batchly Hadoop resource.

Please read the documentation for more details for creating batchly Hadoop job.

                # Create an batchly hadoop group

                resource "batchly_aws_hadoop_group" "workers" {
                    name = "app_name"
                    account_resource_id = "A-7D9E9469"
                    region = "us-east-1"
                    cluster_id = "j-asdfhjtvwscekvq"
                    jar_location = "s3 location of jar"
                    action_on_failure = "Continue"
                    instanceTypes = ["c1.medium", "c4.large"]
                    arguments = "arg1"
                    vpc_id = "vpc-XXXX"
                    subnets = ["s-xxxxxxx", "s-xxxxxxx"]
                }