diff --git a/infoblox/datasource_infoblox_a_record_test.go b/infoblox/datasource_infoblox_a_record_test.go index 3bc3e4340..b237f8070 100644 --- a/infoblox/datasource_infoblox_a_record_test.go +++ b/infoblox/datasource_infoblox_a_record_test.go @@ -26,10 +26,15 @@ func TestAccDataSourceARecord(t *testing.T) { } var testAccDataSourceARecordsRead = fmt.Sprintf(` +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" +} + resource "infoblox_a_record" "foo"{ dns_view="default" fqdn="test-name.test.com" ip_addr="10.0.0.20" + depends_on = [infoblox_zone_auth.test] } data "infoblox_a_record" "acctest" { @@ -48,6 +53,9 @@ func TestAccDataSourceARecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } resource "infoblox_a_record" "arec1"{ ip_addr = "10.4.0.18" fqdn = "sample.test.com" @@ -56,6 +64,7 @@ func TestAccDataSourceARecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Location": "Las Vegas" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_a_record" "ds1" { @@ -70,7 +79,7 @@ func TestAccDataSourceARecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_a_record.ds1", "results.0.ip_addr", "10.4.0.18"), resource.TestCheckResourceAttr("data.infoblox_a_record.ds1", "results.0.fqdn", "sample.test.com"), resource.TestCheckResourceAttr("data.infoblox_a_record.ds1", "results.0.comment", "test sample A-record"), - resource.TestCheckResourceAttr("data.infoblox_a_record.ds1", "results.0.ext_attrs", "{\"Location\":\"Las Vegas\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_a_record.ds1", "results.0.ext_attrs.Location", "infoblox_a_record.arec1", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/datasource_infoblox_aaaa_record_test.go b/infoblox/datasource_infoblox_aaaa_record_test.go index e6e1ebb87..141fabe6f 100644 --- a/infoblox/datasource_infoblox_aaaa_record_test.go +++ b/infoblox/datasource_infoblox_aaaa_record_test.go @@ -26,10 +26,14 @@ func TestAccDataSourceAAAARecord(t *testing.T) { } var testAccDataSourceAAAARecordsRead = fmt.Sprintf(` +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" +} resource "infoblox_aaaa_record" "foo"{ dns_view="default" fqdn="aaaa-test.test.com" ipv6_addr="2002:1111::7" + depends_on = [infoblox_zone_auth.test] } data "infoblox_aaaa_record" "acctest" { @@ -48,6 +52,9 @@ func TestAccDataSourceAAAARecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "qarec1"{ ipv6_addr = "2002:1f93:0:4::11" fqdn = "sampleqa.test.com" @@ -56,6 +63,7 @@ func TestAccDataSourceAAAARecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Location": "Norway" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_aaaa_record" "dqa1" { @@ -71,7 +79,7 @@ func TestAccDataSourceAAAARecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_aaaa_record.dqa1", "results.0.ipv6_addr", "2002:1f93:0:4::11"), resource.TestCheckResourceAttr("data.infoblox_aaaa_record.dqa1", "results.0.fqdn", "sampleqa.test.com"), resource.TestCheckResourceAttr("data.infoblox_aaaa_record.dqa1", "results.0.comment", "test sample AAAA-record"), - resource.TestCheckResourceAttr("data.infoblox_aaaa_record.dqa1", "results.0.ext_attrs", "{\"Location\":\"Norway\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_aaaa_record.dqa1", "results.0.ext_attrs.Location", "infoblox_aaaa_record.qarec1", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/datasource_infoblox_cname_record_test.go b/infoblox/datasource_infoblox_cname_record_test.go index eaa8e0e6f..90869eeda 100644 --- a/infoblox/datasource_infoblox_cname_record_test.go +++ b/infoblox/datasource_infoblox_cname_record_test.go @@ -26,11 +26,15 @@ func TestAccDataSourceCNameRecord(t *testing.T) { } var testAccDataSourceCNameRecordsRead = fmt.Sprintf(` +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" +} resource "infoblox_cname_record" "foo"{ dns_view="default" alias="test.test.com" - canonical="test-name.test.com" + canonical="test-name.test.com" + depends_on = [infoblox_zone_auth.test] } data "infoblox_cname_record" "acctest" { @@ -49,6 +53,9 @@ func TestAccDataSourceCNameRecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } resource "infoblox_cname_record" "cname1"{ canonical = "somewhere.in.the.net" alias = "samplecname.test.com" @@ -57,6 +64,7 @@ func TestAccDataSourceCNameRecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Site": "test site one" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_cname_record" "dcname1" { @@ -71,7 +79,7 @@ func TestAccDataSourceCNameRecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_cname_record.dcname1", "results.0.canonical", "somewhere.in.the.net"), resource.TestCheckResourceAttr("data.infoblox_cname_record.dcname1", "results.0.alias", "samplecname.test.com"), resource.TestCheckResourceAttr("data.infoblox_cname_record.dcname1", "results.0.comment", "test sample CName-record"), - resource.TestCheckResourceAttr("data.infoblox_cname_record.dcname1", "results.0.ext_attrs", "{\"Site\":\"test site one\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_cname_record.dcname1", "results.0.ext_attrs.Site", "infoblox_cname_record.cname1", "ext_attrs.Site"), ), }, }, diff --git a/infoblox/datasource_infoblox_dns_view_test.go b/infoblox/datasource_infoblox_dns_view_test.go index df707c869..9131df69e 100644 --- a/infoblox/datasource_infoblox_dns_view_test.go +++ b/infoblox/datasource_infoblox_dns_view_test.go @@ -67,7 +67,7 @@ func TestAccDataSourceDNSViewSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_dns_view.accview", "results.0.name", "customview"), resource.TestCheckResourceAttr("data.infoblox_dns_view.accview", "results.0.network_view", "default"), resource.TestCheckResourceAttr("data.infoblox_dns_view.accview", "results.0.comment", "new dns view example"), - resource.TestCheckResourceAttr("data.infoblox_dns_view.accview", "results.0.ext_attrs", "{\"Site\":\"Main DNS Site\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_dns_view.accview", "results.0.ext_attrs.Site", "infoblox_dns_view.dview1", "ext_attrs.Site"), ), }, }, diff --git a/infoblox/datasource_infoblox_mx_record_test.go b/infoblox/datasource_infoblox_mx_record_test.go index bcec7e415..68baa4d3e 100644 --- a/infoblox/datasource_infoblox_mx_record_test.go +++ b/infoblox/datasource_infoblox_mx_record_test.go @@ -19,7 +19,6 @@ func TestAccDataSourceMXRecord(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_mx_record.rec1", "results.0.fqdn", "test-name.test.com"), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec1", "results.0.mail_exchanger", "mx-test.test.com"), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec1", "results.0.preference", "25"), - //resource.TestCheckResourceAttr("data.infoblox_mx_record.rec1", "ttl", ""), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec1", "results.0.comment", ""), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec2", "results.0.dns_view", "nondefault_view"), @@ -28,7 +27,7 @@ func TestAccDataSourceMXRecord(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_mx_record.rec2", "results.0.preference", "25"), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec2", "results.0.ttl", "10"), resource.TestCheckResourceAttr("data.infoblox_mx_record.rec2", "results.0.comment", "non-empty comment"), - resource.TestCheckResourceAttr("data.infoblox_mx_record.rec2", "results.0.ext_attrs", "{\"Site\":\"None\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_mx_record.rec2", "results.0.ext_attrs.Site", "infoblox_mx_record.rec2", "ext_attrs.Site"), ), }, }, @@ -36,11 +35,16 @@ func TestAccDataSourceMXRecord(t *testing.T) { } var testAccDataSourceMXRecordsRead = fmt.Sprintf(` +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" +} + resource "infoblox_mx_record" "rec1" { dns_view = "default" fqdn = "test-name.test.com" mail_exchanger = "mx-test.test.com" preference = 25 + depends_on = [infoblox_zone_auth.test] } data "infoblox_mx_record" "rec1" { @@ -54,6 +58,17 @@ data "infoblox_mx_record" "rec1" { depends_on = [infoblox_mx_record.rec1] } +resource "infoblox_dns_view" "view" { + name = "nondefault_view" + network_view = "default" +} + +resource "infoblox_zone_auth" "test2" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view] +} + resource "infoblox_mx_record" "rec2" { dns_view = "nondefault_view" fqdn = "test-name2.test.com" @@ -65,6 +80,7 @@ resource "infoblox_mx_record" "rec2" { ext_attrs = jsonencode({ "Site": "None" }) + depends_on = [infoblox_zone_auth.test2] } data "infoblox_mx_record" "rec2" { @@ -86,6 +102,10 @@ func TestAccDataSourceMXRecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } + resource "infoblox_mx_record" "mx1"{ fqdn = "samplemx.test.com" mail_exchanger = "exdemo.test.com" @@ -96,6 +116,7 @@ func TestAccDataSourceMXRecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Site": "Some automated site" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_mx_record" "dmx1" { @@ -111,7 +132,7 @@ func TestAccDataSourceMXRecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_mx_record.dmx1", "results.0.preference", "30"), resource.TestCheckResourceAttr("data.infoblox_mx_record.dmx1", "results.0.fqdn", "samplemx.test.com"), resource.TestCheckResourceAttr("data.infoblox_mx_record.dmx1", "results.0.comment", "new sample mx-record"), - resource.TestCheckResourceAttr("data.infoblox_mx_record.dmx1", "results.0.ext_attrs", "{\"Site\":\"Some automated site\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_mx_record.dmx1", "results.0.ext_attrs.Site", "infoblox_mx_record.mx1", "ext_attrs.Site"), ), }, }, diff --git a/infoblox/datasource_infoblox_network_container_test.go b/infoblox/datasource_infoblox_network_container_test.go index 3fec81735..f2441835c 100644 --- a/infoblox/datasource_infoblox_network_container_test.go +++ b/infoblox/datasource_infoblox_network_container_test.go @@ -17,7 +17,7 @@ func TestAccDataSourceNetworkContainer(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.#", "1"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.cidr", "10.4.20.0/24"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.comment", "network container #1"), - resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.ext_attrs", "{\"Location\":\"North Pole\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ipv4_network_container.ds1", "results.0.ext_attrs.Location", "infoblox_ipv4_network_container.nc1", "ext_attrs.Location"), ), }, }, @@ -67,7 +67,7 @@ func TestAccDataSourceNetworkCOntainerSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.#", "1"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.cidr", "10.4.20.0/24"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.comment", "network container #1"), - resource.TestCheckResourceAttr("data.infoblox_ipv4_network_container.ds1", "results.0.ext_attrs", "{\"Location\":\"North Pole\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ipv4_network_container.ds1", "results.0.ext_attrs.Location", "infoblox_ipv4_network_container.nc1", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/datasource_infoblox_network_test.go b/infoblox/datasource_infoblox_network_test.go index c8155a64c..25645b6f9 100644 --- a/infoblox/datasource_infoblox_network_test.go +++ b/infoblox/datasource_infoblox_network_test.go @@ -62,7 +62,7 @@ func TestAccDataSourceNetworkReadByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_ipv4_network.acctest", "results.0.network_view", "default"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network.acctest", "results.0.cidr", "10.4.20.0/24"), resource.TestCheckResourceAttr("data.infoblox_ipv4_network.acctest", "results.0.comment", "Created by terraform-provider-infoblox acceptance test"), - resource.TestCheckResourceAttr("data.infoblox_ipv4_network.acctest", "results.0.ext_attrs", "{\"Building\":\"AcceptanceTerraform\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ipv4_network.acctest", "results.0.ext_attrs.Building", "infoblox_ipv4_network.test_network", "ext_attrs.Building"), ), }, }, diff --git a/infoblox/datasource_infoblox_network_view_test.go b/infoblox/datasource_infoblox_network_view_test.go index 8bbfe5c95..68f245fba 100644 --- a/infoblox/datasource_infoblox_network_view_test.go +++ b/infoblox/datasource_infoblox_network_view_test.go @@ -32,7 +32,7 @@ func TestAccDataSourceNetworkViewReadByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_network_view.acctest", "results.#", "1"), resource.TestCheckResourceAttr("data.infoblox_network_view.acctest", "results.0.name", "testNetworkView"), resource.TestCheckResourceAttr("data.infoblox_network_view.acctest", "results.0.comment", "test comment 1"), - resource.TestCheckResourceAttr("data.infoblox_network_view.acctest", "results.0.ext_attrs", "{\"Location\":\"AcceptanceTerraform\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_network_view.acctest", "results.0.ext_attrs.Location", "infoblox_network_view.test_network_view", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/datasource_infoblox_ptr_record_test.go b/infoblox/datasource_infoblox_ptr_record_test.go index cfc1d2385..111bf804a 100644 --- a/infoblox/datasource_infoblox_ptr_record_test.go +++ b/infoblox/datasource_infoblox_ptr_record_test.go @@ -20,14 +20,14 @@ func TestAccDataSourcePTRRecord(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds1", "results.0.ip_addr", "2002:1f93::10"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds1", "results.0.ttl", "300"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds1", "results.0.comment", "workstation #1"), - resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds1", "results.0.ext_attrs", "{\"Location\":\"the main office\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ptr_record.ds1", "results.0.ext_attrs.Location", "infoblox_ptr_record.rec1", "ext_attrs.Location"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.dns_view", "default"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.ptrdname", "rec2.test.com"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.ip_addr", "10.0.0.101"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.ttl", "301"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.comment", "workstation #2"), - resource.TestCheckResourceAttr("data.infoblox_ptr_record.ds2", "results.0.ext_attrs", "{\"Location\":\"the external office\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ptr_record.ds2", "results.0.ext_attrs.Location", "infoblox_ptr_record.rec2", "ext_attrs.Location"), ), }, }, @@ -35,6 +35,23 @@ func TestAccDataSourcePTRRecord(t *testing.T) { } var testAccDataSourcePTRRecordsRead = ` +resource "infoblox_dns_view" "view" { + name = "nondefault_dnsview1" +} + +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + view = "nondefault_dnsview1" + depends_on = [infoblox_dns_view.view] +} + +resource "infoblox_zone_auth" "itest" { + fqdn = "2002:1f93::/64" + view = "nondefault_dnsview1" + zone_format = "IPV6" + depends_on = [infoblox_dns_view.view] +} + resource "infoblox_ptr_record" "rec1" { ptrdname = "rec1.test.com" dns_view = "nondefault_dnsview1" @@ -44,27 +61,38 @@ resource "infoblox_ptr_record" "rec1" { ext_attrs = jsonencode({ "Location" = "the main office" }) + depends_on = [infoblox_zone_auth.test, infoblox_zone_auth.itest] } data "infoblox_ptr_record" "ds1" { - filters = { - ptrdname = "rec1.test.com" - view = "nondefault_dnsview1" - ipv6addr = "2002:1f93::10" - } + filters = { + ptrdname = "rec1.test.com" + view = "nondefault_dnsview1" + ipv6addr = "2002:1f93::10" + } + + depends_on = [infoblox_ptr_record.rec1] +} - depends_on = [infoblox_ptr_record.rec1] +resource "infoblox_zone_auth" "test1" { + fqdn = "test.com" } +resource "infoblox_zone_auth" "itest1" { + fqdn = "10.0.0.0/24" + zone_format = "IPV4" + depends_on = [infoblox_zone_auth.test1] +} resource "infoblox_ptr_record" "rec2" { - ptrdname = "rec2.test.com" - // the default 'dns_view' - ip_addr = "10.0.0.101" - comment = "workstation #2" - ttl = 301 - ext_attrs = jsonencode({ - "Location" = "the external office" - }) + ptrdname = "rec2.test.com" + // the default 'dns_view' + ip_addr = "10.0.0.101" + comment = "workstation #2" + ttl = 301 + ext_attrs = jsonencode({ + "Location" = "the external office" + }) + depends_on = [infoblox_zone_auth.test1, infoblox_zone_auth.itest1] } data "infoblox_ptr_record" "ds2" { @@ -85,6 +113,14 @@ func TestAccDataSourcePTRRecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } + resource "infoblox_zone_auth" "itest" { + fqdn = "10.0.0.0/24" + zone_format = "IPV4" + depends_on = [infoblox_zone_auth.test] + } resource "infoblox_ptr_record" "ptr1"{ ptrdname = "decoyptr.test.com" ip_addr = "10.0.0.89" @@ -93,6 +129,7 @@ func TestAccDataSourcePTRRecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Location" = "PTR test location" }) + depends_on = [infoblox_zone_auth.itest, infoblox_zone_auth.test] } data "infoblox_ptr_record" "dptr1" { @@ -107,7 +144,7 @@ func TestAccDataSourcePTRRecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_ptr_record.dptr1", "results.0.ip_addr", "10.0.0.89"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.dptr1", "results.0.ptrdname", "decoyptr.test.com"), resource.TestCheckResourceAttr("data.infoblox_ptr_record.dptr1", "results.0.comment", "new sample ptr-record"), - resource.TestCheckResourceAttr("data.infoblox_ptr_record.dptr1", "results.0.ext_attrs", "{\"Location\":\"PTR test location\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_ptr_record.dptr1", "results.0.ext_attrs.Location", "infoblox_ptr_record.ptr1", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/datasource_infoblox_srv_record_test.go b/infoblox/datasource_infoblox_srv_record_test.go index 9e9478ff9..e64cb31df 100644 --- a/infoblox/datasource_infoblox_srv_record_test.go +++ b/infoblox/datasource_infoblox_srv_record_test.go @@ -23,7 +23,7 @@ func TestAccDataSourceSRVRecord(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_srv_record.srec1", "results.0.weight", "40"), resource.TestCheckResourceAttr("data.infoblox_srv_record.srec1", "results.0.ttl", "10"), resource.TestCheckResourceAttr("data.infoblox_srv_record.srec1", "results.0.comment", "testing SRV-record datasource"), - resource.TestCheckResourceAttr("data.infoblox_srv_record.srec1", "results.0.ext_attrs", "{\"Site\":\"Moon\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_srv_record.srec1", "results.0.ext_attrs.Site", "infoblox_srv_record.rec1", "ext_attrs.Site"), resource.TestCheckResourceAttr("data.infoblox_srv_record.srec2", "results.0.dns_view", "default"), resource.TestCheckResourceAttr("data.infoblox_srv_record.srec2", "results.0.name", "_http._tcp.test.com"), @@ -40,6 +40,14 @@ func TestAccDataSourceSRVRecord(t *testing.T) { } var testAccDataSourceSRVRecordsRead = fmt.Sprintf(` +resource "infoblox_dns_view" "view" { + name = "nondefault_view" +} +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view] +} resource "infoblox_srv_record" "rec1" { dns_view = "nondefault_view" name = "_http._tcp.test.com" @@ -52,6 +60,7 @@ resource "infoblox_srv_record" "rec1" { ext_attrs = jsonencode({ "Site": "Moon" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_srv_record" "srec1" { @@ -65,12 +74,16 @@ data "infoblox_srv_record" "srec1" { depends_on = [infoblox_srv_record.rec1] } +resource "infoblox_zone_auth" "test1" { + fqdn = "test.com" +} resource "infoblox_srv_record" "rec2" { name = "_http._tcp.test.com" priority = 50 weight = 40 port = 8080 target = "www2.test.com" + depends_on = [infoblox_zone_auth.test1] } data "infoblox_srv_record" "srec2" { @@ -92,6 +105,9 @@ func TestAccDataSourceSRVRecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } resource "infoblox_srv_record" "srv1"{ name = "_http._udp.test.com" priority = 40 @@ -103,6 +119,7 @@ func TestAccDataSourceSRVRecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Site" = "test srv site" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_srv_record" "dsrv1" { @@ -120,7 +137,7 @@ func TestAccDataSourceSRVRecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_srv_record.dsrv1", "results.0.port", "5080"), resource.TestCheckResourceAttr("data.infoblox_srv_record.dsrv1", "results.0.target", "random.test.com"), resource.TestCheckResourceAttr("data.infoblox_srv_record.dsrv1", "results.0.comment", "new sample srv-record"), - resource.TestCheckResourceAttr("data.infoblox_srv_record.dsrv1", "results.0.ext_attrs", "{\"Site\":\"test srv site\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_srv_record.dsrv1", "results.0.ext_attrs.Site", "infoblox_srv_record.srv1", "ext_attrs.Site"), ), }, }, diff --git a/infoblox/datasource_infoblox_txt_record_test.go b/infoblox/datasource_infoblox_txt_record_test.go index 566eb2b7b..1673ed351 100644 --- a/infoblox/datasource_infoblox_txt_record_test.go +++ b/infoblox/datasource_infoblox_txt_record_test.go @@ -21,7 +21,7 @@ func TestAccDataSourceTXTRecord(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_txt_record.ds1", "results.0.text", "some text for a TXT-record"), resource.TestCheckResourceAttr("data.infoblox_txt_record.ds1", "results.0.ttl", "30"), resource.TestCheckResourceAttr("data.infoblox_txt_record.ds1", "results.0.comment", "this is a test TXT-record"), - resource.TestCheckResourceAttr("data.infoblox_txt_record.ds1", "results.0.ext_attrs", "{\"Site\":\"Greenland\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_txt_record.ds1", "results.0.ext_attrs.Site", "infoblox_txt_record.rec1", "ext_attrs.Site"), resource.TestCheckResourceAttr("data.infoblox_txt_record.ds2", "results.0.dns_view", "nondefault_view"), resource.TestCheckResourceAttr("data.infoblox_txt_record.ds2", "results.0.fqdn", "test-name2.test.com"), @@ -36,6 +36,10 @@ func TestAccDataSourceTXTRecord(t *testing.T) { } var testAccDataSourceTXTRecordsRead = fmt.Sprintf(` +resource "infoblox_zone_auth" "test" { + fqdn = "test.com" +} + resource "infoblox_txt_record" "rec1"{ dns_view = "default" fqdn = "test-name1.test.com" @@ -45,6 +49,7 @@ resource "infoblox_txt_record" "rec1"{ ext_attrs = jsonencode({ "Site": "Greenland" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_txt_record" "ds1"{ @@ -56,10 +61,21 @@ data "infoblox_txt_record" "ds1"{ depends_on = [infoblox_txt_record.rec1] } +resource "infoblox_dns_view" "view" { + name = "nondefault_view" +} + +resource "infoblox_zone_auth" "test2" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view] +} + resource "infoblox_txt_record" "rec2"{ dns_view = "nondefault_view" fqdn = "test-name2.test.com" text = "some text for a TXT-record 2" + depends_on = [infoblox_zone_auth.test2] } data "infoblox_txt_record" "ds2"{ @@ -79,6 +95,10 @@ func TestAccDataSourceTXTRecordSearchByEA(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "test" { + fqdn = "test.com" + } + resource "infoblox_txt_record" "txt1"{ dns_view = "default" fqdn = "newtxt.test.com" @@ -88,6 +108,7 @@ func TestAccDataSourceTXTRecordSearchByEA(t *testing.T) { ext_attrs = jsonencode({ "Site" = "sample text site" }) + depends_on = [infoblox_zone_auth.test] } data "infoblox_txt_record" "dtxt1" { @@ -103,7 +124,7 @@ func TestAccDataSourceTXTRecordSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_txt_record.dtxt1", "results.0.text", "some text for a TXT-record"), resource.TestCheckResourceAttr("data.infoblox_txt_record.dtxt1", "results.0.ttl", "30"), resource.TestCheckResourceAttr("data.infoblox_txt_record.dtxt1", "results.0.comment", "new sample txt-record"), - resource.TestCheckResourceAttr("data.infoblox_txt_record.dtxt1", "results.0.ext_attrs", "{\"Site\":\"sample text site\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_txt_record.dtxt1", "results.0.ext_attrs.Site", "infoblox_txt_record.txt1", "ext_attrs.Site"), ), }, }, diff --git a/infoblox/datasource_infoblox_zone_auth_test.go b/infoblox/datasource_infoblox_zone_auth_test.go index 05a661bff..ccbd13ab3 100644 --- a/infoblox/datasource_infoblox_zone_auth_test.go +++ b/infoblox/datasource_infoblox_zone_auth_test.go @@ -112,7 +112,7 @@ func TestAccDataSourceZoneAuthSearchByEA(t *testing.T) { resource.TestCheckResourceAttr("data.infoblox_zone_auth.dzone1", "results.0.fqdn", "17.1.0.0/16"), resource.TestCheckResourceAttr("data.infoblox_zone_auth.dzone1", "results.0.comment", "test sample reverse zone"), resource.TestCheckResourceAttr("data.infoblox_zone_auth.dzone1", "results.0.zone_format", "IPV4"), - resource.TestCheckResourceAttr("data.infoblox_zone_auth.dzone1", "results.0.ext_attrs", "{\"Location\":\"Test Zone Location\"}"), + resource.TestCheckResourceAttrPair("data.infoblox_zone_auth.dzone1", "results.0.ext_attrs.Location", "infoblox_zone_auth.zone1", "ext_attrs.Location"), ), }, }, diff --git a/infoblox/resource_infoblox_a_record_test.go b/infoblox/resource_infoblox_a_record_test.go index 5c83b0e2e..e87b19f70 100644 --- a/infoblox/resource_infoblox_a_record_test.go +++ b/infoblox/resource_infoblox_a_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "net" @@ -42,18 +43,36 @@ func testAccARecordCompare( if !found { return fmt.Errorf("not found: %s", resPath) } - if res.Primary.ID == "" { + + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetARecordByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") } + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + recA, err := objMgr.SearchObjectByAltId("A", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } + } + // Assertion of object type and error handling + var rec *ibclient.RecordA + recJson, _ := json.Marshal(recA) + err = json.Unmarshal(recJson, &rec) + if rec.Name == nil { return fmt.Errorf("'fqdn' is expected to be defined but it is not") } @@ -150,6 +169,14 @@ func TestAccResourceARecord(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } resource "infoblox_a_record" "foo"{ fqdn = "name1.test.com" ip_addr = "10.0.0.2" @@ -160,6 +187,14 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } resource "infoblox_a_record" "foo"{ fqdn = "name1.test.com" }`), @@ -167,15 +202,25 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } resource "infoblox_a_record" "foo"{ fqdn = "name1.test.com" ip_addr = "10.0.0.2" + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo", &ibclient.RecordA{ Ipv4Addr: utils.StringPtr("10.0.0.2"), Name: utils.StringPtr("name1.test.com"), - View: "default", + View: "nondefault_view", Ttl: utils.Uint32Ptr(0), UseTtl: utils.BoolPtr(false), Comment: nil, @@ -185,6 +230,14 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } resource "infoblox_a_record" "foo2"{ fqdn = "name2.test.com" ip_addr = "192.168.31.31" @@ -195,6 +248,7 @@ func TestAccResourceARecord(t *testing.T) { "Location" = "New York" "Site" = "HQ" }) + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -213,12 +267,19 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" ip_addr = "10.10.0.1" ttl = 155 dns_view = "nondefault_view" comment = "test comment 2" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -233,10 +294,17 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" ip_addr = "10.10.0.1" dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -249,15 +317,22 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_ipv4_network" "net1" { - cidr = "10.20.30.0/24" - network_view = "default" - } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } + resource "infoblox_ipv4_network" "net1" { + cidr = "10.20.30.0/24" + network_view = "default" + } + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" - cidr = infoblox_ipv4_network.net1.cidr - network_view = infoblox_ipv4_network.net1.network_view + cidr = infoblox_ipv4_network.net1.cidr + network_view = infoblox_ipv4_network.net1.network_view dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_ipv4_network.net1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -269,30 +344,44 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_ipv4_network" "netA" { - cidr = "11.20.0.0/24" - network_view = "default" - } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } + resource "infoblox_ipv4_network" "netA" { + cidr = "11.20.0.0/24" + network_view = "default" + } + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" - cidr = infoblox_ipv4_network.netA.cidr + cidr = infoblox_ipv4_network.netA.cidr ip_addr = "10.10.0.7" - network_view = infoblox_ipv4_network.netA.network_view + network_view = infoblox_ipv4_network.netA.network_view dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_ipv4_network.netA, infoblox_dns_view.view1] }`), ExpectError: regexpUpdateConflictIPv4, }, { Config: fmt.Sprintf(` - resource "infoblox_ipv4_network" "net2" { - cidr = "10.20.33.0/24" - network_view = "default" - } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } + resource "infoblox_ipv4_network" "net2" { + cidr = "10.20.33.0/24" + network_view = "default" + } + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" - cidr = infoblox_ipv4_network.net2.cidr - network_view = infoblox_ipv4_network.net2.network_view + cidr = infoblox_ipv4_network.net2.cidr + network_view = infoblox_ipv4_network.net2.network_view dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_ipv4_network.net2, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -304,27 +393,39 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_network_view" "view1" { name = "nondefault_netview" } - resource "infoblox_ipv4_network" "net3" { - cidr = "10.20.34.0/24" - network_view = infoblox_network_view.view1.name - } + resource "infoblox_ipv4_network" "net3" { + cidr = "10.20.34.0/24" + network_view = infoblox_network_view.view1.name + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" - cidr = infoblox_ipv4_network.net3.cidr - network_view = infoblox_ipv4_network.net3.network_view + cidr = infoblox_ipv4_network.net3.cidr + network_view = infoblox_ipv4_network.net3.network_view dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_network_view.view1, infoblox_ipv4_network.net3] }`), ExpectError: regexpNetviewUpdateNotAllowed, }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view1.name + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" ip_addr = "10.10.0.2" dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccARecordCompare(t, "infoblox_a_record.foo2", &ibclient.RecordA{ @@ -337,10 +438,14 @@ func TestAccResourceARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo2"{ fqdn = "name3.test.com" ip_addr = "10.10.0.2" dns_view = "default" + depends_on = [infoblox_zone_auth.zone1] }`), ExpectError: regexpDnsviewUpdateNotAllowed, }, @@ -353,9 +458,13 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckARecordDestroy, + Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo3"{ dns_view = "default" fqdn = "samplearec2.test.com" @@ -364,6 +473,7 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test location A" }) + depends_on = [infoblox_zone_auth.zone1] }`, Check: testAccARecordCompare(t, "infoblox_a_record.foo3", &ibclient.RecordA{ Ipv4Addr: utils.StringPtr("10.1.0.2"), @@ -407,6 +517,9 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo3"{ dns_view = "default" fqdn = "samplearec2.test.com" @@ -415,6 +528,7 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test location A" }) + depends_on = [infoblox_zone_auth.zone1] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -439,6 +553,9 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo3"{ dns_view = "default" fqdn = "samplearec2.test.com" @@ -447,6 +564,7 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test location A" }) + depends_on = [infoblox_zone_auth.zone1] }`, Check: testAccARecordCompare(t, "infoblox_a_record.foo3", &ibclient.RecordA{ Ipv4Addr: utils.StringPtr("10.1.0.2"), @@ -463,6 +581,9 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo3"{ dns_view = "default" fqdn = "samplearec2.test.com" @@ -472,6 +593,7 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { "Location" = "test location A" "Site" = "new extensible site" }) + depends_on = [infoblox_zone_auth.zone1] }`, Check: testAccARecordCompare(t, "infoblox_a_record.foo3", &ibclient.RecordA{ Ipv4Addr: utils.StringPtr("10.1.0.2"), @@ -488,6 +610,9 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + } resource "infoblox_a_record" "foo3"{ dns_view = "default" fqdn = "samplearec2.test.com" @@ -496,6 +621,7 @@ func TestAcc_resourceARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test location A" }) + depends_on = [infoblox_zone_auth.zone1] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_aaaa_record_test.go b/infoblox/resource_infoblox_aaaa_record_test.go index 8e390c062..d8d084047 100644 --- a/infoblox/resource_infoblox_aaaa_record_test.go +++ b/infoblox/resource_infoblox_aaaa_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "net" @@ -42,17 +43,34 @@ func testAccAAAARecordCompare( if !found { return fmt.Errorf("not found: %s", resPath) } - if res.Primary.ID == "" { + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetAAAARecordByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + recAAAA, err := objMgr.SearchObjectByAltId("AAAA", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } } + // Assertion of object type and error handling + var rec *ibclient.RecordAAAA + recJson, _ := json.Marshal(recAAAA) + err = json.Unmarshal(recJson, &rec) if rec.Name == nil { return fmt.Errorf("'fqdn' is expected to be defined but it is not") @@ -147,6 +165,10 @@ func TestAccResourceAAAARecord(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + view = "default" + } resource "infoblox_aaaa_record" "foo"{ fqdn = "name1.test.com" ipv6_addr = "2000::1" @@ -157,6 +179,10 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + view = "default" + } resource "infoblox_aaaa_record" "foo"{ fqdn = "name1.test.com" }`), @@ -164,9 +190,14 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + view = "default" + } resource "infoblox_aaaa_record" "foo"{ fqdn = "name1.test.com" ipv6_addr = "2000::1" + depends_on = [infoblox_zone_auth.zone] }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo", &ibclient.RecordAAAA{ @@ -182,6 +213,14 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } resource "infoblox_aaaa_record" "foo2"{ fqdn = "name2.test.com" ipv6_addr = "2002::10" @@ -192,6 +231,7 @@ func TestAccResourceAAAARecord(t *testing.T) { "Location" = "New York" "Site" = "HQ" }) + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ @@ -210,13 +250,22 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - ipv6_addr = "2000::1" - ttl = 155 - dns_view = "nondefault_view" - comment = "test comment 2" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + ipv6_addr = "2000::1" + ttl = 155 + dns_view = "nondefault_view" + comment = "test comment 2" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] + }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2000::1"), @@ -230,11 +279,20 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - ipv6_addr = "2000::1" - dns_view = "nondefault_view" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + ipv6_addr = "2000::1" + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] + }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2000::1"), @@ -246,16 +304,25 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_ipv6_network" "net1" { - cidr = "2000:1fde::/96" - network_view = "default" - } - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - cidr = infoblox_ipv6_network.net1.cidr - network_view = infoblox_ipv6_network.net1.network_view - dns_view = "nondefault_view" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_ipv6_network" "net1" { + cidr = "2000:1fde::/96" + network_view = "default" + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + cidr = infoblox_ipv6_network.net1.cidr + network_view = infoblox_ipv6_network.net1.network_view + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1, infoblox_ipv6_network.net1] + }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ Name: utils.StringPtr("name3.test.com"), @@ -266,31 +333,49 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_ipv6_network" "netA" { - cidr = "2000:1fcc::/96" - network_view = "default" - } - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - cidr = infoblox_ipv6_network.netA.cidr - ipv6_addr = "2002::4" - network_view = infoblox_ipv6_network.netA.network_view - dns_view = "nondefault_view" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_ipv6_network" "netA" { + cidr = "2000:1fcc::/96" + network_view = "default" + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + cidr = infoblox_ipv6_network.netA.cidr + ipv6_addr = "2002::4" + network_view = infoblox_ipv6_network.netA.network_view + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1, infoblox_ipv6_network.netA] + }`), ExpectError: regexpUpdateConflictIPv6, }, { Config: fmt.Sprintf(` - resource "infoblox_ipv6_network" "net2" { - cidr = "2000:1fcc::/96" - network_view = "default" - } - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - cidr = infoblox_ipv6_network.net2.cidr - network_view = infoblox_ipv6_network.net2.network_view - dns_view = "nondefault_view" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_ipv6_network" "netA" { + cidr = "2000:1fcc::/96" + network_view = "default" + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + cidr = infoblox_ipv6_network.netA.cidr + network_view = infoblox_ipv6_network.netA.network_view + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1, infoblox_ipv6_network.netA] + }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ Name: utils.StringPtr("name3.test.com"), @@ -301,28 +386,49 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_network_view" "view1" { - name = "nondefault_netview" - } - resource "infoblox_ipv6_network" "net3" { - cidr = "2000:1fcd::/96" - network_view = infoblox_network_view.view1.name - } - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - cidr = infoblox_ipv6_network.net3.cidr - network_view = infoblox_ipv6_network.net3.network_view - dns_view = "nondefault_view" - }`), + resource "infoblox_network_view" "netview1" { + name = "nondefault_netview" + } + resource "infoblox_dns_view" "view2" { + name = "nondefault_view" + network_view = "nondefault_view" + depends_on = [infoblox_network_view.netview1] + + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view2] + } + + resource "infoblox_ipv6_network" "net3" { + cidr = "2000:1fcd::/96" + network_view = infoblox_network_view.netview1.name + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + cidr = infoblox_ipv6_network.net3.cidr + network_view = infoblox_ipv6_network.net3.network_view + dns_view = "nondefault_view" + }`), ExpectError: regexpNetviewUpdateNotAllowed, }, { Config: fmt.Sprintf(` - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - ipv6_addr = "2000::2" - dns_view = "nondefault_view" - }`), + resource "infoblox_dns_view" "view1" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = "nondefault_view" + depends_on = [infoblox_dns_view.view1] + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + ipv6_addr = "2000::2" + dns_view = "nondefault_view" + depends_on = [infoblox_zone_auth.zone1, infoblox_dns_view.view1] + }`), Check: resource.ComposeTestCheckFunc( testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo2", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2000::2"), @@ -334,11 +440,16 @@ func TestAccResourceAAAARecord(t *testing.T) { }, { Config: fmt.Sprintf(` - resource "infoblox_aaaa_record" "foo2"{ - fqdn = "name3.test.com" - ipv6_addr = "2000::2" - dns_view = "default" - }`), + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + view = "default" + } + resource "infoblox_aaaa_record" "foo2"{ + fqdn = "name3.test.com" + ipv6_addr = "2000::2" + dns_view = "default" + depends_on = [infoblox_zone_auth.zone] + }`), ExpectError: regexpDnsviewUpdateNotAllowed, }, }, @@ -353,6 +464,9 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "foo3"{ dns_view = "default" fqdn = "testname2.test.com" @@ -361,6 +475,7 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test AAAA location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo3", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2002::4"), @@ -404,6 +519,9 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "foo3"{ dns_view = "default" fqdn = "testname2.test.com" @@ -412,6 +530,7 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test AAAA location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -436,6 +555,9 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "foo3"{ dns_view = "default" fqdn = "testname2.test.com" @@ -444,6 +566,7 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test AAAA location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo3", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2002::4"), @@ -460,6 +583,9 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "foo3"{ dns_view = "default" fqdn = "testname2.test.com" @@ -469,6 +595,7 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { "Location" = "test AAAA location" "Site" = "New Testing Site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccAAAARecordCompare(t, "infoblox_aaaa_record.foo3", &ibclient.RecordAAAA{ Ipv6Addr: utils.StringPtr("2002::4"), @@ -485,6 +612,9 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_aaaa_record" "foo3"{ dns_view = "default" fqdn = "testname2.test.com" @@ -493,6 +623,7 @@ func TestAcc_resourceAAAARecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "test AAAA location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_cname_record_test.go b/infoblox/resource_infoblox_cname_record_test.go index fbdb14c67..db5ad52a2 100644 --- a/infoblox/resource_infoblox_cname_record_test.go +++ b/infoblox/resource_infoblox_cname_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "testing" @@ -11,6 +12,9 @@ import ( ) var testAccresourceCNAMERecordCreate = fmt.Sprintf(` +resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" +} resource "infoblox_cname_record" "foo"{ dns_view="default" canonical="test-canonicalName.test.com" @@ -20,12 +24,14 @@ resource "infoblox_cname_record" "foo"{ "Tenant ID" = "terraform_test_tenant" "Location" = "Test loc" "Site" = "Test site" - "TestEA1"=["text1","text2"] }) - + depends_on=[infoblox_zone_auth.zone] }`) var testAccresourceCNAMERecordUpdate = fmt.Sprintf(` +resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" +} resource "infoblox_cname_record" "foo"{ dns_view="default" canonical="test-canonicalName.test.com" @@ -35,9 +41,8 @@ resource "infoblox_cname_record" "foo"{ "Tenant ID" = "terraform_test_tenant" "Location" = "Test loc 2" "Site" = "Test site 2" - "TestEA1"="text3" }) - + depends_on=[infoblox_zone_auth.zone] }`) func validateRecordCNAME( @@ -49,6 +54,16 @@ func validateRecordCNAME( return fmt.Errorf("not found: %s", resourceName) } + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + id := res.Primary.ID if id == "" { return fmt.Errorf("ID is not set") @@ -58,16 +73,20 @@ func validateRecordCNAME( objMgr := ibclient.NewObjectManager( connector, "terraform_test", - "terraform_test_tenant") - recCNAME, err := objMgr.GetCNAMERecordByRef(id) + "test") + rec, err := objMgr.SearchObjectByAltId("CNAME", ref, internalId, eaNameForInternalId) if err != nil { if isNotFoundError(err) { if expectedValue == nil { return nil } - return fmt.Errorf("object with ID '%s' not found, but expected to exist", id) + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) } } + // Assertion of object type and error handling + var recCNAME *ibclient.RecordCNAME + recJson, _ := json.Marshal(rec) + err = json.Unmarshal(recJson, &recCNAME) expCanonical := *expectedValue.Canonical if *recCNAME.Canonical != expCanonical { @@ -128,7 +147,6 @@ func TestAccResourceCNAMERecord(t *testing.T) { "Tenant ID": "terraform_test_tenant", "Location": "Test loc", "Site": "Test site", - "TestEA1": []string{"text1", "text2"}, }, }, ), @@ -147,7 +165,6 @@ func TestAccResourceCNAMERecord(t *testing.T) { "Tenant ID": "terraform_test_tenant", "Location": "Test loc 2", "Site": "Test site 2", - "TestEA1": "text3", }, }, ), @@ -188,6 +205,9 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_cname_record" "foo1"{ dns_view="default" canonical="test.somewhere.net" @@ -197,6 +217,7 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" "Site" = "Marking site" }) + depends_on=[infoblox_zone_auth.zone] }`, Check: validateRecordCNAME( "infoblox_cname_record.foo1", @@ -243,6 +264,9 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_cname_record" "foo1"{ dns_view="default" canonical="test.somewhere.net" @@ -252,6 +276,7 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" "Site" = "Marking site" }) + depends_on=[infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Location EA, since it's omitted by provider @@ -280,6 +305,9 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_cname_record" "foo1"{ dns_view="default" canonical="testhidden.somewhere.net" @@ -289,6 +317,7 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" "Site" = "Marking site" }) + depends_on=[infoblox_zone_auth.zone] }`, Check: validateRecordCNAME( "infoblox_cname_record.foo1", @@ -309,6 +338,9 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_cname_record" "foo1"{ dns_view="default" canonical="test.somewhere.net" @@ -319,6 +351,7 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { "Site" = "Marking site" "Location" = "New California" }) + depends_on=[infoblox_zone_auth.zone] }`, Check: validateRecordCNAME( "infoblox_cname_record.foo1", @@ -339,6 +372,9 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_cname_record" "foo1"{ dns_view="default" canonical="test.somewhere.net" @@ -348,6 +384,7 @@ func TestAcc_resourceCNAMERecord_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" "Site" = "Marking site" }) + depends_on=[infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_dns_view_test.go b/infoblox/resource_infoblox_dns_view_test.go index cf50ee4bb..51936a499 100644 --- a/infoblox/resource_infoblox_dns_view_test.go +++ b/infoblox/resource_infoblox_dns_view_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -225,22 +226,36 @@ func validateDnsView( return fmt.Errorf("ID is not set") } - conn := testAccProvider.Meta().(ibclient.IBConnector) - v := &ibclient.View{} - v.SetReturnFields([]string{"name", "comment", "network_view", "extattrs"}) + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } - actualView := ibclient.View{} + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } - err := conn.GetObject(v, id, nil, &actualView) + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + rec, err := objMgr.SearchObjectByAltId("DNSView", ref, internalId, eaNameForInternalId) if err != nil { if isNotFoundError(err) { if expectedValue == nil { return nil } - return fmt.Errorf("object with ID '%s' not found, but expected to exist", id) + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) } } + // Assertion of object type and error handling + var actualView *ibclient.View + recJson, _ := json.Marshal(rec) + err = json.Unmarshal(recJson, &actualView) + if *actualView.Name != *expectedValue.Name { return fmt.Errorf( "the value of 'name' field is '%s', but expected '%s'", diff --git a/infoblox/resource_infoblox_ip_allocation_test.go b/infoblox/resource_infoblox_ip_allocation_test.go index 8fd99908d..746b1389a 100644 --- a/infoblox/resource_infoblox_ip_allocation_test.go +++ b/infoblox/resource_infoblox_ip_allocation_test.go @@ -241,6 +241,9 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -254,6 +257,7 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Location = "Test loc." Site = "Test site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -277,6 +281,9 @@ func TestAcc_resourceIPAllocation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -291,6 +298,7 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Location = "Test loc." Site = "Test site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -316,6 +324,9 @@ func TestAcc_resourceIPAllocation(t *testing.T) { // Validate that ipv6_addr can be removed { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -328,6 +339,7 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Location = "Test loc." Site = "Test site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -350,6 +362,9 @@ func TestAcc_resourceIPAllocation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ipv4_network" "net1" { cidr = "10.0.0.0/24" } @@ -365,7 +380,7 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Location = "Test loc." Site = "Test site" }) - depends_on = [infoblox_ipv4_network.net1] + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -388,6 +403,9 @@ func TestAcc_resourceIPAllocation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ipv4_network" "net1" { cidr = "10.0.0.0/24" } @@ -403,6 +421,7 @@ func TestAcc_resourceIPAllocation(t *testing.T) { Location = "Test loc." Site = "Test site" }) + depends_on = [infoblox_zone_auth.zone, infoblox_ipv4_network.net1] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -435,6 +454,9 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -447,6 +469,7 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" Location = "Test loc." }) + depends_on = [infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -498,6 +521,9 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -510,6 +536,7 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" Location = "Test loc." }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -542,6 +569,9 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -554,6 +584,7 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" Location = "Test loc." }) + depends_on = [infoblox_zone_auth.zone] }`, // Actual API object should have EA Check: validateIPAllocation( @@ -579,6 +610,9 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -592,6 +626,7 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { Location = "Test loc." Site = "Updated test site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: validateIPAllocation( "infoblox_ip_allocation.foo3", @@ -616,6 +651,9 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_ip_allocation" "foo3"{ network_view="default" dns_view = "default" @@ -628,6 +666,7 @@ func TestAcc_resourceIPAllocation_ea_inheritance(t *testing.T) { "Tenant ID" = "terraform_test_tenant" Location = "Test loc." }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_ip_association_test.go b/infoblox/resource_infoblox_ip_association_test.go index 327b073c5..6d3484f8f 100644 --- a/infoblox/resource_infoblox_ip_association_test.go +++ b/infoblox/resource_infoblox_ip_association_test.go @@ -198,6 +198,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -213,7 +216,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1] + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -242,6 +245,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -262,7 +268,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -296,6 +302,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -315,7 +324,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -349,6 +358,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -369,7 +381,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -403,6 +415,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -422,7 +437,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -456,6 +471,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -476,7 +494,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { @@ -510,6 +528,9 @@ func TestAcc_resourceipAssociation(t *testing.T) { }, { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource infoblox_ipv4_network "net1" { cidr = "10.0.0.0/24" } @@ -530,7 +551,7 @@ func TestAcc_resourceipAssociation(t *testing.T) { "Location" = "Test loc." "Site" = "Test site" }) - depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2] + depends_on = [infoblox_ipv4_network.net1, infoblox_ipv6_network.net2, infoblox_zone_auth.zone] } resource "infoblox_ip_association" "foo" { diff --git a/infoblox/resource_infoblox_mx_record_test.go b/infoblox/resource_infoblox_mx_record_test.go index 6dc4c5232..5bb57a713 100644 --- a/infoblox/resource_infoblox_mx_record_test.go +++ b/infoblox/resource_infoblox_mx_record_test.go @@ -1,8 +1,10 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -34,17 +36,44 @@ func testAccMXRecordCompare(t *testing.T, resPath string, expectedRec *ibclient. if !found { return fmt.Errorf("not found: %s", resPath) } + + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + if res.Primary.ID == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetMXRecordByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + recMx, err := objMgr.SearchObjectByAltId("MX", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } } + // Assertion of object type and error handling + var rec *ibclient.RecordMX + recJson, _ := json.Marshal(recMx) + err = json.Unmarshal(recJson, &rec) + + //rec, _ := objMgr.GetMXRecordByRef(res.Primary.ID) + //if rec == nil { + // return fmt.Errorf("record not found") + //} if *rec.Name != *expectedRec.Name { return fmt.Errorf( @@ -85,146 +114,208 @@ func testAccMXRecordCompare(t *testing.T, resPath string, expectedRec *ibclient. *rec.Ttl, *expectedRec.Ttl) } } - if *rec.Comment != *expectedRec.Comment { - return fmt.Errorf( - "'comment' does not match: got '%s', expected '%s'", - *rec.Comment, *expectedRec.Comment) + + expComment := *expectedRec.Comment + if expComment != "" { + if *rec.Comment != expComment { + return fmt.Errorf( + "'comment' does not match: got '%s', expected '%s'", + *rec.Comment, *expectedRec.Comment) + } } + return validateEAs(rec.Ea, expectedRec.Ea) } } -//func TestAccResourceMXRecord(t *testing.T) { -// resource.Test(t, resource.TestCase{ -// PreCheck: func() { testAccPreCheck(t) }, -// Providers: testAccProviders, -// CheckDestroy: testAccCheckMXRecordDestroy, -// Steps: []resource.TestStep{ -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo"{ -// fqdn = "name1.test.com" -// mail_exchanger = "sample.mx1.com" -// preference = 25 -// }`), -// Check: resource.ComposeTestCheckFunc( -// testAccMXRecordCompare(t, "infoblox_mx_record.foo", &ibclient.RecordMX{ -// View: utils.StringPtr("default"), -// Name: utils.StringPtr("name1.test.com"), -// MailExchanger: utils.StringPtr("sample.mx1.com"), -// Preference: utils.Uint32Ptr(25), -// Ttl: utils.Uint32Ptr(0), -// UseTtl: utils.BoolPtr(false), -// Comment: utils.StringPtr(""), -// Ea: nil, -// }), -// ), -// }, -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo1"{ -// fqdn = "name2.test.com" -// mail_exchanger = "sample.mx2.com" -// preference = 30 -// ttl = 300 -// dns_view = "nondefault_view" -// comment = "test comment 1" -// ext_attrs = jsonencode({ -// "Location" = "Los Angeles" -// "Site" = "HQ" -// }) -// }`), -// Check: resource.ComposeTestCheckFunc( -// testAccMXRecordCompare(t, "infoblox_mx_record.foo1", &ibclient.RecordMX{ -// Name: utils.StringPtr("name2.test.com"), -// MailExchanger: utils.StringPtr("sample.mx2.com"), -// Preference: utils.Uint32Ptr(30), -// View: utils.StringPtr("nondefault_view"), -// Ttl: utils.Uint32Ptr(300), -// UseTtl: utils.BoolPtr(true), -// Comment: utils.StringPtr("test comment 1"), -// Ea: ibclient.EA{ -// "Location": "Los Angeles", -// "Site": "HQ", -// }, -// }), -// ), -// }, -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo2"{ -// fqdn = "name3.test.com" -// mail_exchanger = "sample.mx3.com" -// preference = 35 -// ttl = 150 -// dns_view = "nondefault_view" -// comment = "test comment 2" -// }`), -// Check: resource.ComposeTestCheckFunc( -// testAccMXRecordCompare(t, "infoblox_mx_record.foo2", &ibclient.RecordMX{ -// Name: utils.StringPtr("name3.test.com"), -// MailExchanger: utils.StringPtr("sample.mx3.com"), -// Preference: utils.Uint32Ptr(35), -// View: utils.StringPtr("nondefault_view"), -// Ttl: utils.Uint32Ptr(150), -// UseTtl: utils.BoolPtr(true), -// Comment: utils.StringPtr("test comment 2"), -// }), -// ), -// }, -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo3"{ -// fqdn = "name3.test.com" -// dns_view = "nondefault_view" -// mail_exchanger = "sample.mx3.com" -// preference = 35 -// }`), -// Check: resource.ComposeTestCheckFunc( -// testAccMXRecordCompare(t, "infoblox_mx_record.foo3", &ibclient.RecordMX{ -// Name: utils.StringPtr("name3.test.com"), -// View: utils.StringPtr("nondefault_view"), -// MailExchanger: utils.StringPtr("sample.mx3.com"), -// Preference: utils.Uint32Ptr(35), -// }), -// ), -// }, -// -// // negative test cases -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo3"{ -// fqdn = "name3.test.com" -// dns_view = "nondefault_view" -// mail_exchanger = "sample.mx3.com" -// preference = 350000 -// }`), -// ExpectError: regexp.MustCompile("'preference' must be integer and must be in the range from 0 to 65535 inclusively"), -// }, -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo3"{ -// fqdn = "name3.test.com" -// dns_view = "nondefault_view" -// mail_exchanger = "sample.mx3.com" -// preference = 35 -// ttl = -1 -// }`), -// ExpectError: regexp.MustCompile("TTL value must be 0 or higher"), -// }, -// { -// Config: fmt.Sprintf(` -// resource "infoblox_mx_record" "foo3"{ -// fqdn = "name3.test.com" -// dns_view = "nondefault_view2" -// mail_exchanger = "sample.mx3.com" -// preference = 35 -// }`), -// ExpectError: regexp.MustCompile("changing the value of 'dns_view' field is not allowed"), -// }, -// }, -// }) -//} +func TestAccResourceMXRecord(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMXRecordDestroy, + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } + resource "infoblox_mx_record" "foo"{ + fqdn = "name1.test.com" + mail_exchanger = "sample.mx1.com" + preference = 25 + depends_on = [infoblox_zone_auth.zone] + }`), + Check: resource.ComposeTestCheckFunc( + testAccMXRecordCompare(t, "infoblox_mx_record.foo", &ibclient.RecordMX{ + View: utils.StringPtr("default"), + Name: utils.StringPtr("name1.test.com"), + MailExchanger: utils.StringPtr("sample.mx1.com"), + Preference: utils.Uint32Ptr(25), + Ttl: utils.Uint32Ptr(0), + UseTtl: utils.BoolPtr(false), + Comment: utils.StringPtr(""), + Ea: nil, + }), + ), + }, + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo1"{ + fqdn = "name2.test.com" + mail_exchanger = "sample.mx2.com" + preference = 30 + ttl = 300 + dns_view = "nondefault_view" + comment = "test comment 1" + ext_attrs = jsonencode({ + "Location" = "Los Angeles" + "Site" = "HQ" + }) + depends_on = [infoblox_zone_auth.zone1] + }`), + Check: resource.ComposeTestCheckFunc( + testAccMXRecordCompare(t, "infoblox_mx_record.foo1", &ibclient.RecordMX{ + Name: utils.StringPtr("name2.test.com"), + MailExchanger: utils.StringPtr("sample.mx2.com"), + Preference: utils.Uint32Ptr(30), + View: utils.StringPtr("nondefault_view"), + Ttl: utils.Uint32Ptr(300), + UseTtl: utils.BoolPtr(true), + Comment: utils.StringPtr("test comment 1"), + Ea: ibclient.EA{ + "Location": "Los Angeles", + "Site": "HQ", + }, + }), + ), + }, + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo2"{ + fqdn = "name3.test.com" + mail_exchanger = "sample.mx3.com" + preference = 35 + ttl = 150 + dns_view = "nondefault_view" + comment = "test comment 2" + depends_on = [infoblox_zone_auth.zone1] + }`), + Check: resource.ComposeTestCheckFunc( + testAccMXRecordCompare(t, "infoblox_mx_record.foo2", &ibclient.RecordMX{ + Name: utils.StringPtr("name3.test.com"), + MailExchanger: utils.StringPtr("sample.mx3.com"), + Preference: utils.Uint32Ptr(35), + View: utils.StringPtr("nondefault_view"), + Ttl: utils.Uint32Ptr(150), + UseTtl: utils.BoolPtr(true), + Comment: utils.StringPtr("test comment 2"), + Ea: nil, + }), + ), + }, + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo3"{ + fqdn = "name4.test.com" + dns_view = "nondefault_view" + mail_exchanger = "sample.mx3.com" + preference = 35 + depends_on = [infoblox_zone_auth.zone1] + }`), + Check: resource.ComposeTestCheckFunc( + testAccMXRecordCompare(t, "infoblox_mx_record.foo3", &ibclient.RecordMX{ + Name: utils.StringPtr("name4.test.com"), + View: utils.StringPtr("nondefault_view"), + MailExchanger: utils.StringPtr("sample.mx3.com"), + Preference: utils.Uint32Ptr(35), + Ttl: utils.Uint32Ptr(0), + UseTtl: utils.BoolPtr(false), + Comment: utils.StringPtr(""), + Ea: nil, + }), + ), + }, + + // negative test cases + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo3"{ + fqdn = "name4.test.com" + dns_view = "nondefault_view" + mail_exchanger = "sample.mx3.com" + preference = 350000 + depends_on = [infoblox_zone_auth.zone1] + }`), + ExpectError: regexp.MustCompile("'preference' must be integer and must be in the range from 0 to 65535 inclusively"), + }, + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo3"{ + fqdn = "name4.test.com" + dns_view = "nondefault_view" + mail_exchanger = "sample.mx3.com" + preference = 35 + ttl = -1 + depends_on = [infoblox_zone_auth.zone1] + }`), + ExpectError: regexp.MustCompile("TTL value must be 0 or higher"), + }, + { + Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } + resource "infoblox_mx_record" "foo3"{ + fqdn = "name4.test.com" + dns_view = "nondefault_view2" + mail_exchanger = "sample.mx3.com" + preference = 35 + depends_on = [infoblox_zone_auth.zone1] + }`), + ExpectError: regexp.MustCompile("changing the value of 'dns_view' field is not allowed"), + }, + }, + }) +} func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { resource.Test(t, resource.TestCase{ @@ -234,6 +325,9 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_mx_record" "foo4"{ dns_view = "default" fqdn = "testdemo.test.com" @@ -243,6 +337,7 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Test MX Location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccMXRecordCompare(t, "infoblox_mx_record.foo4", &ibclient.RecordMX{ Name: utils.StringPtr("testdemo.test.com"), @@ -285,6 +380,9 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_mx_record" "foo4"{ dns_view = "default" fqdn = "testdemo.test.com" @@ -294,6 +392,7 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Test MX Location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -318,6 +417,9 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_mx_record" "foo4"{ dns_view = "default" fqdn = "testdemo.test.com" @@ -343,6 +445,9 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_mx_record" "foo4"{ dns_view = "default" fqdn = "testdemo.test.com" @@ -353,6 +458,7 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { "Location" = "Test MX Location" "Site" = "New Modern site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccMXRecordCompare(t, "infoblox_mx_record.foo4", &ibclient.RecordMX{ Name: utils.StringPtr("testdemo.test.com"), @@ -369,6 +475,9 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_mx_record" "foo4"{ dns_view = "default" fqdn = "testdemo.test.com" @@ -378,6 +487,7 @@ func TestAcc_resourceMXRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Test MX Location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_network_container_test.go b/infoblox/resource_infoblox_network_container_test.go index 59a331e2a..b77d42ba6 100644 --- a/infoblox/resource_infoblox_network_container_test.go +++ b/infoblox/resource_infoblox_network_container_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "regexp" "testing" @@ -24,21 +25,34 @@ func validateNetworkContainer( return fmt.Errorf("ID is not set") } + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + connector := testAccProvider.Meta().(ibclient.IBConnector) objMgr := ibclient.NewObjectManager( connector, "terraform_test", - "terraform_test_tenant") - - nc, err := objMgr.GetNetworkContainerByRef(id) + "test") + recA, err := objMgr.SearchObjectByAltId("NetworkContainer", ref, internalId, eaNameForInternalId) if err != nil { if isNotFoundError(err) { if expectedValue == nil { return nil } - return fmt.Errorf("object with ID '%s' not found, but expected to exist", id) + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) } } + // Assertion of object type and error handling + var nc *ibclient.NetworkContainer + recJson, _ := json.Marshal(recA) + err = json.Unmarshal(recJson, &nc) expNv := expectedValue.NetviewName if nc.NetviewName != expNv { diff --git a/infoblox/resource_infoblox_network_test.go b/infoblox/resource_infoblox_network_test.go index 2a77bd0c1..2ac4fc593 100644 --- a/infoblox/resource_infoblox_network_test.go +++ b/infoblox/resource_infoblox_network_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -23,20 +24,35 @@ func validateNetwork( return fmt.Errorf("ID is not set") } + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + connector := testAccProvider.Meta().(ibclient.IBConnector) objMgr := ibclient.NewObjectManager( connector, "terraform_test", - "terraform_test_tenant") - nw, err := objMgr.GetNetworkByRef(id) + "test") + nwObj, err := objMgr.SearchObjectByAltId("Network", ref, internalId, eaNameForInternalId) if err != nil { if isNotFoundError(err) { if expectedValue == nil { return nil } - return fmt.Errorf("object with ID '%s' not found, but expected to exist", id) + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) } } + // Assertion of object type and error handling + var nw *ibclient.Network + recJson, _ := json.Marshal(nwObj) + err = json.Unmarshal(recJson, &nw) + expNv := expectedValue.NetviewName if nw.NetviewName != expNv { return fmt.Errorf( diff --git a/infoblox/resource_infoblox_network_view_test.go b/infoblox/resource_infoblox_network_view_test.go index a7b4d8d30..e3f705dea 100644 --- a/infoblox/resource_infoblox_network_view_test.go +++ b/infoblox/resource_infoblox_network_view_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "testing" @@ -34,17 +35,39 @@ func testAccNetworkViewCompare(t *testing.T, resPath string, expectedRec *ibclie if !found { return fmt.Errorf("Not found: %s", resPath) } + + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + if res.Primary.ID == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetNetworkViewByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + nw, err := objMgr.SearchObjectByAltId("NetworkView", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } } + // Assertion of object type and error handling + var rec *ibclient.NetworkView + recJson, _ := json.Marshal(nw) + err = json.Unmarshal(recJson, &rec) if rec.Name == nil { return fmt.Errorf("network view's 'name' field is expected to be defined but it is not") diff --git a/infoblox/resource_infoblox_ptr_record_expected_data_00.go b/infoblox/resource_infoblox_ptr_record_expected_data_00.go index 35e0c45b2..e48a9d1ce 100644 --- a/infoblox/resource_infoblox_ptr_record_expected_data_00.go +++ b/infoblox/resource_infoblox_ptr_record_expected_data_00.go @@ -12,7 +12,7 @@ var testCasePtrRecordExpectedData00 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("1.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target1.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: nil, Comment: nil, @@ -24,7 +24,7 @@ var testCasePtrRecordExpectedData00 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("2.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target2.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: nil, Comment: nil, @@ -44,11 +44,11 @@ var testCasePtrRecordExpectedData00 = map[string]*ibclient.RecordPTR{ }, "infoblox_ptr_record.rec4": { View: "default", - Ipv4Addr: utils.StringPtr("10.0.0.202"), + Ipv4Addr: utils.StringPtr("10.0.0.201"), Ipv6Addr: nil, - Name: utils.StringPtr("202.0.0.10.in-addr.arpa"), + Name: utils.StringPtr("201.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target4.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: nil, Comment: nil, @@ -140,9 +140,9 @@ var testCasePtrRecordExpectedData00 = map[string]*ibclient.RecordPTR{ }, "infoblox_ptr_record.rec12": { View: "nondefault_dnsview1", - Ipv4Addr: utils.StringPtr("10.0.0.203"), + Ipv4Addr: utils.StringPtr("10.0.0.202"), Ipv6Addr: nil, - Name: utils.StringPtr("203.0.0.10.in-addr.arpa"), + Name: utils.StringPtr("202.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target12.example2.org"), Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(true), @@ -168,7 +168,7 @@ var testCasePtrRecordExpectedData00 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("14.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target14.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: nil, Comment: nil, diff --git a/infoblox/resource_infoblox_ptr_record_expected_data_01.go b/infoblox/resource_infoblox_ptr_record_expected_data_01.go index 12e24cb63..4716a162e 100644 --- a/infoblox/resource_infoblox_ptr_record_expected_data_01.go +++ b/infoblox/resource_infoblox_ptr_record_expected_data_01.go @@ -12,7 +12,7 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("1.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target1.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(true), Ttl: utils.Uint32Ptr(5), Comment: utils.StringPtr("non-empty comment"), @@ -24,7 +24,7 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("32.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target2.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: utils.Uint32Ptr(0), Comment: nil, @@ -48,7 +48,7 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("201.0.16.172.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target4.example1.org"), - Zone: "0.16.172.in-addr.arpa", + Zone: "16.172.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: utils.Uint32Ptr(0), Comment: nil, @@ -57,8 +57,8 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ "infoblox_ptr_record.rec5": { View: "default", Ipv4Addr: nil, - Ipv6Addr: utils.StringPtr("2002:1f93::cb"), - Name: utils.StringPtr("b.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), + Ipv6Addr: utils.StringPtr("2002:1f93::c9"), + Name: utils.StringPtr("9.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), PtrdName: utils.StringPtr("ptr-target5.example1.org"), Zone: "0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa", UseTtl: utils.BoolPtr(true), @@ -69,8 +69,8 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ "infoblox_ptr_record.rec6": { View: "default", Ipv4Addr: nil, - Ipv6Addr: utils.StringPtr("2002:1f93::cc"), - Name: utils.StringPtr("c.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), + Ipv6Addr: utils.StringPtr("2002:1f93::ca"), + Name: utils.StringPtr("a.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), PtrdName: utils.StringPtr("ptr-target6.example1.org"), Zone: "0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa", UseTtl: utils.BoolPtr(false), @@ -81,8 +81,8 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ "infoblox_ptr_record.rec7": { View: "default", Ipv4Addr: nil, - Ipv6Addr: utils.StringPtr("2002:1f93::c9"), - Name: utils.StringPtr("9.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), + Ipv6Addr: utils.StringPtr("2002:1f93::cb"), + Name: utils.StringPtr("b.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), PtrdName: utils.StringPtr("ptr-target7.example1.org"), Zone: "0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa", UseTtl: utils.BoolPtr(false), @@ -105,8 +105,8 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ "infoblox_ptr_record.rec9": { View: "nondefault_dnsview1", Ipv4Addr: nil, - Ipv6Addr: utils.StringPtr("2002:1f93::ca"), - Name: utils.StringPtr("a.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), + Ipv6Addr: utils.StringPtr("2002:1f93::cc"), + Name: utils.StringPtr("c.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa"), PtrdName: utils.StringPtr("ptr-target9.example2.org"), Zone: "0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa", UseTtl: utils.BoolPtr(true), @@ -168,7 +168,7 @@ var testCasePtrRecordExpectedData01 = map[string]*ibclient.RecordPTR{ Ipv6Addr: nil, Name: utils.StringPtr("44.0.0.10.in-addr.arpa"), PtrdName: utils.StringPtr("ptr-target14.example1.org"), - Zone: "0.0.10.in-addr.arpa", + Zone: "10.in-addr.arpa", UseTtl: utils.BoolPtr(false), Ttl: utils.Uint32Ptr(0), Comment: nil, diff --git a/infoblox/resource_infoblox_ptr_record_test.go b/infoblox/resource_infoblox_ptr_record_test.go index 2544c11e0..2f5d701f4 100644 --- a/infoblox/resource_infoblox_ptr_record_test.go +++ b/infoblox/resource_infoblox_ptr_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "regexp" "testing" @@ -35,20 +36,34 @@ func validateRecordPTR( return fmt.Errorf("ID is not set") } + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + connector := testAccProvider.Meta().(ibclient.IBConnector) objMgr := ibclient.NewObjectManager( connector, "terraform_test", - "terraform_test_tenant") - recPtr, err := objMgr.GetPTRRecordByRef(id) + "test") + recPTR, err := objMgr.SearchObjectByAltId("PTR", ref, internalId, eaNameForInternalId) if err != nil { if isNotFoundError(err) { if expectedValue == nil { return nil } - return fmt.Errorf("object with ID '%s' not found, but expected to exist", id) + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) } } + // Assertion of object type and error handling + var recPtr *ibclient.RecordPTR + recJson, _ := json.Marshal(recPTR) + err = json.Unmarshal(recJson, &recPtr) if recPtr.PtrdName == nil { return fmt.Errorf("'ptrdname' is expected to be defined but it is not") @@ -180,7 +195,7 @@ func testAccCheckRecordPTRDestroy(s *terraform.State) error { return nil } -func TestAcc_resourceRecordPTR(t *testing.T) { +func TestAcc_resourceRecordPTR_test1(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -190,10 +205,30 @@ func TestAcc_resourceRecordPTR(t *testing.T) { Config: testCasePtrRecordTestData00, Check: validateFuncForSetOfRecordPTR(testCasePtrRecordExpectedData00), }, + }, + }) +} + +func TestAcc_resourceRecordPTR_test2(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRecordPTRDestroy, + Steps: []resource.TestStep{ { Config: testCasePtrRecordTestData01, Check: validateFuncForSetOfRecordPTR(testCasePtrRecordExpectedData01), }, + }, + }) +} + +func TestAcc_resourceRecordPTR_test3(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRecordPTRDestroy, + Steps: []resource.TestStep{ { Config: testCasePtrRecordTestErrData01, ExpectError: regexp.MustCompile("only one of 'ip_addr', 'cidr' and 'record_name' must be defined"), diff --git a/infoblox/resource_infoblox_ptr_record_test_data_00.go b/infoblox/resource_infoblox_ptr_record_test_data_00.go index 770229070..e0d24add1 100644 --- a/infoblox/resource_infoblox_ptr_record_test_data_00.go +++ b/infoblox/resource_infoblox_ptr_record_test_data_00.go @@ -1,192 +1,254 @@ package infoblox const testCasePtrRecordTestData00 = ` + +resource "infoblox_network_view" "netview1" { + name = "nondefault_netview" +} + resource "infoblox_ipv4_network" "net1" { - cidr = "10.0.0.0/8" - reserve_ip = 200 + cidr = "10.0.0.0/8" + reserve_ip = 200 } resource "infoblox_ipv4_network" "net2" { - cidr = "172.16.0.0/16" - reserve_ip = 200 + cidr = "172.16.0.0/16" + reserve_ip = 200 } resource "infoblox_ipv6_network" "net1" { - cidr = "2002:1f93::/64" - reserve_ipv6 = 200 + cidr = "2002:1f93::/64" + reserve_ipv6 = 200 } resource "infoblox_ipv6_network" "net2" { - cidr = "2002:1f94::/64" - reserve_ipv6 = 200 + cidr = "2002:1f94::/64" + reserve_ipv6 = 200 } resource "infoblox_ipv6_network" "net3" { - network_view = "nondefault_netview" - cidr = "2002:1f93::/64" - reserve_ipv6 = 200 + network_view = "nondefault_netview" + cidr = "2002:1f93::/64" + reserve_ipv6 = 200 + depends_on = [infoblox_network_view.netview1] } resource "infoblox_ipv6_network" "net4" { - network_view = "nondefault_netview" - cidr = "2002:1f94::/64" - reserve_ipv6 = 200 + network_view = "nondefault_netview" + cidr = "2002:1f94::/64" + reserve_ipv6 = 200 + depends_on = [infoblox_network_view.netview1] +} + +resource "infoblox_zone_auth" "zone1" { + fqdn = "example1.org" +} + +resource "infoblox_zone_auth" "izone1" { + fqdn = "10.0.0.0/8" + zone_format = "IPV4" + depends_on = [infoblox_ipv4_network.net1] } resource "infoblox_ptr_record" "rec1" { - ptrdname = "ptr-target1.example1.org" - ip_addr = "10.0.0.1" + ptrdname = "ptr-target1.example1.org" + ip_addr = "10.0.0.1" + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1] } resource "infoblox_ptr_record" "rec2" { - ptrdname = "ptr-target2.example1.org" - record_name = "2.0.0.10.in-addr.arpa" - - depends_on = [infoblox_ptr_record.rec1] + ptrdname = "ptr-target2.example1.org" + record_name = "2.0.0.10.in-addr.arpa" + + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1, infoblox_ptr_record.rec1] } resource "infoblox_ptr_record" "rec3" { - ptrdname = "ptr-target3.example1.org" - record_name = "ptr-rec3.example1.org" - - depends_on = [infoblox_ptr_record.rec2] + ptrdname = "ptr-target3.example1.org" + record_name = "ptr-rec3.example1.org" + + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1, infoblox_ptr_record.rec2] } resource "infoblox_ptr_record" "rec4" { - ptrdname = "ptr-target4.example1.org" - cidr = "10.0.0.0/8" + ptrdname = "ptr-target4.example1.org" + cidr = "10.0.0.0/8" + + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1, infoblox_ptr_record.rec3] +} - depends_on = [infoblox_ipv4_network.net1, infoblox_ptr_record.rec3] +resource "infoblox_zone_auth" "izone2" { + fqdn = "2002:1f93::/64" + zone_format = "IPV6" } resource "infoblox_ptr_record" "rec5" { - dns_view = "default" - ptrdname = "ptr-target5.example1.org" - ip_addr = "2002:1f93::5" - comment = "workstation #5" - ttl = 300 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ptr_record.rec4] + dns_view = "default" + ptrdname = "ptr-target5.example1.org" + ip_addr = "2002:1f93::5" + comment = "workstation #5" + ttl = 300 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone2, infoblox_ptr_record.rec4] } resource "infoblox_ptr_record" "rec6" { - dns_view = "default" - ptrdname = "ptr-target6.example1.org" - record_name = "6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa" - comment = "workstation #6" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ptr_record.rec5] + dns_view = "default" + ptrdname = "ptr-target6.example1.org" + record_name = "6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa" + comment = "workstation #6" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone2, infoblox_ptr_record.rec5] } resource "infoblox_ptr_record" "rec7" { - dns_view = "default" - network_view = "default" - ptrdname = "ptr-target7.example1.org" - cidr = "2002:1f93::/64" - comment = "workstation #7" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ipv6_network.net1, infoblox_ptr_record.rec6] + dns_view = "default" + network_view = "default" + ptrdname = "ptr-target7.example1.org" + cidr = "2002:1f93::/64" + comment = "workstation #7" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone2, infoblox_ptr_record.rec6] } resource "infoblox_ptr_record" "rec8" { - dns_view = "default" - ptrdname = "ptr-target8.example1.org" - record_name = "ptr-rec8.example1.org" - comment = "workstation #8" - ttl = 301 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ptr_record.rec7] + dns_view = "default" + ptrdname = "ptr-target8.example1.org" + record_name = "ptr-rec8.example1.org" + comment = "workstation #8" + ttl = 301 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone2, infoblox_ptr_record.rec7] } //////////////////////////////////////////////// -resource "infoblox_ptr_record" "rec9" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target9.example2.org" - ip_addr = "2002:1f93::9" - comment = "workstation #9" - ttl = 300 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) +resource "infoblox_dns_view" "view1" { + name = "nondefault_dnsview1" +} - depends_on = [infoblox_ptr_record.rec8] +resource "infoblox_zone_auth" "zone2" { + fqdn = "example2.org" + view = "nondefault_dnsview1" + depends_on = [infoblox_dns_view.view1] +} + +resource "infoblox_zone_auth" "izone3" { + fqdn = "2002:1f93::/64" + view = "nondefault_dnsview1" + zone_format = "IPV6" + depends_on = [infoblox_dns_view.view1] +} +resource "infoblox_ptr_record" "rec9" { + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target9.example2.org" + ip_addr = "2002:1f93::9" + comment = "workstation #9" + ttl = 300 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone2, infoblox_zone_auth.izone3, infoblox_ptr_record.rec8] } resource "infoblox_ptr_record" "rec10" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target10.example2.org" - record_name = "a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa" - comment = "workstation #10" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ptr_record.rec9] + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target10.example2.org" + record_name = "a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.9.f.1.2.0.0.2.ip6.arpa" + comment = "workstation #10" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone2, infoblox_zone_auth.izone3, infoblox_ptr_record.rec9] } resource "infoblox_ptr_record" "rec11" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target11.example2.org" - record_name = "ptr-rec11.example2.org" - comment = "workstation #11" - ttl = 301 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target11.example2.org" + record_name = "ptr-rec11.example2.org" + comment = "workstation #11" + ttl = 301 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net1, infoblox_zone_auth.zone2, infoblox_zone_auth.izone3, infoblox_ptr_record.rec10] +} - depends_on = [infoblox_ptr_record.rec10] +resource "infoblox_zone_auth" "izone4" { + fqdn = "10.0.0.0/8" + view = "nondefault_dnsview1" + zone_format = "IPV4" + depends_on = [infoblox_dns_view.view1] } resource "infoblox_ptr_record" "rec12" { - dns_view = "nondefault_dnsview1" - network_view = "default" - ptrdname = "ptr-target12.example2.org" - cidr = "10.0.0.0/8" - comment = "workstation #12" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) + dns_view = "nondefault_dnsview1" + network_view = "default" + ptrdname = "ptr-target12.example2.org" + cidr = "10.0.0.0/8" + comment = "workstation #12" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone2, infoblox_zone_auth.izone4, infoblox_ptr_record.rec11] +} + +resource "infoblox_dns_view" "view2" { + name = "nondefault_dnsview2" +} - depends_on = [infoblox_ipv4_network.net1, infoblox_ptr_record.rec11] +resource "infoblox_zone_auth" "zone3" { + fqdn = "example4.org" + view = "nondefault_dnsview2" + depends_on = [infoblox_dns_view.view2] +} + +resource "infoblox_zone_auth" "izone5" { + fqdn = "2002:1f93::/64" + view = "nondefault_dnsview2" + zone_format = "IPV6" + depends_on = [infoblox_dns_view.view2] } resource "infoblox_ptr_record" "rec13" { - dns_view = "nondefault_dnsview2" - network_view = "nondefault_netview" - ptrdname = "ptr-target13.example4.org" - cidr = "2002:1f93::/64" - comment = "workstation #13" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) + dns_view = "nondefault_dnsview2" + network_view = "nondefault_netview" + ptrdname = "ptr-target13.example4.org" + cidr = "2002:1f93::/64" + comment = "workstation #13" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) - depends_on = [infoblox_ipv6_network.net3, infoblox_ptr_record.rec12] + depends_on = [infoblox_ipv6_network.net3, infoblox_zone_auth.zone3, infoblox_zone_auth.izone5, infoblox_ptr_record.rec12] } -//////////////////////////////////////////////// +////////////////////////////////////////////// resource "infoblox_ptr_record" "rec14" { - ptrdname = "ptr-target14.example1.org" - ip_addr = "10.0.0.14" + ptrdname = "ptr-target14.example1.org" + ip_addr = "10.0.0.14" - depends_on = [infoblox_ptr_record.rec13] + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1, infoblox_ptr_record.rec13] } ` diff --git a/infoblox/resource_infoblox_ptr_record_test_data_01.go b/infoblox/resource_infoblox_ptr_record_test_data_01.go index 1fee3c0b2..2e5765de8 100644 --- a/infoblox/resource_infoblox_ptr_record_test_data_01.go +++ b/infoblox/resource_infoblox_ptr_record_test_data_01.go @@ -2,186 +2,255 @@ package infoblox const testCasePtrRecordTestData01 = ` resource "infoblox_ipv4_network" "net1" { - cidr = "10.0.0.0/8" - reserve_ip = 200 + cidr = "10.0.0.0/8" + reserve_ip = 200 } resource "infoblox_ipv4_network" "net2" { - cidr = "172.16.0.0/16" - reserve_ip = 200 + cidr = "172.16.0.0/16" + reserve_ip = 200 } resource "infoblox_ipv6_network" "net1" { - cidr = "2002:1f93::/64" - reserve_ipv6 = 200 + cidr = "2002:1f93::/64" + reserve_ipv6 = 200 } resource "infoblox_ipv6_network" "net2" { - cidr = "2002:1f94::/64" - reserve_ipv6 = 200 + cidr = "2002:1f94::/64" + reserve_ipv6 = 200 +} + +resource "infoblox_network_view" "netview1" { + name = "nondefault_netview" } resource "infoblox_ipv6_network" "net3" { - network_view = "nondefault_netview" - cidr = "2002:1f93::/64" - reserve_ipv6 = 200 + network_view = "nondefault_netview" + cidr = "2002:1f93::/64" + reserve_ipv6 = 200 + depends_on = [infoblox_network_view.netview1] } resource "infoblox_ipv6_network" "net4" { - network_view = "nondefault_netview" - cidr = "2002:1f94::/64" - reserve_ipv6 = 200 + network_view = "nondefault_netview" + cidr = "2002:1f94::/64" + reserve_ipv6 = 200 + depends_on = [infoblox_network_view.netview1] +} + +resource "infoblox_zone_auth" "zone1" { + fqdn = "example1.org" +} + +resource "infoblox_zone_auth" "izone1" { + fqdn = "10.0.0.0/8" + zone_format = "IPV4" } resource "infoblox_ptr_record" "rec1" { - ptrdname = "ptr-target1.example1.org" - ip_addr = "10.0.0.1" - comment = "non-empty comment" - ttl = 5 - ext_attrs = jsonencode({ - Location = "Test location" - }) + ptrdname = "ptr-target1.example1.org" + ip_addr = "10.0.0.1" + comment = "non-empty comment" + ttl = 5 + ext_attrs = jsonencode({ + Location = "Test location" + }) + depends_on = [infoblox_ipv4_network.net1, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1] } resource "infoblox_ptr_record" "rec2" { - ptrdname = "ptr-target2.example1.org" - record_name = "32.0.0.10.in-addr.arpa" - - depends_on = [infoblox_ptr_record.rec1] + ptrdname = "ptr-target2.example1.org" + record_name = "32.0.0.10.in-addr.arpa" + + depends_on = [infoblox_ptr_record.rec1, infoblox_ipv4_network.net1, infoblox_zone_auth.izone1, infoblox_zone_auth.zone1] } resource "infoblox_ptr_record" "rec3" { - ptrdname = "ptr-target3.example1.org" - record_name = "ptr-rec3-2.example1.org" + ptrdname = "ptr-target3.example1.org" + record_name = "ptr-rec3-2.example1.org" + + depends_on = [infoblox_ptr_record.rec2, infoblox_zone_auth.zone1, infoblox_zone_auth.izone1] +} - depends_on = [infoblox_ptr_record.rec2] +resource "infoblox_zone_auth" "izone2" { + fqdn = "172.16.0.0/16" + zone_format = "IPV4" } resource "infoblox_ptr_record" "rec4" { - ptrdname = "ptr-target4.example1.org" - cidr = "172.16.0.0/16" - - depends_on = [infoblox_ipv4_network.net2, infoblox_ptr_record.rec3] + ptrdname = "ptr-target4.example1.org" + cidr = "172.16.0.0/16" + + depends_on = [infoblox_ipv4_network.net2, infoblox_ptr_record.rec3, infoblox_zone_auth.izone2] } -resource "infoblox_ptr_record" "rec5" { - dns_view = "default" - ptrdname = "ptr-target5.example1.org" - cidr = "2002:1f93::0/64" - comment = "workstation #5-2" - ttl = 302 - ext_attrs = jsonencode({ - "Location" = "the new office" - }) +resource "infoblox_zone_auth" "izone3" { + fqdn = "2002:1f93::/64" + zone_format = "IPV6" + depends_on = [infoblox_ipv6_network.net1] +} - depends_on = [infoblox_ptr_record.rec4] +resource "infoblox_ptr_record" "rec5" { + dns_view = "default" + ptrdname = "ptr-target5.example1.org" + cidr = "2002:1f93::0/64" + comment = "workstation #5-2" + ttl = 302 + ext_attrs = jsonencode({ + "Location" = "the new office" + }) + + depends_on = [infoblox_ptr_record.rec4, infoblox_ipv6_network.net1, infoblox_zone_auth.izone3, infoblox_zone_auth.zone1] } resource "infoblox_ptr_record" "rec6" { - ptrdname = "ptr-target6.example1.org" - cidr = "2002:1f93::/64" - - depends_on = [infoblox_ptr_record.rec5] + ptrdname = "ptr-target6.example1.org" + cidr = "2002:1f93::/64" + + depends_on = [infoblox_ptr_record.rec5, infoblox_ipv6_network.net1, infoblox_zone_auth.izone3, infoblox_zone_auth.zone1] } resource "infoblox_ptr_record" "rec7" { - ptrdname = "ptr-target7.example1.org" - cidr = "2002:1f93::/64" - - depends_on = [infoblox_ipv6_network.net1, infoblox_ptr_record.rec6] + ptrdname = "ptr-target7.example1.org" + cidr = "2002:1f93::/64" + + depends_on = [infoblox_ipv6_network.net1, infoblox_ptr_record.rec6, infoblox_zone_auth.izone3, infoblox_zone_auth.zone1] } resource "infoblox_ptr_record" "rec8" { - dns_view = "default" - ptrdname = "ptr-target8.example1.org" - record_name = "ptr-rec8.example1.org" - comment = "workstation #8" - ttl = 301 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - - depends_on = [infoblox_ptr_record.rec7] + dns_view = "default" + ptrdname = "ptr-target8.example1.org" + record_name = "ptr-rec8.example1.org" + comment = "workstation #8" + ttl = 301 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ptr_record.rec7, infoblox_ipv6_network.net1, infoblox_zone_auth.izone3, infoblox_zone_auth.zone1] } //////////////////////////////////////////////// -resource "infoblox_ptr_record" "rec9" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target9.example2.org" - cidr = "2002:1f93::/64" - comment = "workstation #9" - ttl = 300 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) +resource "infoblox_dns_view" "view1" { + name = "nondefault_dnsview1" + network_view = "nondefault_netview" + depends_on = [infoblox_network_view.netview1] +} - depends_on = [infoblox_ptr_record.rec8] +resource "infoblox_zone_auth" "zone2" { + fqdn = "example2.org" + view = "nondefault_dnsview1" + depends_on = [infoblox_dns_view.view1] } -resource "infoblox_ptr_record" "rec10" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target10.example2.org" - ip_addr = "2002:1f93::b" - comment = "workstation #10" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) +resource "infoblox_zone_auth" "izone4" { + fqdn = "2002:1f93::/64" + zone_format = "IPV6" + view = "nondefault_dnsview1" + depends_on = [infoblox_ipv6_network.net3] +} - depends_on = [infoblox_ptr_record.rec9] +resource "infoblox_ptr_record" "rec9" { + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target9.example2.org" + cidr = "2002:1f93::/64" + comment = "workstation #9" + ttl = 300 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + depends_on = [infoblox_ptr_record.rec8, infoblox_ipv6_network.net1, infoblox_zone_auth.izone4, infoblox_zone_auth.zone2] +} + +resource "infoblox_ptr_record" "rec10" { + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target10.example2.org" + ip_addr = "2002:1f93::b" + comment = "workstation #10" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ptr_record.rec9, infoblox_ipv6_network.net3, infoblox_zone_auth.izone4, infoblox_zone_auth.zone2] } resource "infoblox_ptr_record" "rec11" { - dns_view = "nondefault_dnsview1" - ptrdname = "ptr-target11.example2.org" - record_name = "ptr-rec11.example2.org" - comment = "workstation #11" - ttl = 301 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) + dns_view = "nondefault_dnsview1" + ptrdname = "ptr-target11.example2.org" + record_name = "ptr-rec11.example2.org" + comment = "workstation #11" + ttl = 301 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ptr_record.rec10, infoblox_zone_auth.izone4, infoblox_zone_auth.zone2] +} - depends_on = [infoblox_ptr_record.rec10] +resource "infoblox_zone_auth" "izone5" { + fqdn = "10.0.0.0/8" + zone_format = "IPV4" + view = "nondefault_dnsview1" + depends_on = [infoblox_ipv4_network.net1] } resource "infoblox_ptr_record" "rec12" { - dns_view = "nondefault_dnsview1" - network_view = "default" - ptrdname = "ptr-target12.example2.org" - record_name = "32.0.0.10.in-addr.arpa" - comment = "workstation #12" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) + dns_view = "nondefault_dnsview1" + network_view = "default" + ptrdname = "ptr-target12.example2.org" + record_name = "32.0.0.10.in-addr.arpa" + comment = "workstation #12" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv4_network.net1, infoblox_ptr_record.rec11, infoblox_zone_auth.izone5, infoblox_zone_auth.zone2] +} - depends_on = [infoblox_ipv4_network.net1, infoblox_ptr_record.rec11] +resource "infoblox_dns_view" "view2" { + name = "nondefault_dnsview2" } -resource "infoblox_ptr_record" "rec13" { - dns_view = "nondefault_dnsview2" - network_view = "nondefault_netview" - ptrdname = "ptr-target13.example4.org" +resource "infoblox_zone_auth" "zone3" { + fqdn = "example4.org" + view = "nondefault_dnsview2" + depends_on = [infoblox_dns_view.view2] +} - // must be within the same network - ip_addr = "2002:1f93::13" +resource "infoblox_zone_auth" "izone6" { + fqdn = "2002:1f93::/64" + zone_format = "IPV6" + view = "nondefault_dnsview2" + depends_on = [infoblox_dns_view.view2] +} - comment = "workstation #13" - ttl = 30 - ext_attrs = jsonencode({ - "Location" = "the main office" - }) - depends_on = [infoblox_ipv6_network.net3, infoblox_ptr_record.rec12] +resource "infoblox_ptr_record" "rec13" { + dns_view = "nondefault_dnsview2" + network_view = "nondefault_netview" + ptrdname = "ptr-target13.example4.org" + + // must be within the same network + ip_addr = "2002:1f93::13" + comment = "workstation #13" + ttl = 30 + ext_attrs = jsonencode({ + "Location" = "the main office" + }) + + depends_on = [infoblox_ipv6_network.net3, infoblox_ptr_record.rec12, infoblox_zone_auth.zone3, infoblox_zone_auth.izone6] } //////////////////////////////////////////////// resource "infoblox_ptr_record" "rec14" { - ptrdname = "ptr-target14.example1.org" - record_name = "44.0.0.10.in-addr.arpa" - - depends_on = [infoblox_ptr_record.rec13] + ptrdname = "ptr-target14.example1.org" + record_name = "44.0.0.10.in-addr.arpa" + + depends_on = [infoblox_ptr_record.rec13, infoblox_ipv4_network.net1, infoblox_zone_auth.izone1, infoblox_zone_auth.zone1] } ` diff --git a/infoblox/resource_infoblox_ptr_record_test_err_data_00.go b/infoblox/resource_infoblox_ptr_record_test_err_data_00.go index 30399655a..56a74af74 100644 --- a/infoblox/resource_infoblox_ptr_record_test_err_data_00.go +++ b/infoblox/resource_infoblox_ptr_record_test_err_data_00.go @@ -34,9 +34,19 @@ resource "infoblox_ptr_record" "err_ptr_rec1" { ` const testCasePtrRecordTestErrData05Pre = ` +resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" +} + +resource "infoblox_zone_auth" "izone" { + fqdn = "10.0.0.0/8" + zone_format = "IPV4" +} + resource "infoblox_ptr_record" "err_ptr_rec1" { ptrdname = "test.com" ip_addr = "10.0.0.1" + depends_on = [infoblox_zone_auth.zone, infoblox_zone_auth.izone] } ` @@ -45,6 +55,7 @@ resource "infoblox_ptr_record" "err_ptr_rec1" { ptrdname = "test.com" ip_addr = "10.0.0.2" record_name = "2.0.0.10.in-addr.arpa" + //depends_on = [infoblox_zone_auth.zone1, infoblox_zone_auth.izone1] } ` diff --git a/infoblox/resource_infoblox_srv_record_test.go b/infoblox/resource_infoblox_srv_record_test.go index c9c4fb7db..0d1caac70 100644 --- a/infoblox/resource_infoblox_srv_record_test.go +++ b/infoblox/resource_infoblox_srv_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "regexp" @@ -33,17 +34,39 @@ func testAccSRVRecordCompare(t *testing.T, resPath string, expectedRec *ibclient if !found { return fmt.Errorf("not found: %s", resPath) } + if res.Primary.ID == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetSRVRecordByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + recSRV, err := objMgr.SearchObjectByAltId("SRV", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } } + // Assertion of object type and error handling + var rec *ibclient.RecordSRV + recJson, _ := json.Marshal(recSRV) + err = json.Unmarshal(recJson, &rec) if rec.Name == nil { return fmt.Errorf("'name' is expected to be defined but it is not") @@ -139,12 +162,16 @@ func TestAccResourceSRVRecord(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo"{ name = "_sip._tcp.host1.test.com" priority = 50 weight = 30 port = 80 target = "sample.target1.com" + depends_on = [infoblox_zone_auth.zone] }`), Check: resource.ComposeTestCheckFunc( testAccSRVRecordCompare(t, "infoblox_srv_record.foo", &ibclient.RecordSRV{ @@ -160,6 +187,13 @@ func TestAccResourceSRVRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo1" { dns_view = "nondefault_view" name = "_sip._udp.host2.test.com" @@ -173,6 +207,7 @@ func TestAccResourceSRVRecord(t *testing.T) { "Location" = "France" "Site" = "DHQ" }) + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccSRVRecordCompare(t, "infoblox_srv_record.foo1", &ibclient.RecordSRV{ @@ -194,6 +229,13 @@ func TestAccResourceSRVRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_http._tcp.demo.host3.test.com" @@ -206,6 +248,7 @@ func TestAccResourceSRVRecord(t *testing.T) { ext_attrs = jsonencode({ "Site" = "DHQ" }) + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccSRVRecordCompare(t, "infoblox_srv_record.foo2", &ibclient.RecordSRV{ @@ -226,6 +269,13 @@ func TestAccResourceSRVRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_http._tcp.demo.host4.test.com" @@ -238,6 +288,7 @@ func TestAccResourceSRVRecord(t *testing.T) { ext_attrs = jsonencode({ "Site" = "None" }) + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccSRVRecordCompare(t, "infoblox_srv_record.foo2", &ibclient.RecordSRV{ @@ -258,6 +309,13 @@ func TestAccResourceSRVRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -265,6 +323,7 @@ func TestAccResourceSRVRecord(t *testing.T) { weight = 51 port = 89 target = "sample.target4.com" + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccSRVRecordCompare(t, "infoblox_srv_record.foo2", &ibclient.RecordSRV{ @@ -282,6 +341,13 @@ func TestAccResourceSRVRecord(t *testing.T) { // negative test cases { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -290,11 +356,19 @@ func TestAccResourceSRVRecord(t *testing.T) { port = 89 target = "sample.target4.com" ttl = -1 + depends_on = [infoblox_zone_auth.zone1] }`), ExpectError: regexp.MustCompile("TTL value must be 0 or higher"), }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -302,11 +376,19 @@ func TestAccResourceSRVRecord(t *testing.T) { weight = 51 port = 89000 target = "sample.target4.com" + depends_on = [infoblox_zone_auth.zone1] }`), ExpectError: regexp.MustCompile("'port' must be integer and must be in the range from 0 to 65535 inclusively"), }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -314,11 +396,19 @@ func TestAccResourceSRVRecord(t *testing.T) { weight = 51 port = 89 target = "sample.target4.com" + depends_on = [infoblox_zone_auth.zone1] }`), ExpectError: regexp.MustCompile("'priority' must be integer and must be in the range from 0 to 65535 inclusively"), }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -326,11 +416,19 @@ func TestAccResourceSRVRecord(t *testing.T) { weight = 510000 port = 89 target = "sample.target4.com" + depends_on = [infoblox_zone_auth.zone1] }`), ExpectError: regexp.MustCompile("'weight' must be integer and must be in the range from 0 to 65535 inclusively"), }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view2" + } + resource "infoblox_zone_auth" "zone2" { + fqdn = "test.com" + view = infoblox_dns_view.view1.name + } resource "infoblox_srv_record" "foo2"{ dns_view = "nondefault_view2" name = "_customservice._newcoolproto.demo.host4.test.com" @@ -338,6 +436,7 @@ func TestAccResourceSRVRecord(t *testing.T) { weight = 51 port = 89 target = "sample.target4.com" + depends_on = [infoblox_zone_auth.zone2] }`), ExpectError: regexp.MustCompile("changing the value of 'dns_view' field is not allowed"), }, @@ -353,6 +452,9 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo3" { dns_view = "default" name = "_sip._udp.test.com" @@ -364,6 +466,7 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Newyork" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccSRVRecordCompare(t, "infoblox_srv_record.foo3", &ibclient.RecordSRV{ View: "default", @@ -411,6 +514,9 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo3" { dns_view = "default" name = "_sip._udp.test.com" @@ -422,6 +528,7 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Newyork" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -449,6 +556,9 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo3" { dns_view = "default" name = "_sip._udp.test.com" @@ -460,6 +570,7 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Newyork" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccSRVRecordCompare(t, "infoblox_srv_record.foo3", &ibclient.RecordSRV{ View: "default", @@ -479,6 +590,9 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo3" { dns_view = "default" name = "_sip._udp.test.com" @@ -491,6 +605,7 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { "Location" = "Newyork" "Site" = "random new site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccSRVRecordCompare(t, "infoblox_srv_record.foo3", &ibclient.RecordSRV{ View: "default", @@ -510,6 +625,9 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_srv_record" "foo3" { dns_view = "default" name = "_sip._udp.test.com" @@ -521,6 +639,7 @@ func TestAcc_resourceSRVRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Newyork" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_txt_record_test.go b/infoblox/resource_infoblox_txt_record_test.go index a597dfe66..d8eb90d1c 100644 --- a/infoblox/resource_infoblox_txt_record_test.go +++ b/infoblox/resource_infoblox_txt_record_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/infobloxopen/infoblox-go-client/v2/utils" "regexp" @@ -38,14 +39,35 @@ func testAccTXTRecordCompare(t *testing.T, resPath string, expectedRec *ibclient if res.Primary.ID == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - rec, _ := objMgr.GetTXTRecordByRef(res.Primary.ID) - if rec == nil { - return fmt.Errorf("record not found") + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") + } + + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + recTXT, err := objMgr.SearchObjectByAltId("TXT", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedRec == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } } + // Assertion of object type and error handling + var rec *ibclient.RecordTXT + recJson, _ := json.Marshal(recTXT) + err = json.Unmarshal(recJson, &rec) if rec.Name == nil { return fmt.Errorf("'fqdn' is expected to be defined but it is not") @@ -118,9 +140,13 @@ func TestAccResourceTXTRecord(t *testing.T) { Steps: []resource.TestStep{ { Config: fmt.Sprintf(` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo"{ fqdn = "name1.test.com" text = "this is a sample text" + depends_on = [infoblox_zone_auth.zone] }`), Check: resource.ComposeTestCheckFunc( testAccTXTRecordCompare(t, "infoblox_txt_record.foo", &ibclient.RecordTXT{ @@ -133,6 +159,13 @@ func TestAccResourceTXTRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_txt_record" "foo2"{ fqdn = "name2.test.com" text = "this is a sample text-2" @@ -143,6 +176,7 @@ func TestAccResourceTXTRecord(t *testing.T) { "Location" = "California" "Site" = "HQ" }) + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccTXTRecordCompare(t, "infoblox_txt_record.foo2", &ibclient.RecordTXT{ @@ -161,12 +195,20 @@ func TestAccResourceTXTRecord(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } + resource "infoblox_zone_auth" "zone1" { + fqdn = "test.com" + view = infoblox_dns_view.view.name + } resource "infoblox_txt_record" "foo2" { fqdn = "name3.test.com" text = "this is a text record" ttl = 150 dns_view = "nondefault_view" comment = "test comment 2" + depends_on = [infoblox_zone_auth.zone1] }`), Check: resource.ComposeTestCheckFunc( testAccTXTRecordCompare(t, "infoblox_txt_record.foo2", &ibclient.RecordTXT{ @@ -183,6 +225,13 @@ func TestAccResourceTXTRecord(t *testing.T) { // negative test cases { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view1" { + name = "nondefault_view2" + } + resource "infoblox_zone_auth" "zone2" { + fqdn = "test.com" + view = infoblox_dns_view.view1.name + } resource "infoblox_txt_record" "foo2" { fqdn = "name3.test.com" text = "this is a text record" @@ -204,6 +253,9 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { Steps: []resource.TestStep{ { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo3"{ dns_view = "default" fqdn = "newtext.test.com" @@ -212,6 +264,7 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Some location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccTXTRecordCompare(t, "infoblox_txt_record.foo3", &ibclient.RecordTXT{ Text: utils.StringPtr("this is sample text record"), @@ -254,6 +307,9 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { } }, Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo3"{ dns_view = "default" fqdn = "newtext.test.com" @@ -262,6 +318,7 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Some location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( // Resource object shouldn't have Site EA, since it's omitted by provider @@ -286,6 +343,9 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA won't be removed if some field is updated in the resource { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo3"{ dns_view = "default" fqdn = "newtext.test.com" @@ -294,6 +354,7 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Some location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccTXTRecordCompare(t, "infoblox_txt_record.foo3", &ibclient.RecordTXT{ Text: utils.StringPtr("this is sample text record"), @@ -310,6 +371,9 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo3"{ dns_view = "default" fqdn = "newtext.test.com" @@ -319,6 +383,7 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { "Location" = "Some location" "Site" = "Sample text site" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: testAccTXTRecordCompare(t, "infoblox_txt_record.foo3", &ibclient.RecordTXT{ Text: utils.StringPtr("this is sample text record"), @@ -335,6 +400,9 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { // Validate that inherited EA can be removed, if updated { Config: ` + resource "infoblox_zone_auth" "zone" { + fqdn = "test.com" + } resource "infoblox_txt_record" "foo3"{ dns_view = "default" fqdn = "newtext.test.com" @@ -343,6 +411,7 @@ func TestAcc_resourceTXTRecord_ea_inheritance(t *testing.T) { ext_attrs = jsonencode({ "Location" = "Some location" }) + depends_on = [infoblox_zone_auth.zone] }`, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/infoblox/resource_infoblox_zone_auth_test.go b/infoblox/resource_infoblox_zone_auth_test.go index f071fb31f..9490957eb 100644 --- a/infoblox/resource_infoblox_zone_auth_test.go +++ b/infoblox/resource_infoblox_zone_auth_test.go @@ -1,6 +1,7 @@ package infoblox import ( + "encoding/json" "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -36,15 +37,36 @@ func testAccZoneAuthCompare(t *testing.T, resPath string, expectedObj *ibclient. if res.Primary.ID == "" { return fmt.Errorf("ID is not set") } - meta := testAccProvider.Meta() - connector := meta.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "terraform_test", "test") - zoneObj, _ := objMgr.GetZoneAuthByRef(res.Primary.ID) - if zoneObj == nil { - return fmt.Errorf("zone not found") + internalId := res.Primary.Attributes["internal_id"] + if internalId == "" { + return fmt.Errorf("ID is not set") } + ref, found := res.Primary.Attributes["ref"] + if !found { + return fmt.Errorf("'ref' attribute is not set") + } + + connector := testAccProvider.Meta().(ibclient.IBConnector) + objMgr := ibclient.NewObjectManager( + connector, + "terraform_test", + "test") + zone, err := objMgr.SearchObjectByAltId("ZoneAuth", ref, internalId, eaNameForInternalId) + if err != nil { + if isNotFoundError(err) { + if expectedObj == nil { + return nil + } + return fmt.Errorf("object with Terraform ID '%s' not found, but expected to exist", internalId) + } + } + // Assertion of object type and error handling + var zoneObj *ibclient.ZoneAuth + recJson, _ := json.Marshal(zone) + err = json.Unmarshal(recJson, &zoneObj) + if zoneObj.Fqdn != expectedObj.Fqdn { return fmt.Errorf( "'fqdn' does not match: got '%s', expected '%s'", zoneObj.Fqdn, @@ -60,14 +82,6 @@ func testAccZoneAuthCompare(t *testing.T, resPath string, expectedObj *ibclient. *zoneObj.View, *expectedObj.View) } - if zoneObj.NsGroup != nil { - if *zoneObj.NsGroup != *expectedObj.NsGroup { - return fmt.Errorf( - "'ns_group' does not match: got '%s', expected '%s'", - *zoneObj.NsGroup, *expectedObj.NsGroup) - } - } - if expectedObj.ZoneFormat != "" { if zoneObj.ZoneFormat != expectedObj.ZoneFormat { return fmt.Errorf( @@ -147,11 +161,14 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource "infoblox_zone_auth" "test_zone2" { fqdn = "test2.com" } + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } resource "infoblox_zone_auth" "test_zone3" { fqdn = "test3.com" view = "nondefault_view" zone_format = "FORWARD" - ns_group = "nsgroup1" + //ns_group = "nsgroup1" restart_if_needed = true soa_default_ttl = 36000 soa_expire = 72000 @@ -162,16 +179,13 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { ext_attrs = jsonencode({ Location = "AcceptanceTerraform" }) + depends_on = [infoblox_dns_view.view] } `), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "fqdn", "test2.com"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "view", "default"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "zone_format", "FORWARD"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ext_attrs", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ns_group", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_negative_ttl", "900"), @@ -183,8 +197,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "zone_format", "FORWARD"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "comment", "Zone Auth created by terraform acceptance test"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ext_attrs", "{\"Location\":\"AcceptanceTerraform\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ns_group", "nsgroup1"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "restart_if_needed", "true"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_default_ttl", "36000"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_expire", "72000"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_negative_ttl", "600"), @@ -196,7 +208,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { Config: fmt.Sprintf(` resource "infoblox_zone_auth" "test_zone2" { fqdn = "test2.com" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" restart_if_needed = true soa_default_ttl = 36002 soa_expire = 72002 @@ -208,11 +220,14 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { Location = "AcceptanceTerraform 22" }) } + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } resource "infoblox_zone_auth" "test_zone3" { fqdn = "test3.com" view = "nondefault_view" zone_format = "FORWARD" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" restart_if_needed = false soa_default_ttl = 36001 soa_expire = 72001 @@ -223,6 +238,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { ext_attrs = jsonencode({ Location = "AcceptanceTerraform 2" }) + depends_on = [infoblox_dns_view.view] } `), Check: resource.ComposeTestCheckFunc( @@ -231,7 +247,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "zone_format", "FORWARD"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "comment", "Zone Auth created by terraform acceptance test 22"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ext_attrs", "{\"Location\":\"AcceptanceTerraform 22\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ns_group", "nsgroup2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "restart_if_needed", "true"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_default_ttl", "36002"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_expire", "72002"), @@ -244,7 +259,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "zone_format", "FORWARD"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "comment", "Zone Auth created by terraform acceptance test 2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ext_attrs", "{\"Location\":\"AcceptanceTerraform 2\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ns_group", "nsgroup2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_default_ttl", "36001"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_expire", "72001"), @@ -255,24 +269,24 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { }, { Config: fmt.Sprintf(` + resource "infoblox_dns_view" "view" { + name = "nondefault_view" + } resource "infoblox_zone_auth" "test_zone2" { fqdn = "test2.com" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" } resource "infoblox_zone_auth" "test_zone3" { fqdn = "test3.com" view = "nondefault_view" zone_format = "FORWARD" + depends_on = [infoblox_dns_view.view] } `), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "fqdn", "test2.com"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "view", "default"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "zone_format", "FORWARD"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ext_attrs", ""), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "ns_group", "nsgroup2"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone2", "soa_negative_ttl", "900"), @@ -282,10 +296,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "fqdn", "test3.com"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "view", "nondefault_view"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "zone_format", "FORWARD"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ext_attrs", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "ns_group", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone3", "soa_negative_ttl", "900"), @@ -302,7 +312,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource "infoblox_zone_auth" "test_zone5" { fqdn = "2345::/64" zone_format = "IPV6" - ns_group = "nsgroup1" + //ns_group = "nsgroup1" restart_if_needed = true soa_default_ttl = 36000 soa_expire = 72000 @@ -319,10 +329,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "fqdn", "10.20.30.0/24"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "view", "default"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "zone_format", "IPV4"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ext_attrs", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ns_group", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_negative_ttl", "900"), @@ -334,7 +340,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "zone_format", "IPV6"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "comment", "Zone Auth created by terraform acceptance test"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ext_attrs", "{\"Location\":\"AcceptanceTerraform\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ns_group", "nsgroup1"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "restart_if_needed", "true"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_default_ttl", "36000"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_expire", "72000"), @@ -348,7 +353,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource "infoblox_zone_auth" "test_zone4" { fqdn = "10.20.30.0/24" zone_format = "IPV4" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" restart_if_needed = true soa_default_ttl = 36002 soa_expire = 72002 @@ -363,7 +368,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource "infoblox_zone_auth" "test_zone5" { fqdn = "2345::/64" zone_format = "IPV6" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" restart_if_needed = false soa_default_ttl = 36001 soa_expire = 72001 @@ -382,7 +387,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "zone_format", "IPV4"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "comment", "Zone Auth created by terraform acceptance test 22"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ext_attrs", "{\"Location\":\"AcceptanceTerraform 22\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ns_group", "nsgroup2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "restart_if_needed", "true"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_default_ttl", "36002"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_expire", "72002"), @@ -395,7 +399,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "zone_format", "IPV6"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "comment", "Zone Auth created by terraform acceptance test 2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ext_attrs", "{\"Location\":\"AcceptanceTerraform 2\"}"), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ns_group", "nsgroup2"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_default_ttl", "36001"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_expire", "72001"), @@ -409,7 +412,7 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource "infoblox_zone_auth" "test_zone4" { fqdn = "10.20.30.0/24" zone_format = "IPV4" - ns_group = "nsgroup2" + //ns_group = "nsgroup2" } resource "infoblox_zone_auth" "test_zone5" { fqdn = "2345::/64" @@ -420,10 +423,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "fqdn", "10.20.30.0/24"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "view", "default"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "zone_format", "IPV4"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ext_attrs", ""), - resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "ns_group", "nsgroup2"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone4", "soa_negative_ttl", "900"), @@ -433,10 +432,6 @@ func TestAccResourceZoneAuthBasic(t *testing.T) { resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "fqdn", "2345::/64"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "view", "default"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "zone_format", "IPV6"), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "comment", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ext_attrs", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "ns_group", ""), - //resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "restart_if_needed", "false"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_default_ttl", "28800"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_expire", "2419200"), resource.TestCheckResourceAttr("infoblox_zone_auth.test_zone5", "soa_negative_ttl", "900"), diff --git a/scripts/unit-test-prerequisites.sh b/scripts/unit-test-prerequisites.sh new file mode 100644 index 000000000..edef74a39 --- /dev/null +++ b/scripts/unit-test-prerequisites.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +NIOS_SERVER="${NIOS_SERVER:-192.168.1.2:443}" +NIOS_USER="${NIOS_USER:-admin}" +NIOS_PASSWORD="${NIOS_PASSWORD:-infoblox}" + +WAPI_URL="https://${NIOS_SERVER}/wapi/v2.11.1" +CURL_AUTH="-u ${NIOS_USER}:${NIOS_PASSWORD}" + + +curl -k -X POST -H 'Content-Type: application/json' $CURL_AUTH "${WAPI_URL}/extensibleattributedef" -d '{"name":"Location","type":"STRING"}' +echo + +curl -k -X POST -H 'Content-Type: application/json' $CURL_AUTH "${WAPI_URL}/extensibleattributedef" -d '{"name":"Tenant ID","type":"STRING"}' +echo + +curl -k -X POST -H 'Content-Type: application/json' $CURL_AUTH "${WAPI_URL}/extensibleattributedef" -d '{"name":"VM Name","type":"STRING"}' +echo + +curl -k -X POST -H 'Content-Type: application/json' $CURL_AUTH "${WAPI_URL}/extensibleattributedef" -d '{"name":"Network Name","type":"STRING"}' +echo + + + +