github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_http_test.go (about)

     1  package circonus
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/acctest"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccCirconusCheckHTTP_basic(t *testing.T) {
    12  	checkName := fmt.Sprintf("Terraform test: noit's jezebel availability check - %s", acctest.RandString(5))
    13  
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:     func() { testAccPreCheck(t) },
    16  		Providers:    testAccProviders,
    17  		CheckDestroy: testAccCheckDestroyCirconusCheckBundle,
    18  		Steps: []resource.TestStep{
    19  			{
    20  				Config: fmt.Sprintf(testAccCirconusCheckHTTPConfigFmt, checkName),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr("circonus_check.jezebel", "active", "true"),
    23  					resource.TestCheckResourceAttr("circonus_check.jezebel", "collector.#", "1"),
    24  					resource.TestCheckResourceAttr("circonus_check.jezebel", "collector.2388330941.id", "/broker/1"),
    25  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.#", "1"),
    26  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.auth_method", ""),
    27  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.auth_password", ""),
    28  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.auth_user", ""),
    29  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.body_regexp", ""),
    30  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.ca_chain", ""),
    31  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.certificate_file", ""),
    32  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.ciphers", ""),
    33  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.code", `^200$`),
    34  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.extract", `HTTP/1.1 200 OK`),
    35  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.key_file", ""),
    36  					// resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.payload", ""),
    37  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.headers.%", "1"),
    38  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.headers.Host", "127.0.0.1"),
    39  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.version", "1.1"),
    40  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.method", "GET"),
    41  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.read_limit", "1048576"),
    42  					resource.TestCheckResourceAttr("circonus_check.jezebel", "http.4213422905.url", "http://127.0.0.1:8083/resmon"),
    43  					resource.TestCheckResourceAttr("circonus_check.jezebel", "name", checkName),
    44  					resource.TestCheckResourceAttr("circonus_check.jezebel", "notes", "Check to make sure jezebel is working as expected"),
    45  					resource.TestCheckResourceAttr("circonus_check.jezebel", "period", "60s"),
    46  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.#", "4"),
    47  
    48  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.active", "true"),
    49  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.name", "code"),
    50  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.tags.#", "4"),
    51  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.tags.30226350", "app:circonus"),
    52  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.tags.3219687752", "app:jezebel"),
    53  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.tags.1401442048", "lifecycle:unittest"),
    54  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.tags.3241999189", "source:circonus"),
    55  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2380257438.type", "text"),
    56  
    57  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.active", "true"),
    58  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.name", "duration"),
    59  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.tags.#", "4"),
    60  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.tags.30226350", "app:circonus"),
    61  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.tags.3219687752", "app:jezebel"),
    62  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.tags.1401442048", "lifecycle:unittest"),
    63  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.tags.3241999189", "source:circonus"),
    64  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.type", "numeric"),
    65  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.3634949264.unit", "seconds"),
    66  
    67  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.active", "true"),
    68  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.name", "tt_connect"),
    69  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.tags.#", "4"),
    70  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.tags.30226350", "app:circonus"),
    71  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.tags.3219687752", "app:jezebel"),
    72  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.tags.1401442048", "lifecycle:unittest"),
    73  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.tags.3241999189", "source:circonus"),
    74  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.type", "numeric"),
    75  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.1717167158.unit", "milliseconds"),
    76  
    77  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.active", "true"),
    78  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.name", "tt_firstbyte"),
    79  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.tags.#", "4"),
    80  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.tags.30226350", "app:circonus"),
    81  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.tags.3219687752", "app:jezebel"),
    82  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.tags.1401442048", "lifecycle:unittest"),
    83  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.tags.3241999189", "source:circonus"),
    84  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.type", "numeric"),
    85  					resource.TestCheckResourceAttr("circonus_check.jezebel", "metric.2305894402.unit", "milliseconds"),
    86  
    87  					resource.TestCheckResourceAttr("circonus_check.jezebel", "tags.#", "4"),
    88  					resource.TestCheckResourceAttr("circonus_check.jezebel", "tags.30226350", "app:circonus"),
    89  					resource.TestCheckResourceAttr("circonus_check.jezebel", "tags.3219687752", "app:jezebel"),
    90  					resource.TestCheckResourceAttr("circonus_check.jezebel", "tags.1401442048", "lifecycle:unittest"),
    91  					resource.TestCheckResourceAttr("circonus_check.jezebel", "tags.3241999189", "source:circonus"),
    92  					resource.TestCheckResourceAttr("circonus_check.jezebel", "target", "127.0.0.1"),
    93  					resource.TestCheckResourceAttr("circonus_check.jezebel", "type", "http"),
    94  				),
    95  			},
    96  		},
    97  	})
    98  }
    99  
   100  const testAccCirconusCheckHTTPConfigFmt = `
   101  variable "http_check_tags" {
   102    type = "list"
   103    default = [ "app:circonus", "app:jezebel", "lifecycle:unittest", "source:circonus" ]
   104  }
   105  
   106  resource "circonus_metric" "status_code" {
   107    name = "code"
   108    tags = [ "${var.http_check_tags}" ]
   109    type = "text"
   110  }
   111  
   112  resource "circonus_metric" "request_duration" {
   113    name = "duration"
   114    tags = [ "${var.http_check_tags}" ]
   115    type = "numeric"
   116    unit = "seconds"
   117  }
   118  
   119  resource "circonus_metric" "request_ttconnect" {
   120    name = "tt_connect"
   121    tags = [ "${var.http_check_tags}" ]
   122    type = "numeric"
   123    unit = "milliseconds"
   124  }
   125  
   126  resource "circonus_metric" "request_ttfb" {
   127    name = "tt_firstbyte"
   128    tags = [ "${var.http_check_tags}" ]
   129    type = "numeric"
   130    unit = "milliseconds"
   131  }
   132  
   133  resource "circonus_check" "jezebel" {
   134    active = true
   135    name = "%s"
   136    notes = "Check to make sure jezebel is working as expected"
   137    period = "60s"
   138  
   139    collector {
   140      id = "/broker/1"
   141    }
   142  
   143    http {
   144      code = "^200$"
   145      extract     = "HTTP/1.1 200 OK"
   146      headers     = {
   147        Host = "127.0.0.1",
   148      }
   149      version     = "1.1"
   150      method      = "GET"
   151      read_limit  = 1048576
   152      url         = "http://127.0.0.1:8083/resmon"
   153    }
   154  
   155    metric {
   156      name = "${circonus_metric.status_code.name}"
   157      tags = [ "${circonus_metric.status_code.tags}" ]
   158      type = "${circonus_metric.status_code.type}"
   159    }
   160  
   161    metric {
   162      name = "${circonus_metric.request_duration.name}"
   163      tags = [ "${circonus_metric.request_duration.tags}" ]
   164      type = "${circonus_metric.request_duration.type}"
   165      unit = "${circonus_metric.request_duration.unit}"
   166    }
   167  
   168    metric {
   169      name = "${circonus_metric.request_ttconnect.name}"
   170      tags = [ "${circonus_metric.request_ttconnect.tags}" ]
   171      type = "${circonus_metric.request_ttconnect.type}"
   172      unit = "${circonus_metric.request_ttconnect.unit}"
   173    }
   174  
   175    metric {
   176      name = "${circonus_metric.request_ttfb.name}"
   177      tags = [ "${circonus_metric.request_ttfb.tags}" ]
   178      type = "${circonus_metric.request_ttfb.type}"
   179      unit = "${circonus_metric.request_ttfb.unit}"
   180    }
   181  
   182    tags = [ "${var.http_check_tags}" ]
   183  }
   184  `