Automating BIG-IP with Terraform

Follow this script to demonstrate creation of Pools and Virtual Servers using Terraform plans.

Task – Imperative - Create VS, Pool and Members using playbook variables

  1. From Firefox browser explore BIG-IP GUI Local Traffic -> Network Map to confirm app110 virtual servers does not exist

    ../../_images/nmap1.png
  2. From VScode explorer click on imparative/main.tf to examine the plan

    ../../_images/imparativemain.png
    terraform {
      required_providers {
        bigip = {
           source = "F5Networks/bigip"
         }
       }
     }
    
     provider "bigip" {
         address = var.address
         username = var.username
         password = var.password
     }
    
     resource "bigip_ltm_monitor" "monitor" {
       name     = "/Common/app100_monitor"
       parent   = "/Common/http"
       send     = "GET /\r\n"
       timeout  = "300"
       interval = "3"
     }
    
     resource "bigip_ltm_node" "node" {
       name    = "/Common/10.1.20.5"
       address = "10.1.20.5"
     }
    
     resource "bigip_ltm_pool" "pool" {
       name                = "/Common/app100_pool"
       load_balancing_mode = "round-robin"
       monitors            = ["/Common/app100_monitor"]
       allow_snat          = "yes"
       allow_nat           = "yes"
       depends_on = [bigip_ltm_monitor.monitor]
     }
    
     resource "bigip_ltm_pool_attachment" "attach_node" {
       pool = "/Common/app100_pool"
       node = "/Common/10.1.20.5:80"
       depends_on = [bigip_ltm_pool.pool, bigip_ltm_node.node]
     }
    
     resource "bigip_ltm_virtual_server" "http" {
       pool = "/Common/app100_pool"
       name = "/Common/app100_vs"
       destination = "10.1.10.100"
       port = 80
       source_address_translation = "automap"
       depends_on = [bigip_ltm_pool.pool]
     }
    
  3. From VScode terminal cd to hashicorp demo directory

    • Type cd ~/f5channel-demos/hashicorp/imperative/

  4. Run the terraform init

    • Type terraform init

    ../../_images/imparativeinit.png
  5. Run the terraform plan

    • Type terraform plan

    ../../_images/imparativeplan.png
  6. Run the terraform apply

    • Type terraform apply -auto-approve

    ../../_images/imparativeapply.png
  7. From Firefox browser explore BIG-IP GUI Local Traffic -> Network Map to confirm app100 virtual server now exists

    ../../_images/mapimparative.png
  8. Run the terraform destroy

    • Type terraform destroy -auto-approve

  9. From Firefox browser refresh BIG-IP GUI Local Traffic -> Network Map to confirm app100 virtual server is removed

Task – Declarative - Create VS, Pool and Members using AS3

  1. From VScode explorer click on declarative/main.tf to examine the plan

    terraform {
      required_providers {
        bigip = {
          source = "F5Networks/bigip"
        }
      }
    }
    
    provider "bigip" {
        address = var.address
        username = var.username
        password = var.password
    }
    
    resource "bigip_as3" "app101" {
      as3_json = "${file("app101.json")}"
    }
    
  2. From VScode explorer click on declarative/app101.json to examine the AS3 template

    {
        "class": "AS3",
        "action": "deploy",
        "persist": true,
        "declaration": {
            "class": "ADC",
            "schemaVersion": "3.0.0",
            "id": "app_101",
            "label": "App_101",
            "remark": "Simple HTTP application with round robin pool",
            "app_101": {
                "class": "Tenant",
                "defaultRouteDomain": 0,
                "Application_1": {
                    "class": "Application",
                    "template": "http",
                    "serviceMain": {
                        "class": "Service_HTTP",
                        "virtualAddresses": [
                            "10.1.10.101"
                        ],
                        "pool": "app101_pool"
                    },
                    "app101_pool": {
                        "class": "Pool",
                        "monitors": [
                            "http"
                       ],
                        "members": [
                            {
                                "servicePort": 80,
                                "serverAddresses": [
                                    "10.1.20.7",
                                    "10.1.20.8"
                                ]
                            }
                        ]
                    }
                }
            }
        }
    }
    
  3. From VScode terminal cd to hashicorp demo directory

    • Type cd ~/f5channel-demos/hashicorp/declarative/

  4. Run the terraform init

    • Type terraform init

  5. Run the terraform plan

    • Type terraform plan

    • Type terraform apply -auto-approve

    class1/module4/./images/runimparative.png
  6. From Firefox browser explore BIG-IP GUI Local Traffic -> Network Map to confirm app101 virtual servers now exists

    pictures/maptdeclarative.png
  7. Run the terraform destroy

    • Type terraform destroy -auto-approve

  8. From Firefox browser refresh BIG-IP GUI Local Traffic -> Network Map to confirm app101 virtual server removed