provider/azurerm: Add the DNS A Record Resource

This commit is contained in:
stack72 2016-02-05 11:28:48 +00:00
parent 57836e0072
commit 761308cd2a
27 changed files with 1042 additions and 27 deletions

6
Godeps/Godeps.json generated
View File

@ -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",

View File

@ -61,6 +61,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_storage_blob": resourceArmStorageBlob(),
"azurerm_storage_queue": resourceArmStorageQueue(),
"azurerm_dns_zone": resourceArmDnsZone(),
"azurerm_dns_a_record": resourceArmDnsARecord(),
"azurerm_sql_server": resourceArmSqlServer(),
"azurerm_sql_database": resourceArmSqlDatabase(),
},

View File

@ -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
}

View File

@ -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"
}
}
`

View File

@ -11,10 +11,11 @@ type APICall interface {
// version is required, the HTTP method to use, and a factory function for
// responses.
type APIInfo struct {
APIVersion string
Method string
URLPathFunc func() string
ResponseTypeFunc func() interface{}
APIVersion string
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

View File

@ -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

View File

@ -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)
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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{}
},
}
}

View File

@ -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 {

View File

@ -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\_zone
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 Zone. Must be a valid domain name.
* `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.

View File

@ -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.

View File

@ -34,6 +34,10 @@
<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-zone") %>>
<a href="/docs/providers/azurerm/r/dns_zone.html">azurerm_dns_zone</a>
</li>