2016-02-07 22:49:02 +01:00
|
|
|
package azurerm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"github.com/jen20/riviera/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAzureRMDnsSrvRecord_basic(t *testing.T) {
|
|
|
|
ri := acctest.RandInt()
|
|
|
|
config := fmt.Sprintf(testAccAzureRMDnsSrvRecord_basic, ri, ri, ri)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMDnsSrvRecordDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: config,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMDnsSrvRecordExists("azurerm_dns_srv_record.test"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureRMDnsSrvRecord_updateRecords(t *testing.T) {
|
|
|
|
ri := acctest.RandInt()
|
|
|
|
preConfig := fmt.Sprintf(testAccAzureRMDnsSrvRecord_basic, ri, ri, ri)
|
|
|
|
postConfig := fmt.Sprintf(testAccAzureRMDnsSrvRecord_updateRecords, ri, ri, ri)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMDnsSrvRecordDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: preConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMDnsSrvRecordExists("azurerm_dns_srv_record.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_dns_srv_record.test", "record.#", "2"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: postConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMDnsSrvRecordExists("azurerm_dns_srv_record.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_dns_srv_record.test", "record.#", "3"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureRMDnsSrvRecord_withTags(t *testing.T) {
|
|
|
|
ri := acctest.RandInt()
|
|
|
|
preConfig := fmt.Sprintf(testAccAzureRMDnsSrvRecord_withTags, ri, ri, ri)
|
|
|
|
postConfig := fmt.Sprintf(testAccAzureRMDnsSrvRecord_withTagsUpdate, ri, ri, ri)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMDnsSrvRecordDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: preConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMDnsSrvRecordExists("azurerm_dns_srv_record.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-06-10 17:07:02 +02:00
|
|
|
"azurerm_dns_srv_record.test", "tags.%", "2"),
|
2016-02-07 22:49:02 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: postConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMDnsSrvRecordExists("azurerm_dns_srv_record.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-06-10 17:07:02 +02:00
|
|
|
"azurerm_dns_srv_record.test", "tags.%", "1"),
|
2016-02-07 22:49:02 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCheckAzureRMDnsSrvRecordExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Ensure we have enough information in state to look up in API
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
|
|
|
|
|
|
|
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
|
|
|
readRequest.Command = &dns.GetSRVRecordSet{}
|
|
|
|
|
|
|
|
readResponse, err := readRequest.Execute()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bad: GetSRVRecordSet: %s", err)
|
|
|
|
}
|
|
|
|
if !readResponse.IsSuccessful() {
|
|
|
|
return fmt.Errorf("Bad: GetSRVRecordSet: %s", readResponse.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCheckAzureRMDnsSrvRecordDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "azurerm_dns_srv_record" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
|
|
|
readRequest.Command = &dns.GetSRVRecordSet{}
|
|
|
|
|
|
|
|
readResponse, err := readRequest.Execute()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bad: GetSRVRecordSet: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if readResponse.IsSuccessful() {
|
|
|
|
return fmt.Errorf("Bad: DNS SRV Record still exists: %s", readResponse.Error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAzureRMDnsSrvRecord_basic = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctest_rg_%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
resource "azurerm_dns_zone" "test" {
|
|
|
|
name = "acctestzone%d.com"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_dns_srv_record" "test" {
|
|
|
|
name = "myarecord%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
zone_name = "${azurerm_dns_zone.test.name}"
|
|
|
|
ttl = "300"
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 1
|
|
|
|
weight = 5
|
|
|
|
port = 8080
|
|
|
|
target = "target1.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 2
|
|
|
|
weight = 25
|
|
|
|
port = 8080
|
|
|
|
target = "target2.contoso.com"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMDnsSrvRecord_updateRecords = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctest_rg_%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
resource "azurerm_dns_zone" "test" {
|
|
|
|
name = "acctestzone%d.com"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_dns_srv_record" "test" {
|
|
|
|
name = "myarecord%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
zone_name = "${azurerm_dns_zone.test.name}"
|
|
|
|
ttl = "300"
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 1
|
|
|
|
weight = 5
|
|
|
|
port = 8080
|
|
|
|
target = "target1.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 2
|
|
|
|
weight = 25
|
|
|
|
port = 8080
|
|
|
|
target = "target2.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 3
|
|
|
|
weight = 100
|
|
|
|
port = 8080
|
|
|
|
target = "target3.contoso.com"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMDnsSrvRecord_withTags = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctest_rg_%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
resource "azurerm_dns_zone" "test" {
|
|
|
|
name = "acctestzone%d.com"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_dns_srv_record" "test" {
|
|
|
|
name = "myarecord%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
zone_name = "${azurerm_dns_zone.test.name}"
|
|
|
|
ttl = "300"
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 1
|
|
|
|
weight = 5
|
|
|
|
port = 8080
|
|
|
|
target = "target1.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 2
|
|
|
|
weight = 25
|
|
|
|
port = 8080
|
|
|
|
target = "target2.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "Production"
|
|
|
|
cost_center = "MSFT"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMDnsSrvRecord_withTagsUpdate = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctest_rg_%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
resource "azurerm_dns_zone" "test" {
|
|
|
|
name = "acctestzone%d.com"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_dns_srv_record" "test" {
|
|
|
|
name = "myarecord%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
zone_name = "${azurerm_dns_zone.test.name}"
|
|
|
|
ttl = "300"
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 1
|
|
|
|
weight = 5
|
|
|
|
port = 8080
|
|
|
|
target = "target1.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
record {
|
|
|
|
priority = 2
|
|
|
|
weight = 25
|
|
|
|
port = 8080
|
|
|
|
target = "target2.contoso.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "staging"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|