Jump to content
Welcome to our new Citrix community!
  • Get Started with NetScaler Automation using Terraform


    Guest
    • Validation Status: Validated
      Has Video?: No

    HashiCorp Terraform is an infrastructure-as-code software tool used to orchestrate and manage IT infrastructure, including networking. Terraform codifies infrastructure into declarative configuration files for easier provisioning, compliance, and management. NetScaler Terraform provider allows users to configure NetScaler's for various use-cases such as global server load balancing, SSL offloading, web application firewall policies, and more. With Terraform, you can share and reuse your NetScaler configurations across your environments — a key time saver when migrating applications from your data center to any public cloud.

     

    image.thumb.png.ba7ba99d9e907ab3814037c332474def.png

    In this tutorial, we will go through Terraform installation and configure our first basic use-case of setting up load balancing vserver on NetScaler:

    Pre-requisite : NetScaler is installed, its NSIP, VIP and SNIP configured and ready to receive user traffic.

    1. Install Terraform
     Install Terraform into any of your local machines that can communicate to NetScaler.
    1. Download  Terraform NetScaler examples
    Clone the Terraform provider for NetScaler GitHub repo to use pre-built examples for NetScaler use cases:
    git clone https://github.com/citrix/terraform-provider-citrixadc/

    1. Define a Netscaler Terraform provider details
    Provider.tf contains the details of the target NetScaler. Edit the simple_server/provider.tf as follows and add details of your target NetScaler. For terraform version > 13.0 edit the provider.tf as follows

    Navigate with the above repo to simple_server example folder :

    cd …/terraform-provider-citrixadc/examples/lb/simple_lb$

    Edit the provider.tf file with your target NetScaler info as shown below, where endpoint is the NSIP(management IP) of your NetScaler.
    terraform {    required_providers {        citrixadc = {            source = "citrix/citrixadc"        }    }}provider "citrixadc" {  endpoint = "http://10.1.1.3:80"  username = "UsernameOfYourADC"  password = "PasswordOfYourADC" }

    1. Define your Netscaler configurations declaratively
    Edit the resource file to create a backend server in your NetScaler as shown below :
    examples/resources.tf contains the desired state of the resources that you want to manage through terraform. Here we want to create simple HTTP load balancing vserver named terraform_LB that will load balance user traffic across group of your backend services bound to servicegroup named productionBackend. You can edit the configuration as per your requirement.
    resource "citrixadc_lbvserver" "production_lb" {  name        = "terraform_LB"  ipv46       = var.vip_config["vip"]  port        = "80"  servicetype = "HTTP"}resource "citrixadc_servicegroup" "backend" {  servicegroupname = "productionBackend"  lbvservers       = [citrixadc_lbvserver.production_lb.name]  servicetype      = "HTTP"  clttimeout       = var.backend_service_config["clttimeout"]  servicegroupmembers = formatlist(    "%s:%s",    var.backend_services,    var.backend_service_config["backend_port"],  )}

    1. Provide values to Netscaler configurations
    In the simple_lb/terraform.tfvars file, specify the values of the vip - the IP the given to load balancing vserver that will receive the traffic and and ip of your backend application services in backend_services  :
     vip_config = {  vip = "10.105.158.176"}backend_service_config = {  clttimeout   = 40  backend_port = 80}backend_services = [  "10.105.158.177",  "10.105.158.178",]

    1. Run Terraform commands to apply configuration to target NetScaler:
    Initialize the NetScaler provider by running :
    terraform init

    image.png.21e57ddedbc07d76e2db9371da8d9972.png

    To view the changes that will be done to your NetScaler configurations, run

    terraform plan

    You will see diff between the NetScaler config specified and the existing NetScaler config for that resources, thuis showing the resources that will wither created or updated to achieve the desired NetScaler configuration.

    image.thumb.png.bbf0ec1188c11fd00e52ae5f17fb29e0.png

    image.thumb.png.2f89eddf4addf862e571d608cf895ff5.png

    Now, to apply the configurations run

    terraform apply

    Review the configuration changes proposed by Terraform and type yes to approve :

     

    image.thumb.png.388f17f460e9a18a9025d95e3d89f330.png

    That’s it! You can log in to NetScaler manually and validate the configuration changes made by Terraform.

    image.thumb.png.3cd22852eff163e287de71398ead2a6a.png

    Once your backend services are up, your Loadbalancing vserver terraform_LB State will show up and it will be ready to receive user traffic and load balance it across your app services. Similarly

    terraform destroy

    will destroy the configuration specified in resources.tf. Check out the detailed documentation here .
    As we see above, Terraform abstracts the NetScaler technicalities and makes it easy to codify and integrate NetScaler with other applications.

    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...