provider/azurerm: DNS CNAME resource wasn't posting records (#7113)
* provider/azurerm: DNS CNAME resource wasn't posting records Azure changed the API for CNAME at some point and since then we haven't been creating CNAME records. The API changes from []records to a single record This PR changes the schema for dns cnames to have a record parameter and adds a deprecation warning around records. Talked with @jen20 on this and we decided that it's currently broken and we should handle this as part of 0.7 where there are other breaking changes ``` TF_LOG=1 make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMDnsCNameRecord' 2>~/tf.log ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /vendor/) TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMDnsCNameRecord -timeout 120m === RUN TestAccAzureRMDnsCNameRecord_basic --- PASS: TestAccAzureRMDnsCNameRecord_basic (97.22s) === RUN TestAccAzureRMDnsCNameRecord_subdomain --- PASS: TestAccAzureRMDnsCNameRecord_subdomain (94.94s) === RUN TestAccAzureRMDnsCNameRecord_updateRecords --- PASS: TestAccAzureRMDnsCNameRecord_updateRecords (116.62s) ``` * Change DNS Records to removed rather than deprecated
This commit is contained in:
parent
18178aa158
commit
5644545680
|
@ -34,10 +34,16 @@ func resourceArmDnsCNameRecord() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"records": &schema.Schema{
|
"records": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Optional: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
|
Removed: "Use `record` instead. This attribute will be removed in a future version",
|
||||||
|
},
|
||||||
|
|
||||||
|
"record": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"ttl": &schema.Schema{
|
"ttl": &schema.Schema{
|
||||||
|
@ -64,17 +70,11 @@ func resourceArmDnsCNameRecordCreate(d *schema.ResourceData, meta interface{}) e
|
||||||
ZoneName: d.Get("zone_name").(string),
|
ZoneName: d.Get("zone_name").(string),
|
||||||
TTL: d.Get("ttl").(int),
|
TTL: d.Get("ttl").(int),
|
||||||
Tags: *expandedTags,
|
Tags: *expandedTags,
|
||||||
|
CNAMERecord: dns.CNAMERecord{
|
||||||
|
CNAME: d.Get("record").(string),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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 := rivieraClient.NewRequest()
|
||||||
createRequest.Command = createCommand
|
createRequest.Command = createCommand
|
||||||
|
|
||||||
|
@ -127,17 +127,7 @@ func resourceArmDnsCNameRecordRead(d *schema.ResourceData, meta interface{}) err
|
||||||
resp := readResponse.Parsed.(*dns.GetCNAMERecordSetResponse)
|
resp := readResponse.Parsed.(*dns.GetCNAMERecordSetResponse)
|
||||||
|
|
||||||
d.Set("ttl", resp.TTL)
|
d.Set("ttl", resp.TTL)
|
||||||
|
d.Set("record", resp.CNAMERecord.CNAME)
|
||||||
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)
|
flattenAndSetTags(d, &resp.Tags)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,27 @@ func TestAccAzureRMDnsCNameRecord_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMDnsCNameRecord_subdomain(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMDnsCNameRecord_subdomain, 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"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"azurerm_dns_cname_record.test", "record", "test.contoso.com"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) {
|
func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_basic, ri, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMDnsCNameRecord_basic, ri, ri, ri)
|
||||||
|
@ -151,7 +172,26 @@ resource "azurerm_dns_cname_record" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
zone_name = "${azurerm_dns_zone.test.name}"
|
zone_name = "${azurerm_dns_zone.test.name}"
|
||||||
ttl = "300"
|
ttl = "300"
|
||||||
records = ["contoso.com"]
|
record = "contoso.com"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var testAccAzureRMDnsCNameRecord_subdomain = `
|
||||||
|
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"
|
||||||
|
record = "test.contoso.com"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -170,7 +210,7 @@ resource "azurerm_dns_cname_record" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
zone_name = "${azurerm_dns_zone.test.name}"
|
zone_name = "${azurerm_dns_zone.test.name}"
|
||||||
ttl = "300"
|
ttl = "300"
|
||||||
records = ["contoso.co.uk"]
|
record = "contoso.co.uk"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -189,7 +229,7 @@ resource "azurerm_dns_cname_record" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
zone_name = "${azurerm_dns_zone.test.name}"
|
zone_name = "${azurerm_dns_zone.test.name}"
|
||||||
ttl = "300"
|
ttl = "300"
|
||||||
records = ["contoso.com"]
|
record = "contoso.com"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
environment = "Production"
|
environment = "Production"
|
||||||
|
@ -213,7 +253,7 @@ resource "azurerm_dns_cname_record" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
zone_name = "${azurerm_dns_zone.test.name}"
|
zone_name = "${azurerm_dns_zone.test.name}"
|
||||||
ttl = "300"
|
ttl = "300"
|
||||||
records = ["contoso.com"]
|
record = "contoso.com"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
environment = "staging"
|
environment = "staging"
|
||||||
|
|
|
@ -12,7 +12,7 @@ type CreateCNAMERecordSetResponse struct {
|
||||||
Location string `mapstructure:"location"`
|
Location string `mapstructure:"location"`
|
||||||
Tags map[string]*string `mapstructure:"tags"`
|
Tags map[string]*string `mapstructure:"tags"`
|
||||||
TTL *int `mapstructure:"TTL"`
|
TTL *int `mapstructure:"TTL"`
|
||||||
CNAMERecords []CNAMERecord `mapstructure:"CNAMERecords"`
|
CNAMERecord CNAMERecord `mapstructure:"CNAMERecord"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateCNAMERecordSet struct {
|
type CreateCNAMERecordSet struct {
|
||||||
|
@ -22,7 +22,7 @@ type CreateCNAMERecordSet struct {
|
||||||
Location string `json:"-" riviera:"location"`
|
Location string `json:"-" riviera:"location"`
|
||||||
Tags map[string]*string `json:"-" riviera:"tags"`
|
Tags map[string]*string `json:"-" riviera:"tags"`
|
||||||
TTL int `json:"TTL"`
|
TTL int `json:"TTL"`
|
||||||
CNAMERecords []CNAMERecord `json:"CNAMERecords"`
|
CNAMERecord CNAMERecord `json:"CNAMERecord"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (command CreateCNAMERecordSet) APIInfo() azure.APIInfo {
|
func (command CreateCNAMERecordSet) APIInfo() azure.APIInfo {
|
||||||
|
|
|
@ -3,12 +3,12 @@ package dns
|
||||||
import "github.com/jen20/riviera/azure"
|
import "github.com/jen20/riviera/azure"
|
||||||
|
|
||||||
type GetCNAMERecordSetResponse struct {
|
type GetCNAMERecordSetResponse struct {
|
||||||
ID string `mapstructure:"id"`
|
ID string `mapstructure:"id"`
|
||||||
Name string `mapstructure:"name"`
|
Name string `mapstructure:"name"`
|
||||||
Location string `mapstructure:"location"`
|
Location string `mapstructure:"location"`
|
||||||
Tags map[string]*string `mapstructure:"tags"`
|
Tags map[string]*string `mapstructure:"tags"`
|
||||||
TTL *int `mapstructure:"TTL"`
|
TTL *int `mapstructure:"TTL"`
|
||||||
CNAMERecords []CNAMERecord `mapstructure:"CNAMERecords"`
|
CNAMERecord CNAMERecord `mapstructure:"CNAMERecord"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetCNAMERecordSet struct {
|
type GetCNAMERecordSet struct {
|
||||||
|
|
|
@ -895,20 +895,28 @@
|
||||||
"revision": "f233a8bac88d1f2dc282a98186f5a3363b806181"
|
"revision": "f233a8bac88d1f2dc282a98186f5a3363b806181"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "oPpOfZn11Ef6DWOoETxSW9Venzs=",
|
||||||
"path": "github.com/jen20/riviera/azure",
|
"path": "github.com/jen20/riviera/azure",
|
||||||
"revision": "70dac624f9d3e37295dfa4012040106e5f7b1add"
|
"revision": "2f01b8f5b09bbc20a591b1dc4b48af0665106b3f",
|
||||||
|
"revisionTime": "2016-06-10T12:18:12Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "A2Ycn6MySifUKTHOnsG9oLwjitE=",
|
||||||
"path": "github.com/jen20/riviera/dns",
|
"path": "github.com/jen20/riviera/dns",
|
||||||
"revision": "70dac624f9d3e37295dfa4012040106e5f7b1add"
|
"revision": "2f01b8f5b09bbc20a591b1dc4b48af0665106b3f",
|
||||||
|
"revisionTime": "2016-06-10T12:18:12Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "zVXx6ha3bt0N4ukRbRHXjSl91S4=",
|
||||||
"path": "github.com/jen20/riviera/search",
|
"path": "github.com/jen20/riviera/search",
|
||||||
"revision": "70dac624f9d3e37295dfa4012040106e5f7b1add"
|
"revision": "2f01b8f5b09bbc20a591b1dc4b48af0665106b3f",
|
||||||
|
"revisionTime": "2016-06-10T12:18:12Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "KfquDaeBPGchw92QnojlJFsJKgk=",
|
||||||
"path": "github.com/jen20/riviera/sql",
|
"path": "github.com/jen20/riviera/sql",
|
||||||
"revision": "70dac624f9d3e37295dfa4012040106e5f7b1add"
|
"revision": "2f01b8f5b09bbc20a591b1dc4b48af0665106b3f",
|
||||||
|
"revisionTime": "2016-06-10T12:18:12Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "nKUCquNpJ9ifHgkXoT4K3Xar6R8=",
|
"checksumSHA1": "nKUCquNpJ9ifHgkXoT4K3Xar6R8=",
|
||||||
|
|
Loading…
Reference in New Issue