github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_tcp_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 TestAccCirconusCheckTCP_basic(t *testing.T) {
    12  	checkName := fmt.Sprintf("Terraform test: TCP+TLS 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(testAccCirconusCheckTCPConfigFmt, checkName),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "active", "true"),
    23  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "collector.#", "1"),
    24  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "collector.1893401625.id", "/broker/1286"),
    25  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.#", "1"),
    26  					// resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.banner_regexp", ""),
    27  					// resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.ca_chain", ""),
    28  					// resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.certificate_file", ""),
    29  					// resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.ciphers", ""),
    30  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.host", "127.0.0.1"),
    31  					// resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.key_file", ""),
    32  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tcp.453641246.port", "443"),
    33  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "name", checkName),
    34  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "notes", "Check to harvest cert expiration information"),
    35  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "period", "60s"),
    36  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.#", "9"),
    37  
    38  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.active", "true"),
    39  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.name", "cert_end"),
    40  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.tags.#", "4"),
    41  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.tags.30226350", "app:circonus"),
    42  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.tags.213659730", "app:tls_cert"),
    43  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.tags.1401442048", "lifecycle:unittest"),
    44  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.tags.862116066", "source:fastly"),
    45  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.type", "numeric"),
    46  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1245733907.unit", "epoch"),
    47  
    48  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.active", "true"),
    49  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.name", "cert_end_in"),
    50  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.tags.#", "4"),
    51  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.tags.30226350", "app:circonus"),
    52  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.tags.213659730", "app:tls_cert"),
    53  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.tags.1401442048", "lifecycle:unittest"),
    54  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.tags.862116066", "source:fastly"),
    55  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.type", "numeric"),
    56  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.2000319022.unit", "seconds"),
    57  
    58  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.active", "true"),
    59  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.name", "cert_error"),
    60  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.tags.#", "4"),
    61  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.tags.30226350", "app:circonus"),
    62  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.tags.213659730", "app:tls_cert"),
    63  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.tags.1401442048", "lifecycle:unittest"),
    64  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.tags.862116066", "source:fastly"),
    65  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.type", "text"),
    66  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.280072942.unit", ""),
    67  
    68  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.active", "true"),
    69  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.name", "cert_issuer"),
    70  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.tags.#", "4"),
    71  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.tags.30226350", "app:circonus"),
    72  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.tags.213659730", "app:tls_cert"),
    73  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.tags.1401442048", "lifecycle:unittest"),
    74  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.tags.862116066", "source:fastly"),
    75  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.type", "text"),
    76  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.1101485564.unit", ""),
    77  
    78  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.active", "true"),
    79  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.name", "cert_start"),
    80  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.tags.#", "4"),
    81  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.tags.30226350", "app:circonus"),
    82  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.tags.213659730", "app:tls_cert"),
    83  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.tags.1401442048", "lifecycle:unittest"),
    84  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.tags.862116066", "source:fastly"),
    85  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.type", "numeric"),
    86  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3987659273.unit", "epoch"),
    87  
    88  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.active", "true"),
    89  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.name", "cert_subject"),
    90  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.tags.#", "4"),
    91  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.tags.30226350", "app:circonus"),
    92  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.tags.213659730", "app:tls_cert"),
    93  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.tags.1401442048", "lifecycle:unittest"),
    94  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.tags.862116066", "source:fastly"),
    95  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.type", "text"),
    96  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3170432128.unit", ""),
    97  
    98  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.active", "true"),
    99  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.name", "duration"),
   100  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.tags.#", "4"),
   101  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.tags.30226350", "app:circonus"),
   102  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.tags.213659730", "app:tls_cert"),
   103  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.tags.1401442048", "lifecycle:unittest"),
   104  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.tags.862116066", "source:fastly"),
   105  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.type", "numeric"),
   106  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.3590989341.unit", "milliseconds"),
   107  
   108  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.active", "true"),
   109  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.name", "tt_connect"),
   110  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.tags.#", "4"),
   111  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.tags.30226350", "app:circonus"),
   112  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.tags.213659730", "app:tls_cert"),
   113  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.tags.1401442048", "lifecycle:unittest"),
   114  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.tags.862116066", "source:fastly"),
   115  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.type", "numeric"),
   116  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.208818063.unit", "milliseconds"),
   117  
   118  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.active", "true"),
   119  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.name", "tt_firstbyte"),
   120  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.tags.#", "4"),
   121  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.tags.30226350", "app:circonus"),
   122  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.tags.213659730", "app:tls_cert"),
   123  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.tags.1401442048", "lifecycle:unittest"),
   124  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.tags.862116066", "source:fastly"),
   125  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.type", "numeric"),
   126  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "metric.4054733260.unit", "milliseconds"),
   127  
   128  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tags.#", "4"),
   129  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tags.30226350", "app:circonus"),
   130  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tags.213659730", "app:tls_cert"),
   131  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tags.1401442048", "lifecycle:unittest"),
   132  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "tags.862116066", "source:fastly"),
   133  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "target", "127.0.0.1"),
   134  					resource.TestCheckResourceAttr("circonus_check.tls_cert", "type", "tcp"),
   135  				),
   136  			},
   137  		},
   138  	})
   139  }
   140  
   141  const testAccCirconusCheckTCPConfigFmt = `
   142  variable "tcp_check_tags" {
   143    type = "list"
   144    default = [ "app:circonus", "app:tls_cert", "lifecycle:unittest", "source:fastly" ]
   145  }
   146  
   147  resource "circonus_check" "tls_cert" {
   148    active = true
   149    name = "%s"
   150    notes = "Check to harvest cert expiration information"
   151    period = "60s"
   152  
   153    collector {
   154      id = "/broker/1286"
   155    }
   156  
   157    tcp {
   158      host = "127.0.0.1"
   159      port = 443
   160    }
   161  
   162    metric {
   163      name = "cert_end"
   164      tags = [ "${var.tcp_check_tags}" ]
   165      type = "numeric"
   166      unit = "epoch"
   167    }
   168  
   169    metric {
   170      name = "cert_end_in"
   171      tags = [ "${var.tcp_check_tags}" ]
   172      type = "numeric"
   173      unit = "seconds"
   174    }
   175  
   176    metric {
   177      name = "cert_error"
   178      tags = [ "${var.tcp_check_tags}" ]
   179      type = "text"
   180    }
   181  
   182    metric {
   183      name = "cert_issuer"
   184      tags = [ "${var.tcp_check_tags}" ]
   185      type = "text"
   186    }
   187  
   188    metric {
   189      name = "cert_start"
   190      tags = [ "${var.tcp_check_tags}" ]
   191      type = "numeric"
   192      unit = "epoch"
   193    }
   194  
   195    metric {
   196      name = "cert_subject"
   197      tags = [ "${var.tcp_check_tags}" ]
   198      type = "text"
   199    }
   200  
   201    metric {
   202      name = "duration"
   203      tags = [ "${var.tcp_check_tags}" ]
   204      type = "numeric"
   205      unit = "milliseconds"
   206    }
   207  
   208    metric {
   209      name = "tt_connect"
   210      tags = [ "${var.tcp_check_tags}" ]
   211      type = "numeric"
   212      unit = "milliseconds"
   213    }
   214  
   215    metric {
   216      name = "tt_firstbyte"
   217      tags = [ "${var.tcp_check_tags}" ]
   218      type = "numeric"
   219      unit = "milliseconds"
   220    }
   221  
   222    tags = [ "${var.tcp_check_tags}" ]
   223  }
   224  `