Merge pull request #5013 from stack72/azurerm-dns-recordsets
provider/azurerm: DNS RecordSets
This commit is contained in:
commit
f57ce437cb
|
@ -526,15 +526,15 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/azure",
|
||||
"Rev": "b5328db47f3ec02cbf39c2c31ac4072bda2ff05b"
|
||||
"Rev": "ad1009032a2ff80c3d6ea094be49a2e98929a42b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/dns",
|
||||
"Rev": "b5328db47f3ec02cbf39c2c31ac4072bda2ff05b"
|
||||
"Rev": "ad1009032a2ff80c3d6ea094be49a2e98929a42b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jen20/riviera/sql",
|
||||
"Rev": "b5328db47f3ec02cbf39c2c31ac4072bda2ff05b"
|
||||
"Rev": "ad1009032a2ff80c3d6ea094be49a2e98929a42b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/jmespath/go-jmespath",
|
||||
|
|
|
@ -61,6 +61,9 @@ func Provider() terraform.ResourceProvider {
|
|||
"azurerm_storage_blob": resourceArmStorageBlob(),
|
||||
"azurerm_storage_queue": resourceArmStorageQueue(),
|
||||
"azurerm_dns_zone": resourceArmDnsZone(),
|
||||
"azurerm_dns_a_record": resourceArmDnsARecord(),
|
||||
"azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(),
|
||||
"azurerm_dns_cname_record": resourceArmDnsCNameRecord(),
|
||||
"azurerm_sql_server": resourceArmSqlServer(),
|
||||
"azurerm_sql_database": resourceArmSqlDatabase(),
|
||||
},
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jen20/riviera/dns"
|
||||
)
|
||||
|
||||
func resourceArmDnsARecord() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmDnsARecordCreate,
|
||||
Read: resourceArmDnsARecordRead,
|
||||
Update: resourceArmDnsARecordCreate,
|
||||
Delete: resourceArmDnsARecordDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"resource_group_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"zone_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"records": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"ttl": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmDnsARecordCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
tags := d.Get("tags").(map[string]interface{})
|
||||
expandedTags := expandTags(tags)
|
||||
|
||||
createCommand := &dns.CreateARecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
Location: "global",
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
TTL: d.Get("ttl").(int),
|
||||
Tags: *expandedTags,
|
||||
}
|
||||
|
||||
recordStrings := d.Get("records").(*schema.Set).List()
|
||||
records := make([]dns.ARecord, len(recordStrings))
|
||||
for i, v := range recordStrings {
|
||||
records[i] = dns.ARecord{
|
||||
IPv4Address: v.(string),
|
||||
}
|
||||
}
|
||||
createCommand.ARecords = records
|
||||
|
||||
createRequest := rivieraClient.NewRequest()
|
||||
createRequest.Command = createCommand
|
||||
|
||||
createResponse, err := createRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating DNS A Record: %s", err)
|
||||
}
|
||||
if !createResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error creating DNS A Record: %s", createResponse.Error)
|
||||
}
|
||||
|
||||
readRequest := rivieraClient.NewRequest()
|
||||
readRequest.Command = &dns.GetARecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetARecordSetResponse)
|
||||
d.SetId(resp.ID)
|
||||
|
||||
return resourceArmDnsARecordRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmDnsARecordRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
readRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
readRequest.Command = &dns.GetARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
log.Printf("[INFO] Error reading DNS A Record %q - removing from state", d.Id())
|
||||
d.SetId("")
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetARecordSetResponse)
|
||||
|
||||
d.Set("ttl", resp.TTL)
|
||||
|
||||
if resp.ARecords != nil {
|
||||
records := make([]string, 0, len(resp.ARecords))
|
||||
for _, record := range resp.ARecords {
|
||||
records = append(records, record.IPv4Address)
|
||||
}
|
||||
|
||||
if err := d.Set("records", records); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
flattenAndSetTags(d, &resp.Tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmDnsARecordDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
deleteRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
deleteRequest.Command = &dns.DeleteRecordSet{
|
||||
RecordSetType: "A",
|
||||
}
|
||||
|
||||
deleteResponse, err := deleteRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting DNS A Record: %s", err)
|
||||
}
|
||||
if !deleteResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error deleting DNS A Record: %s", deleteResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
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 TestAccAzureRMDnsARecord_basic(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMDnsARecord_basic, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsARecordExists("azurerm_dns_a_record.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsARecord_updateRecords(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsARecord_basic, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsARecord_updateRecords, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsARecordExists("azurerm_dns_a_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_a_record.test", "records.#", "2"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsARecordExists("azurerm_dns_a_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_a_record.test", "records.#", "3"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsARecord_withTags(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsARecord_withTags, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsARecord_withTagsUpdate, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsARecordExists("azurerm_dns_a_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_a_record.test", "tags.#", "2"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsARecordExists("azurerm_dns_a_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_a_record.test", "tags.#", "1"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsARecordExists(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.GetARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetARecordSet: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: GetARecordSet: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsARecordDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_dns_a_record" {
|
||||
continue
|
||||
}
|
||||
|
||||
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
||||
readRequest.Command = &dns.GetARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetARecordSet: %s", err)
|
||||
}
|
||||
|
||||
if readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: DNS A Record still exists: %s", readResponse.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMDnsARecord_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_a_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["1.2.3.4", "1.2.4.5"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsARecord_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_a_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["1.2.3.4", "1.2.4.5", "1.2.3.7"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsARecord_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_a_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["1.2.3.4", "1.2.4.5"]
|
||||
|
||||
tags {
|
||||
environment = "Production"
|
||||
cost_center = "MSFT"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsARecord_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_a_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["1.2.3.4", "1.2.4.5"]
|
||||
|
||||
tags {
|
||||
environment = "staging"
|
||||
}
|
||||
}
|
||||
`
|
|
@ -0,0 +1,165 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jen20/riviera/dns"
|
||||
)
|
||||
|
||||
func resourceArmDnsAAAARecord() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmDnsAAAARecordCreate,
|
||||
Read: resourceArmDnsAAAARecordRead,
|
||||
Update: resourceArmDnsAAAARecordCreate,
|
||||
Delete: resourceArmDnsAAAARecordDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"resource_group_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"zone_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"records": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"ttl": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmDnsAAAARecordCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
tags := d.Get("tags").(map[string]interface{})
|
||||
expandedTags := expandTags(tags)
|
||||
|
||||
createCommand := &dns.CreateAAAARecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
Location: "global",
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
TTL: d.Get("ttl").(int),
|
||||
Tags: *expandedTags,
|
||||
}
|
||||
|
||||
recordStrings := d.Get("records").(*schema.Set).List()
|
||||
records := make([]dns.AAAARecord, len(recordStrings))
|
||||
for i, v := range recordStrings {
|
||||
records[i] = dns.AAAARecord{
|
||||
IPv6Address: v.(string),
|
||||
}
|
||||
}
|
||||
createCommand.AAAARecords = records
|
||||
|
||||
createRequest := rivieraClient.NewRequest()
|
||||
createRequest.Command = createCommand
|
||||
|
||||
createResponse, err := createRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating DNS AAAA Record: %s", err)
|
||||
}
|
||||
if !createResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error creating DNS AAAA Record: %s", createResponse.Error)
|
||||
}
|
||||
|
||||
readRequest := rivieraClient.NewRequest()
|
||||
readRequest.Command = &dns.GetAAAARecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS AAAA Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error reading DNS AAAA Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetAAAARecordSetResponse)
|
||||
d.SetId(resp.ID)
|
||||
|
||||
return resourceArmDnsAAAARecordRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmDnsAAAARecordRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
readRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
readRequest.Command = &dns.GetAAAARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS AAAA Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
log.Printf("[INFO] Error reading DNS AAAA Record %q - removing from state", d.Id())
|
||||
d.SetId("")
|
||||
return fmt.Errorf("Error reading DNS AAAA Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetAAAARecordSetResponse)
|
||||
|
||||
d.Set("ttl", resp.TTL)
|
||||
|
||||
if resp.AAAARecords != nil {
|
||||
records := make([]string, 0, len(resp.AAAARecords))
|
||||
for _, record := range resp.AAAARecords {
|
||||
records = append(records, record.IPv6Address)
|
||||
}
|
||||
|
||||
if err := d.Set("records", records); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
flattenAndSetTags(d, &resp.Tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmDnsAAAARecordDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
deleteRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
deleteRequest.Command = &dns.DeleteRecordSet{
|
||||
RecordSetType: "AAAA",
|
||||
}
|
||||
|
||||
deleteResponse, err := deleteRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting DNS AAAA Record: %s", err)
|
||||
}
|
||||
if !deleteResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error deleting DNS AAAA Record: %s", deleteResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
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 TestAccAzureRMDnsAAAARecord_basic(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMDnsAAAARecord_basic, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsAAAARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsAAAARecordExists("azurerm_dns_aaaa_record.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsAAAARecord_updateRecords(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsAAAARecord_basic, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsAAAARecord_updateRecords, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsAAAARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsAAAARecordExists("azurerm_dns_aaaa_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_aaaa_record.test", "records.#", "2"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsAAAARecordExists("azurerm_dns_aaaa_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_aaaa_record.test", "records.#", "3"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsAAAARecord_withTags(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsAAAARecord_withTags, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsAAAARecord_withTagsUpdate, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsAAAARecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsAAAARecordExists("azurerm_dns_aaaa_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_aaaa_record.test", "tags.#", "2"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsAAAARecordExists("azurerm_dns_aaaa_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_aaaa_record.test", "tags.#", "1"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsAAAARecordExists(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.GetAAAARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetAAAARecordSet: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: GetAAAARecordSet: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsAAAARecordDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_dns_aaaa_record" {
|
||||
continue
|
||||
}
|
||||
|
||||
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
||||
readRequest.Command = &dns.GetAAAARecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetAAAARecordSet: %s", err)
|
||||
}
|
||||
|
||||
if readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: DNS AAAA Record still exists: %s", readResponse.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMDnsAAAARecord_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_aaaa_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsAAAARecord_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_aaaa_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006", "::1"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsAAAARecord_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_aaaa_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"]
|
||||
|
||||
tags {
|
||||
environment = "Production"
|
||||
cost_center = "MSFT"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsAAAARecord_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_aaaa_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"]
|
||||
|
||||
tags {
|
||||
environment = "staging"
|
||||
}
|
||||
}
|
||||
`
|
|
@ -0,0 +1,165 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/jen20/riviera/dns"
|
||||
)
|
||||
|
||||
func resourceArmDnsCNameRecord() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceArmDnsCNameRecordCreate,
|
||||
Read: resourceArmDnsCNameRecordRead,
|
||||
Update: resourceArmDnsCNameRecordCreate,
|
||||
Delete: resourceArmDnsCNameRecordDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"resource_group_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"zone_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"records": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Required: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"ttl": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceArmDnsCNameRecordCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
tags := d.Get("tags").(map[string]interface{})
|
||||
expandedTags := expandTags(tags)
|
||||
|
||||
createCommand := &dns.CreateCNAMERecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
Location: "global",
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
TTL: d.Get("ttl").(int),
|
||||
Tags: *expandedTags,
|
||||
}
|
||||
|
||||
recordStrings := d.Get("records").(*schema.Set).List()
|
||||
records := make([]dns.CNAMERecord, len(recordStrings))
|
||||
for i, v := range recordStrings {
|
||||
records[i] = dns.CNAMERecord{
|
||||
CNAME: v.(string),
|
||||
}
|
||||
}
|
||||
createCommand.CNAMERecords = records
|
||||
|
||||
createRequest := rivieraClient.NewRequest()
|
||||
createRequest.Command = createCommand
|
||||
|
||||
createResponse, err := createRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating DNS CName Record: %s", err)
|
||||
}
|
||||
if !createResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error creating DNS CName Record: %s", createResponse.Error)
|
||||
}
|
||||
|
||||
readRequest := rivieraClient.NewRequest()
|
||||
readRequest.Command = &dns.GetCNAMERecordSet{
|
||||
Name: d.Get("name").(string),
|
||||
ResourceGroupName: d.Get("resource_group_name").(string),
|
||||
ZoneName: d.Get("zone_name").(string),
|
||||
}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS CName Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error reading DNS CName Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetCNAMERecordSetResponse)
|
||||
d.SetId(resp.ID)
|
||||
|
||||
return resourceArmDnsCNameRecordRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceArmDnsCNameRecordRead(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
readRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
readRequest.Command = &dns.GetCNAMERecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
log.Printf("[INFO] Error reading DNS A Record %q - removing from state", d.Id())
|
||||
d.SetId("")
|
||||
return fmt.Errorf("Error reading DNS A Record: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
resp := readResponse.Parsed.(*dns.GetCNAMERecordSetResponse)
|
||||
|
||||
d.Set("ttl", resp.TTL)
|
||||
|
||||
if resp.CNAMERecords != nil {
|
||||
records := make([]string, 0, len(resp.CNAMERecords))
|
||||
for _, record := range resp.CNAMERecords {
|
||||
records = append(records, record.CNAME)
|
||||
}
|
||||
|
||||
if err := d.Set("records", records); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
flattenAndSetTags(d, &resp.Tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceArmDnsCNameRecordDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*ArmClient)
|
||||
rivieraClient := client.rivieraClient
|
||||
|
||||
deleteRequest := rivieraClient.NewRequestForURI(d.Id())
|
||||
deleteRequest.Command = &dns.DeleteRecordSet{
|
||||
RecordSetType: "CNAME",
|
||||
}
|
||||
|
||||
deleteResponse, err := deleteRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting DNS CName Record: %s", err)
|
||||
}
|
||||
if !deleteResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Error deleting DNS CName Record: %s", deleteResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
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 TestAccAzureRMDnsCNameRecord_basic(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccAzureRMDnsCNameRecord_basic, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsCNameRecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsCNameRecordExists("azurerm_dns_cname_record.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_basic, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_updateRecords, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsCNameRecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsCNameRecordExists("azurerm_dns_cname_record.test"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsCNameRecordExists("azurerm_dns_cname_record.test"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAzureRMDnsCNameRecord_withTags(t *testing.T) {
|
||||
ri := acctest.RandInt()
|
||||
preConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_withTags, ri, ri, ri)
|
||||
postConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_withTagsUpdate, ri, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckAzureRMDnsCNameRecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: preConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsCNameRecordExists("azurerm_dns_cname_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_cname_record.test", "tags.#", "2"),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: postConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckAzureRMDnsCNameRecordExists("azurerm_dns_cname_record.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"azurerm_dns_cname_record.test", "tags.#", "1"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsCNameRecordExists(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.GetCNAMERecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetCNAMERecordSet: %s", err)
|
||||
}
|
||||
if !readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: GetCNAMERecordSet: %s", readResponse.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testCheckAzureRMDnsCNameRecordDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*ArmClient).rivieraClient
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "azurerm_dns_cname_record" {
|
||||
continue
|
||||
}
|
||||
|
||||
readRequest := conn.NewRequestForURI(rs.Primary.ID)
|
||||
readRequest.Command = &dns.GetCNAMERecordSet{}
|
||||
|
||||
readResponse, err := readRequest.Execute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Bad: GetCNAMERecordSet: %s", err)
|
||||
}
|
||||
|
||||
if readResponse.IsSuccessful() {
|
||||
return fmt.Errorf("Bad: DNS CNAME Record still exists: %s", readResponse.Error)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var testAccAzureRMDnsCNameRecord_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_cname_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["contoso.com"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsCNameRecord_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_cname_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["contoso.co.uk"]
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsCNameRecord_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_cname_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["contoso.com"]
|
||||
|
||||
tags {
|
||||
environment = "Production"
|
||||
cost_center = "MSFT"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testAccAzureRMDnsCNameRecord_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_cname_record" "test" {
|
||||
name = "myarecord%d"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
ttl = "300"
|
||||
records = ["contoso.com"]
|
||||
|
||||
tags {
|
||||
environment = "staging"
|
||||
}
|
||||
}
|
||||
`
|
|
@ -15,6 +15,7 @@ type APIInfo struct {
|
|||
Method string
|
||||
URLPathFunc func() string
|
||||
ResponseTypeFunc func() interface{}
|
||||
RequestPropertiesFunc func() interface{}
|
||||
}
|
||||
|
||||
// HasBody returns true if the API Request should have a body. This is usually
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
@ -106,6 +107,35 @@ func (request *Request) pollForAsynchronousResponse(acceptedResponse *http.Respo
|
|||
}
|
||||
}
|
||||
|
||||
func defaultARMRequestStruct(request *Request, properties interface{}) interface{} {
|
||||
bodyStruct := struct {
|
||||
Location *string `json:"location,omitempty"`
|
||||
Tags *map[string]*string `json:"tags,omitempty"`
|
||||
Properties interface{} `json:"properties"`
|
||||
}{
|
||||
Properties: properties,
|
||||
}
|
||||
|
||||
if location, hasLocation := readLocation(request.Command); hasLocation {
|
||||
bodyStruct.Location = &location
|
||||
}
|
||||
if tags, hasTags := readTags(request.Command); hasTags {
|
||||
if len(tags) > 0 {
|
||||
bodyStruct.Tags = &tags
|
||||
}
|
||||
}
|
||||
|
||||
return bodyStruct
|
||||
}
|
||||
|
||||
func defaultARMRequestSerialize(body interface{}) (io.ReadSeeker, error) {
|
||||
jsonEncodedRequest, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.NewReader(jsonEncodedRequest), nil
|
||||
}
|
||||
|
||||
func (request *Request) Execute() (*Response, error) {
|
||||
apiInfo := request.Command.APIInfo()
|
||||
|
||||
|
@ -124,30 +154,23 @@ func (request *Request) Execute() (*Response, error) {
|
|||
}
|
||||
|
||||
// Encode the request body if necessary
|
||||
body := bytes.NewReader([]byte{})
|
||||
var body io.ReadSeeker
|
||||
if apiInfo.HasBody() {
|
||||
bodyStruct := struct {
|
||||
Location *string `json:"location,omitempty"`
|
||||
Tags *map[string]*string `json:"tags,omitempty"`
|
||||
Properties interface{} `json:"properties"`
|
||||
}{
|
||||
Properties: request.Command,
|
||||
var bodyStruct interface{}
|
||||
if apiInfo.RequestPropertiesFunc != nil {
|
||||
bodyStruct = defaultARMRequestStruct(request, apiInfo.RequestPropertiesFunc())
|
||||
} else {
|
||||
bodyStruct = defaultARMRequestStruct(request, request.Command)
|
||||
}
|
||||
|
||||
if location, hasLocation := readLocation(request.Command); hasLocation {
|
||||
bodyStruct.Location = &location
|
||||
}
|
||||
if tags, hasTags := readTags(request.Command); hasTags {
|
||||
if len(tags) > 0 {
|
||||
bodyStruct.Tags = &tags
|
||||
}
|
||||
}
|
||||
|
||||
jsonEncodedRequest, err := json.Marshal(bodyStruct)
|
||||
serialized, err := defaultARMRequestSerialize(bodyStruct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body = bytes.NewReader(jsonEncodedRequest)
|
||||
|
||||
body = serialized
|
||||
} else {
|
||||
|
||||
body = bytes.NewReader([]byte{})
|
||||
}
|
||||
|
||||
// Create an HTTP request
|
||||
|
|
|
@ -10,3 +10,9 @@ func dnsZoneDefaultURLPathFunc(resourceGroupName, dnsZoneName string) func() str
|
|||
return fmt.Sprintf("resourceGroups/%s/providers/%s/dnsZones/%s", resourceGroupName, apiProvider, dnsZoneName)
|
||||
}
|
||||
}
|
||||
|
||||
func dnsRecordSetDefaultURLPathFunc(resourceGroupName, dnsZoneName, recordSetType, recordSetName string) func() string {
|
||||
return func() string {
|
||||
return fmt.Sprintf("resourceGroups/%s/providers/%s/dnsZones/%s/%s/%s", resourceGroupName, apiProvider, dnsZoneName, recordSetType, recordSetName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type ARecord struct {
|
||||
IPv4Address string `json:"ipv4Address" mapstructure:"ipv4Address"`
|
||||
}
|
||||
|
||||
type CreateARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
ARecords []ARecord `mapstructure:"ARecords"`
|
||||
}
|
||||
|
||||
type CreateARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
ARecords []ARecord `json:"ARecords"`
|
||||
}
|
||||
|
||||
func (command CreateARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "A", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type AAAARecord struct {
|
||||
IPv6Address string `json:"ipv6Address" mapstructure:"ipv6Address"`
|
||||
}
|
||||
|
||||
type CreateAAAARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
AAAARecords []AAAARecord `mapstructure:"AAAARecords"`
|
||||
}
|
||||
|
||||
type CreateAAAARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
AAAARecords []AAAARecord `json:"AAAARecords"`
|
||||
}
|
||||
|
||||
func (command CreateAAAARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "AAAA", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateAAAARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type CNAMERecord struct {
|
||||
CNAME string `json:"cname" mapstructure:"cname"`
|
||||
}
|
||||
|
||||
type CreateCNAMERecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
CNAMERecords []CNAMERecord `mapstructure:"CNAMERecords"`
|
||||
}
|
||||
|
||||
type CreateCNAMERecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
CNAMERecords []CNAMERecord `json:"CNAMERecords"`
|
||||
}
|
||||
|
||||
func (command CreateCNAMERecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "CNAME", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateCNAMERecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type MXRecord struct {
|
||||
Preference string `json:"preference" mapstructure:"preference"` //*Why* is this a string in the API?!
|
||||
Exchange string `json:"exchange" mapstructure:"exchange"`
|
||||
}
|
||||
|
||||
type CreateMXRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
MXRecords []MXRecord `mapstructure:"MXRecords"`
|
||||
}
|
||||
|
||||
type CreateMXRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
MXRecords []MXRecord `json:"MXRecords"`
|
||||
}
|
||||
|
||||
func (command CreateMXRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "MX", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateMXRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type NSRecord struct {
|
||||
NSDName string `json:"nsdname" mapstructure:"nsdname"`
|
||||
}
|
||||
|
||||
type CreateNSRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
NSRecords []NSRecord `mapstructure:"NSRecords"`
|
||||
}
|
||||
|
||||
type CreateNSRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
NSRecords []NSRecord `json:"NSRecords"`
|
||||
}
|
||||
|
||||
func (command CreateNSRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "NS", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateNSRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type SOARecord struct {
|
||||
Email string `json:"email" mapstructure:"email"`
|
||||
ExpireTime int `json:"expireTime" mapstructure:"expireTime"`
|
||||
Host string `json:"host" mapstructure:"host"`
|
||||
MinimumTTL int `json:"minimumTTL" mapstructure:"minimumTTL"`
|
||||
RefreshTime int `json:"refreshTime" mapstructure:"refreshTime"`
|
||||
RetryTime int `json:"retryTime" mapstructure:"retryTime"`
|
||||
}
|
||||
|
||||
type CreateSOARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
SOARecords []SOARecord `mapstructure:"SOARecords"`
|
||||
}
|
||||
|
||||
type CreateSOARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
SOARecords []SOARecord `json:"SOARecords"`
|
||||
}
|
||||
|
||||
func (command CreateSOARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "SOA", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateSOARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type SRVRecord struct {
|
||||
Priority int `json:"priority" mapstructure:"priority"`
|
||||
Weight int `json:"weight" mapstructure:"weight"`
|
||||
Port int `json:"port" mapstructure:"port"`
|
||||
Target string `json:"target" mapstructure:"target"`
|
||||
}
|
||||
|
||||
type CreateSRVRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
SRVRecords []SRVRecord `mapstructure:"SRVRecords"`
|
||||
}
|
||||
|
||||
type CreateSRVRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
SRVRecords []SRVRecord `json:"SRVRecords"`
|
||||
}
|
||||
|
||||
func (command CreateSRVRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "SRV", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateSRVRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type TXTRecord struct {
|
||||
Value int `json:"value" mapstructure:"value"`
|
||||
}
|
||||
|
||||
type CreateTXTRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
TXTRecords []TXTRecord `mapstructure:"TXTRecords"`
|
||||
}
|
||||
|
||||
type CreateTXTRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
Location string `json:"-" riviera:"location"`
|
||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||
TTL int `json:"TTL"`
|
||||
TXTRecords []TXTRecord `json:"TXTRecords"`
|
||||
}
|
||||
|
||||
func (command CreateTXTRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "PUT",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "TXT", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &CreateTXTRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type DeleteRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
RecordSetType string `json:"-"`
|
||||
}
|
||||
|
||||
func (command DeleteRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "DELETE",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, command.RecordSetType, command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
ARecords []ARecord `mapstructure:"ARecords"`
|
||||
}
|
||||
|
||||
type GetARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "A", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetAAAARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
AAAARecords []AAAARecord `mapstructure:"AAAARecords"`
|
||||
}
|
||||
|
||||
type GetAAAARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetAAAARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "AAAA", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetAAAARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetCNAMERecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
CNAMERecords []CNAMERecord `mapstructure:"CNAMERecords"`
|
||||
}
|
||||
|
||||
type GetCNAMERecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetCNAMERecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "CNAME", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetCNAMERecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetMXRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
MXRecords []MXRecord `mapstructure:"MXRecords"`
|
||||
}
|
||||
|
||||
type GetMXRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetMXRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "MX", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetMXRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetNSRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
NSRecords []NSRecord `mapstructure:"NSRecords"`
|
||||
}
|
||||
|
||||
type GetNSRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetNSRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "NS", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetNSRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetSOARecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
SOARecords []SOARecord `mapstructure:"SOARecords"`
|
||||
}
|
||||
|
||||
type GetSOARecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetSOARecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "SOA", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetSOARecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package dns
|
||||
|
||||
import "github.com/jen20/riviera/azure"
|
||||
|
||||
type GetSRVRecordSetResponse struct {
|
||||
ID string `mapstructure:"id"`
|
||||
Name string `mapstructure:"name"`
|
||||
Location string `mapstructure:"location"`
|
||||
Tags map[string]*string `mapstructure:"tags"`
|
||||
TTL *int `mapstructure:"TTL"`
|
||||
SRVRecords []SRVRecord `mapstructure:"SRVRecords"`
|
||||
}
|
||||
|
||||
type GetSRVRecordSet struct {
|
||||
Name string `json:"-"`
|
||||
ResourceGroupName string `json:"-"`
|
||||
ZoneName string `json:"-"`
|
||||
}
|
||||
|
||||
func (command GetSRVRecordSet) APIInfo() azure.APIInfo {
|
||||
return azure.APIInfo{
|
||||
APIVersion: apiVersion,
|
||||
Method: "GET",
|
||||
URLPathFunc: dnsRecordSetDefaultURLPathFunc(command.ResourceGroupName, command.ZoneName, "SRV", command.Name),
|
||||
ResponseTypeFunc: func() interface{} {
|
||||
return &GetSRVRecordSetResponse{}
|
||||
},
|
||||
}
|
||||
}
|
|
@ -7,16 +7,23 @@ type GetDatabaseResponse struct {
|
|||
Name *string `mapstructure:"name"`
|
||||
Location *string `mapstructure:"location"`
|
||||
Tags *map[string]string `mapstructure:"tags"`
|
||||
Kind *string `mapstructure:"kind"`
|
||||
DatabaseID *string `mapstructure:"databaseId"`
|
||||
DatabaseName *string `mapstructure:"databaseName"`
|
||||
Status *string `mapstructure:"status"`
|
||||
Collation *string `mapstructure:"collation"`
|
||||
Edition *string `mapstructure:"edition"`
|
||||
ServiceLevelObjective *string `mapstructure:"serviceLevelObjective"`
|
||||
MaxSizeInBytes *string `mapstructure:"maxSizeInBytes"`
|
||||
CreationDate *string `mapstructure:"creationDate"`
|
||||
CurrentServiceLevelObjectiveID *string `mapstructure:"currentServiceLevelObjectiveId"`
|
||||
RequestedServiceObjectiveID *string `mapstructure:"requestedServiceObjectiveId"`
|
||||
RequestedServiceObjectiveName *string `mapstructure:"requestedServiceObjectiveName"`
|
||||
DefaultSecondaryLocation *string `mapstructure:"defaultSecondaryLocation"`
|
||||
Encryption *string `mapstructure:"encryption"`
|
||||
EarliestRestoreDate *string `mapstructure:"earliestRestoreDate"`
|
||||
ElasticPoolName *string `mapstructure:"elasticPoolName"`
|
||||
ContainmentState *string `mapstructure:"containmentState"`
|
||||
}
|
||||
|
||||
type GetDatabase struct {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
layout: "azurerm"
|
||||
page_title: "Azure Resource Manager: azurerm_dns_a_record"
|
||||
sidebar_current: "docs-azurerm-resource-dns-a-record"
|
||||
description: |-
|
||||
Create a DNS A Record.
|
||||
---
|
||||
|
||||
# azurerm\_dns\_a\_record
|
||||
|
||||
Enables you to manage DNS A Records within Azure DNS.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acceptanceTestResourceGroup1"
|
||||
location = "West US"
|
||||
}
|
||||
resource "azurerm_dns_zone" "test" {
|
||||
name = "mydomain.com"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
}
|
||||
|
||||
resource "azurerm_dns_a_record" "test" {
|
||||
name = "test"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
ttl = "300"
|
||||
records = ["10.0.180.17"]
|
||||
}
|
||||
```
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the DNS A Record.
|
||||
|
||||
* `resource_group_name` - (Required) Specifies the resource group where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `zone_name` - (Required) Specifies the DNS Zone where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `TTL` - (Required) The Time To Live (TTL) of the DNS record.
|
||||
|
||||
* `records` - (Required) List of IPv4 Addresses.
|
||||
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The DNS A Record ID.
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
layout: "azurerm"
|
||||
page_title: "Azure Resource Manager: azurerm_dns_aaaa_record"
|
||||
sidebar_current: "docs-azurerm-resource-dns-aaaa-record"
|
||||
description: |-
|
||||
Create a DNS AAAA Record.
|
||||
---
|
||||
|
||||
# azurerm\_dns\_aaaa\_record
|
||||
|
||||
Enables you to manage DNS AAAA Records within Azure DNS.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acceptanceTestResourceGroup1"
|
||||
location = "West US"
|
||||
}
|
||||
resource "azurerm_dns_zone" "test" {
|
||||
name = "mydomain.com"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
}
|
||||
|
||||
resource "azurerm_dns_aaaa_record" "test" {
|
||||
name = "test"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
ttl = "300"
|
||||
records = ["2607:f8b0:4009:1803::1005"]
|
||||
}
|
||||
```
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the DNS AAAA Record.
|
||||
|
||||
* `resource_group_name` - (Required) Specifies the resource group where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `zone_name` - (Required) Specifies the DNS Zone where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `TTL` - (Required) The Time To Live (TTL) of the DNS record.
|
||||
|
||||
* `records` - (Required) List of IPv6 Addresses.
|
||||
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The DNS AAAA Record ID.
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
layout: "azurerm"
|
||||
page_title: "Azure Resource Manager: azurerm_dns_cname_record"
|
||||
sidebar_current: "docs-azurerm-resource-dns-cname-record"
|
||||
description: |-
|
||||
Create a DNS CNAME Record.
|
||||
---
|
||||
|
||||
# azurerm\_dns\_cname\_record
|
||||
|
||||
Enables you to manage DNS CNAME Records within Azure DNS.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
resource "azurerm_resource_group" "test" {
|
||||
name = "acceptanceTestResourceGroup1"
|
||||
location = "West US"
|
||||
}
|
||||
resource "azurerm_dns_zone" "test" {
|
||||
name = "mydomain.com"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
}
|
||||
|
||||
resource "azurerm_dns_cname_record" "test" {
|
||||
name = "test"
|
||||
zone_name = "${azurerm_dns_zone.test.name}"
|
||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||
ttl = "300"
|
||||
records = ["contoso.com"]
|
||||
}
|
||||
```
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the DNS CNAME Record.
|
||||
|
||||
* `resource_group_name` - (Required) Specifies the resource group where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `zone_name` - (Required) Specifies the DNS Zone where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `TTL` - (Required) The Time To Live (TTL) of the DNS record.
|
||||
|
||||
* `records` - (Required) The target of the CNAME. Must be a single value.
|
||||
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The DNS CName Record ID.
|
|
@ -28,7 +28,7 @@ The following arguments are supported:
|
|||
|
||||
* `name` - (Required) The name of the DNS Zone. Must be a valid domain name.
|
||||
|
||||
* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.
|
||||
* `resource_group_name` - (Required) Specifies the resource group where the resource exists. Changing this forces a new resource to be created.
|
||||
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
|
|
|
@ -34,6 +34,18 @@
|
|||
<a href="#">DNS Resources</a>
|
||||
<ul class="nav nav-visible">
|
||||
|
||||
<li<%= sidebar_current("docs-azurerm-resource-dns-a-record") %>>
|
||||
<a href="/docs/providers/azurerm/r/dns_a_record.html">azurerm_dns_a_record</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-azurerm-resource-dns-aaaa-record") %>>
|
||||
<a href="/docs/providers/azurerm/r/dns_aaaa_record.html">azurerm_dns_aaaa_record</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-azurerm-resource-dns-cname-record") %>>
|
||||
<a href="/docs/providers/azurerm/r/dns_cname_record.html">azurerm_dns_cname_record</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-azurerm-resource-dns-zone") %>>
|
||||
<a href="/docs/providers/azurerm/r/dns_zone.html">azurerm_dns_zone</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue