From 45b3b9d18120f163491a5435b52804f863598646 Mon Sep 17 00:00:00 2001 From: Mat Davies Date: Tue, 8 Dec 2015 17:19:20 +0000 Subject: [PATCH] provider/dme: Add support for `gtdLocation` Add support for GTD (Global Traffic Director) enabled domains to the DME provider. Specifically add `gtdLocation` to the `dme_record` resource. --- builtin/providers/dme/resource_dme_record.go | 11 +++++++ .../providers/dme/resource_dme_record_test.go | 31 +++++++++++++++++++ .../docs/providers/dme/r/record.html.markdown | 4 +++ 3 files changed, 46 insertions(+) diff --git a/builtin/providers/dme/resource_dme_record.go b/builtin/providers/dme/resource_dme_record.go index 8e078e420..4578dd5f9 100644 --- a/builtin/providers/dme/resource_dme_record.go +++ b/builtin/providers/dme/resource_dme_record.go @@ -74,6 +74,10 @@ func resourceDMERecord() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "gtdLocation": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, } } @@ -168,6 +172,9 @@ func getAll(d *schema.ResourceData, cr map[string]interface{}) error { if attr, ok := d.GetOk("value"); ok { cr["value"] = attr.(string) } + if attr, ok := d.GetOk("gtdLocation"); ok { + cr["gtdLocation"] = attr.(string) + } switch strings.ToUpper(d.Get("type").(string)) { case "A", "CNAME", "ANAME", "TXT", "SPF", "NS", "PTR", "AAAA": @@ -213,6 +220,10 @@ func setAll(d *schema.ResourceData, rec *dnsmadeeasy.Record) error { d.Set("name", rec.Name) d.Set("ttl", rec.TTL) d.Set("value", rec.Value) + // only set gtdLocation if it is given as this is optional. + if rec.GtdLocation != "" { + d.Set("gtdLocation", rec.GtdLocation) + } switch rec.Type { case "A", "CNAME", "ANAME", "TXT", "SPF", "NS", "PTR": diff --git a/builtin/providers/dme/resource_dme_record_test.go b/builtin/providers/dme/resource_dme_record_test.go index 430afacb2..f1b79292a 100644 --- a/builtin/providers/dme/resource_dme_record_test.go +++ b/builtin/providers/dme/resource_dme_record_test.go @@ -36,6 +36,8 @@ func TestAccDMERecord_basic(t *testing.T) { "dme_record.test", "value", "1.1.1.1"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -65,6 +67,8 @@ func TestAccDMERecordCName(t *testing.T) { "dme_record.test", "value", "foo"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -131,6 +135,8 @@ func TestAccDMERecordMX(t *testing.T) { "dme_record.test", "mxLevel", "10"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -172,6 +178,8 @@ func TestAccDMERecordHTTPRED(t *testing.T) { resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -201,6 +209,8 @@ func TestAccDMERecordTXT(t *testing.T) { "dme_record.test", "value", "\"foo\""), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -230,6 +240,8 @@ func TestAccDMERecordSPF(t *testing.T) { "dme_record.test", "value", "\"foo\""), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -259,6 +271,8 @@ func TestAccDMERecordPTR(t *testing.T) { "dme_record.test", "value", "foo"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -288,6 +302,8 @@ func TestAccDMERecordNS(t *testing.T) { "dme_record.test", "value", "foo"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -317,6 +333,8 @@ func TestAccDMERecordAAAA(t *testing.T) { "dme_record.test", "value", "fe80::0202:b3ff:fe1e:8329"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -352,6 +370,8 @@ func TestAccDMERecordSRV(t *testing.T) { "dme_record.test", "port", "30"), resource.TestCheckResourceAttr( "dme_record.test", "ttl", "2000"), + resource.TestCheckResourceAttr( + "dme_record.test", "gtdLocation", "DEFAULT"), ), }, }, @@ -413,6 +433,7 @@ resource "dme_record" "test" { type = "A" value = "1.1.1.1" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigCName = ` @@ -422,6 +443,7 @@ resource "dme_record" "test" { type = "CNAME" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigAName = ` @@ -431,6 +453,7 @@ resource "dme_record" "test" { type = "ANAME" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigMX = ` @@ -441,6 +464,7 @@ resource "dme_record" "test" { value = "foo" mxLevel = 10 ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigHTTPRED = ` @@ -455,6 +479,7 @@ resource "dme_record" "test" { keywords = "terraform example" description = "This is a description" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigTXT = ` @@ -464,6 +489,7 @@ resource "dme_record" "test" { type = "TXT" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigSPF = ` @@ -473,6 +499,7 @@ resource "dme_record" "test" { type = "SPF" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigPTR = ` @@ -482,6 +509,7 @@ resource "dme_record" "test" { type = "PTR" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigNS = ` @@ -491,6 +519,7 @@ resource "dme_record" "test" { type = "NS" value = "foo" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigAAAA = ` @@ -500,6 +529,7 @@ resource "dme_record" "test" { type = "AAAA" value = "FE80::0202:B3FF:FE1E:8329" ttl = 2000 + gtdLocation = "DEFAULT" }` const testDMERecordConfigSRV = ` @@ -512,4 +542,5 @@ resource "dme_record" "test" { weight = 20 port = 30 ttl = 2000 + gtdLocation = "DEFAULT" }` diff --git a/website/source/docs/providers/dme/r/record.html.markdown b/website/source/docs/providers/dme/r/record.html.markdown index e4cea025e..94f66655f 100644 --- a/website/source/docs/providers/dme/r/record.html.markdown +++ b/website/source/docs/providers/dme/r/record.html.markdown @@ -20,6 +20,7 @@ resource "dme_record" "www" { type = "A" value = "192.168.1.1" ttl = 3600 + gtdLocation = "DEFAULT" } ``` @@ -34,6 +35,7 @@ The following arguments are supported: * `value` - (Required) The value of the record; its usage will depend on the `type` (see below) * `ttl` - (Integer, Optional) The TTL of the record +* `gtdLocation` - (String, Optional) The GTD Location of the record on GTD enabled domains; Unless GTD is enabled this should be omitted or set to "DEFAULT" Additional arguments are listed below under DNS Record Types. @@ -117,6 +119,7 @@ The following attributes are exported: * `value` - The value of the record `type` (see below) * `ttl` - The TTL of the record +* `gtdLocation` - The GTD Location of the record on GTD enabled domains Additional fields may also be exported by some record types - see DNS Record Types. @@ -141,6 +144,7 @@ resource "dme_record" "testa" { type = "A" value = "1.1.1.1" ttl = 1000 + gtdLocation = "DEFAULT" } # CNAME record