github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/ultradns/resource_ultradns_dirpool_test.go (about)

     1  package ultradns
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/Ensighten/udnssdk"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  func TestAccUltradnsDirpool(t *testing.T) {
    13  	var record udnssdk.RRSet
    14  	domain := "ultradns.phinze.com"
    15  
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck:     func() { testAccPreCheck(t) },
    18  		Providers:    testAccProviders,
    19  		CheckDestroy: testAccDirpoolCheckDestroy,
    20  		Steps: []resource.TestStep{
    21  			resource.TestStep{
    22  				Config: fmt.Sprintf(testCfgDirpoolMinimal, domain),
    23  				Check: resource.ComposeTestCheckFunc(
    24  					testAccCheckUltradnsRecordExists("ultradns_dirpool.it", &record),
    25  					// Specified
    26  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "zone", domain),
    27  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "name", "test-dirpool-minimal"),
    28  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "type", "A"),
    29  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "ttl", "300"),
    30  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "description", "Minimal directional pool"),
    31  					// hashRdatas(): 10.1.0.1 -> 463398947
    32  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.463398947.host", "10.1.0.1"),
    33  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.463398947.all_non_configured", "true"),
    34  					// Generated
    35  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "id", "test-dirpool-minimal.ultradns.phinze.com"),
    36  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "hostname", "test-dirpool-minimal.ultradns.phinze.com."),
    37  				),
    38  			},
    39  			resource.TestStep{
    40  				Config: fmt.Sprintf(testCfgDirpoolMaximal, domain),
    41  				Check: resource.ComposeTestCheckFunc(
    42  					testAccCheckUltradnsRecordExists("ultradns_dirpool.it", &record),
    43  					// Specified
    44  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "zone", domain),
    45  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "name", "test-dirpool-maximal"),
    46  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "type", "A"),
    47  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "ttl", "300"),
    48  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "description", "Description of pool"),
    49  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "conflict_resolve", "GEO"),
    50  
    51  					// hashRdatas(): 10.1.1.1 -> 442270228
    52  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.442270228.host", "10.1.1.1"),
    53  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.442270228.all_non_configured", "true"),
    54  					// hashRdatas(): 10.1.1.2 -> 2203440046
    55  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.2203440046.host", "10.1.1.2"),
    56  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.2203440046.geo_info.0.name", "North America"),
    57  					// hashRdatas(): 10.1.1.3 -> 4099072824
    58  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.4099072824.host", "10.1.1.3"),
    59  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.4099072824.ip_info.0.name", "some Ips"),
    60  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "no_response.0.geo_info.0.name", "nrGeo"),
    61  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "no_response.0.ip_info.0.name", "nrIP"),
    62  					// Generated
    63  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "id", "test-dirpool-maximal.ultradns.phinze.com"),
    64  					resource.TestCheckResourceAttr("ultradns_dirpool.it", "hostname", "test-dirpool-maximal.ultradns.phinze.com."),
    65  				),
    66  			},
    67  		},
    68  	})
    69  }
    70  
    71  func testAccDirpoolCheckDestroy(s *terraform.State) error {
    72  	client := testAccProvider.Meta().(*udnssdk.Client)
    73  
    74  	for _, rs := range s.RootModule().Resources {
    75  		if rs.Type != "ultradns_dirpool" {
    76  			continue
    77  		}
    78  
    79  		k := udnssdk.RRSetKey{
    80  			Zone: rs.Primary.Attributes["zone"],
    81  			Name: rs.Primary.Attributes["name"],
    82  			Type: rs.Primary.Attributes["type"],
    83  		}
    84  
    85  		_, err := client.RRSets.Select(k)
    86  
    87  		if err == nil {
    88  			return fmt.Errorf("Record still exists")
    89  		}
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  const testCfgDirpoolMinimal = `
    96  resource "ultradns_dirpool" "it" {
    97    zone        = "%s"
    98    name        = "test-dirpool-minimal"
    99    type        = "A"
   100    ttl         = 300
   101    description = "Minimal directional pool"
   102  
   103    rdata {
   104      host = "10.1.0.1"
   105      all_non_configured = true
   106    }
   107  }
   108  `
   109  
   110  const testCfgDirpoolMaximal = `
   111  resource "ultradns_dirpool" "it" {
   112    zone        = "%s"
   113    name        = "test-dirpool-maximal"
   114    type        = "A"
   115    ttl         = 300
   116    description = "Description of pool"
   117  
   118    conflict_resolve = "GEO"
   119  
   120    rdata {
   121      host               = "10.1.1.1"
   122      all_non_configured = true
   123    }
   124  
   125    rdata {
   126      host = "10.1.1.2"
   127  
   128      geo_info {
   129        name = "North America"
   130  
   131        codes = [
   132          "US-OK",
   133          "US-DC",
   134          "US-MA",
   135        ]
   136      }
   137    }
   138  
   139    rdata {
   140      host = "10.1.1.3"
   141  
   142      ip_info {
   143        name = "some Ips"
   144  
   145        ips {
   146          start = "200.20.0.1"
   147          end   = "200.20.0.10"
   148        }
   149  
   150        ips {
   151          cidr = "20.20.20.0/24"
   152        }
   153  
   154        ips {
   155          address = "50.60.70.80"
   156        }
   157      }
   158    }
   159  
   160  #   rdata {
   161  #     host = "10.1.1.4"
   162  #
   163  #     geo_info {
   164  #       name             = "accountGeoGroup"
   165  #       is_account_level = true
   166  #     }
   167  #
   168  #     ip_info {
   169  #       name             = "accountIPGroup"
   170  #       is_account_level = true
   171  #     }
   172  #   }
   173  
   174    no_response {
   175      geo_info {
   176        name = "nrGeo"
   177  
   178        codes = [
   179          "Z4",
   180        ]
   181      }
   182  
   183      ip_info {
   184        name = "nrIP"
   185  
   186        ips {
   187          address = "197.231.41.3"
   188        }
   189      }
   190    }
   191  }
   192  `