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

     1  package circonus
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  
     7  	"github.com/circonus-labs/circonus-gometrics/api/config"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccCirconusCheckJSON_basic(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:     func() { testAccPreCheck(t) },
    14  		Providers:    testAccProviders,
    15  		CheckDestroy: testAccCheckDestroyCirconusCheckBundle,
    16  		Steps: []resource.TestStep{
    17  			{
    18  				Config: testAccCirconusCheckJSONConfig1,
    19  				Check: resource.ComposeTestCheckFunc(
    20  					resource.TestCheckResourceAttr("circonus_check.usage", "active", "true"),
    21  					resource.TestMatchResourceAttr("circonus_check.usage", "check_id", regexp.MustCompile(config.CheckCIDRegex)),
    22  					resource.TestCheckResourceAttr("circonus_check.usage", "collector.#", "1"),
    23  					resource.TestCheckResourceAttr("circonus_check.usage", "collector.2388330941.id", "/broker/1"),
    24  					resource.TestCheckResourceAttr("circonus_check.usage", "json.#", "1"),
    25  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.auth_method", ""),
    26  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.auth_password", ""),
    27  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.auth_user", ""),
    28  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.ca_chain", ""),
    29  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.certificate_file", ""),
    30  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.ciphers", ""),
    31  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.key_file", ""),
    32  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.payload", ""),
    33  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.headers.%", "3"),
    34  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.headers.Accept", "application/json"),
    35  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.headers.X-Circonus-App-Name", "TerraformCheck"),
    36  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.headers.X-Circonus-Auth-Token", "<env 'CIRCONUS_API_TOKEN'>"),
    37  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.version", "1.0"),
    38  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.method", "GET"),
    39  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.port", "443"),
    40  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.read_limit", "1048576"),
    41  					resource.TestCheckResourceAttr("circonus_check.usage", "json.2626248092.url", "https://api.circonus.com/account/current"),
    42  					resource.TestCheckResourceAttr("circonus_check.usage", "name", "Terraform test: api.circonus.com metric usage check"),
    43  					resource.TestCheckResourceAttr("circonus_check.usage", "notes", ""),
    44  					resource.TestCheckResourceAttr("circonus_check.usage", "period", "60s"),
    45  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.#", "2"),
    46  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.active", "true"),
    47  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.name", "_usage`0`_limit"),
    48  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.tags.#", "1"),
    49  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.tags.3241999189", "source:circonus"),
    50  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.type", "numeric"),
    51  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.unit", "qty"),
    52  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.active", "true"),
    53  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.name", "_usage`0`_used"),
    54  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.tags.#", "1"),
    55  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.tags.3241999189", "source:circonus"),
    56  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.type", "numeric"),
    57  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.unit", "qty"),
    58  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.#", "2"),
    59  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.3241999189", "source:circonus"),
    60  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.1401442048", "lifecycle:unittest"),
    61  					resource.TestCheckResourceAttr("circonus_check.usage", "target", "api.circonus.com"),
    62  					resource.TestCheckResourceAttr("circonus_check.usage", "type", "json"),
    63  				),
    64  			},
    65  			{
    66  				Config: testAccCirconusCheckJSONConfig2,
    67  				Check: resource.ComposeTestCheckFunc(
    68  					resource.TestCheckResourceAttr("circonus_check.usage", "active", "true"),
    69  					resource.TestCheckResourceAttr("circonus_check.usage", "collector.#", "1"),
    70  					resource.TestCheckResourceAttr("circonus_check.usage", "collector.2388330941.id", "/broker/1"),
    71  					resource.TestCheckResourceAttr("circonus_check.usage", "json.#", "1"),
    72  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.auth_method", ""),
    73  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.auth_password", ""),
    74  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.auth_user", ""),
    75  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.ca_chain", ""),
    76  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.certificate_file", ""),
    77  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.ciphers", ""),
    78  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.key_file", ""),
    79  					// resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.payload", ""),
    80  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.headers.%", "3"),
    81  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.headers.Accept", "application/json"),
    82  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.headers.X-Circonus-App-Name", "TerraformCheck"),
    83  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.headers.X-Circonus-Auth-Token", "<env 'CIRCONUS_API_TOKEN'>"),
    84  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.version", "1.1"),
    85  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.method", "GET"),
    86  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.port", "443"),
    87  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.read_limit", "1048576"),
    88  					resource.TestCheckResourceAttr("circonus_check.usage", "json.3951979786.url", "https://api.circonus.com/account/current"),
    89  					resource.TestCheckResourceAttr("circonus_check.usage", "name", "Terraform test: api.circonus.com metric usage check"),
    90  					resource.TestCheckResourceAttr("circonus_check.usage", "notes", "notes!"),
    91  					resource.TestCheckResourceAttr("circonus_check.usage", "period", "300s"),
    92  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.#", "2"),
    93  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.active", "true"),
    94  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.name", "_usage`0`_limit"),
    95  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.tags.#", "1"),
    96  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.tags.3241999189", "source:circonus"),
    97  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.type", "numeric"),
    98  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.1992097900.unit", "qty"),
    99  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.active", "true"),
   100  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.name", "_usage`0`_used"),
   101  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.tags.#", "1"),
   102  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.tags.3241999189", "source:circonus"),
   103  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.type", "numeric"),
   104  					resource.TestCheckResourceAttr("circonus_check.usage", "metric.3280673139.unit", "qty"),
   105  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.#", "2"),
   106  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.3241999189", "source:circonus"),
   107  					resource.TestCheckResourceAttr("circonus_check.usage", "tags.1401442048", "lifecycle:unittest"),
   108  					resource.TestCheckResourceAttr("circonus_check.usage", "target", "api.circonus.com"),
   109  					resource.TestCheckResourceAttr("circonus_check.usage", "type", "json"),
   110  				),
   111  			},
   112  		},
   113  	})
   114  }
   115  
   116  const testAccCirconusCheckJSONConfig1 = `
   117  variable "usage_default_unit" {
   118    default = "qty"
   119  }
   120  
   121  resource "circonus_metric" "limit" {
   122    name = "_usage` + "`0`" + `_limit"
   123    tags = [ "source:circonus" ]
   124    type = "numeric"
   125    unit = "${var.usage_default_unit}"
   126  }
   127  
   128  resource "circonus_metric" "used" {
   129    name = "_usage` + "`0`" + `_used"
   130    tags = [ "source:circonus" ]
   131    type = "numeric"
   132    unit = "${var.usage_default_unit}"
   133  }
   134  
   135  resource "circonus_check" "usage" {
   136    active = true
   137    name = "Terraform test: api.circonus.com metric usage check"
   138    period = "60s"
   139  
   140    collector {
   141      id = "/broker/1"
   142    }
   143  
   144    json {
   145      url = "https://api.circonus.com/account/current"
   146      headers = {
   147        Accept                = "application/json",
   148        X-Circonus-App-Name   = "TerraformCheck",
   149        X-Circonus-Auth-Token = "<env 'CIRCONUS_API_TOKEN'>",
   150      }
   151      version = "1.0"
   152      method = "GET"
   153      port = 443
   154      read_limit = 1048576
   155    }
   156  
   157    metric {
   158      name = "${circonus_metric.used.name}"
   159      tags = [ "${circonus_metric.used.tags}" ]
   160      type = "${circonus_metric.used.type}"
   161      unit = "${coalesce(circonus_metric.used.unit, var.usage_default_unit)}"
   162    }
   163  
   164    metric {
   165      name = "${circonus_metric.limit.name}"
   166      tags = [ "${circonus_metric.limit.tags}" ]
   167      type = "${circonus_metric.limit.type}"
   168      unit = "${coalesce(circonus_metric.limit.unit, var.usage_default_unit)}"
   169    }
   170  
   171    tags = [ "source:circonus", "lifecycle:unittest" ]
   172  }
   173  `
   174  
   175  const testAccCirconusCheckJSONConfig2 = `
   176  variable "usage_default_unit" {
   177    default = "qty"
   178  }
   179  
   180  resource "circonus_metric" "limit" {
   181    name = "_usage` + "`0`" + `_limit"
   182    tags = [ "source:circonus" ]
   183    type = "numeric"
   184    unit = "${var.usage_default_unit}"
   185  }
   186  
   187  resource "circonus_metric" "used" {
   188    name = "_usage` + "`0`" + `_used"
   189    tags = [ "source:circonus" ]
   190    type = "numeric"
   191    unit = "${var.usage_default_unit}"
   192  }
   193  
   194  resource "circonus_check" "usage" {
   195    active = true
   196    name = "Terraform test: api.circonus.com metric usage check"
   197    notes = "notes!"
   198    period = "300s"
   199  
   200    collector {
   201      id = "/broker/1"
   202    }
   203  
   204    json {
   205      url = "https://api.circonus.com/account/current"
   206      headers = {
   207        Accept                = "application/json",
   208        X-Circonus-App-Name   = "TerraformCheck",
   209        X-Circonus-Auth-Token = "<env 'CIRCONUS_API_TOKEN'>",
   210      }
   211      version = "1.1"
   212      method = "GET"
   213      port = 443
   214      read_limit = 1048576
   215    }
   216  
   217    metric {
   218      name = "${circonus_metric.used.name}"
   219      tags = [ "${circonus_metric.used.tags}" ]
   220      type = "${circonus_metric.used.type}"
   221      unit = "${coalesce(circonus_metric.used.unit, var.usage_default_unit)}"
   222    }
   223  
   224    metric {
   225      name = "${circonus_metric.limit.name}"
   226      tags = [ "${circonus_metric.limit.tags}" ]
   227      type = "${circonus_metric.limit.type}"
   228      unit = "${coalesce(circonus_metric.limit.unit, var.usage_default_unit)}"
   229    }
   230  
   231    tags = [ "source:circonus", "lifecycle:unittest" ]
   232  }
   233  `