From 4febaab59783bf056074c4aa543c39a34a8156ed Mon Sep 17 00:00:00 2001 From: ecklf Date: Fri, 26 Aug 2022 13:36:34 +0200 Subject: [PATCH 1/3] fix dns record bugs --- docs/resources/dns_record.md | 5 ++++- vercel/resource_dns_record.go | 13 ++++++++++++- vercel/resource_dns_record_model.go | 1 + vercel/resource_dns_record_test.go | 24 ++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/docs/resources/dns_record.md b/docs/resources/dns_record.md index f50f57f7..6e9b5e52 100644 --- a/docs/resources/dns_record.md +++ b/docs/resources/dns_record.md @@ -5,6 +5,7 @@ subcategory: "" description: |- Provides a DNS Record resource. DNS records are instructions that live in authoritative DNS servers and provide information about a domain. + ~> The value field must be specified on all DNS record types except SRV. When using SRV DNS records, the srv field must be specified. For more detailed information, please see the Vercel documentation https://vercel.com/docs/concepts/projects/custom-domains#dns-records --- @@ -14,6 +15,8 @@ Provides a DNS Record resource. DNS records are instructions that live in authoritative DNS servers and provide information about a domain. +~> The `value` field must be specified on all DNS record types except `SRV`. When using `SRV` DNS records, the `srv` field must be specified. + For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/custom-domains#dns-records) ## Example Usage @@ -97,7 +100,7 @@ resource "vercel_dns_record" "txt" { - `domain` (String) The domain name, or zone, that the DNS record should be created beneath. - `name` (String) The subdomain name of the record. This should be an empty string if the rercord is for the root domain. -- `type` (String) The type of DNS record. +- `type` (String) The type of DNS record. Available types: `A`, `AAAA`, `ALIAS`, `CAA`, `CNAME`, `MX`, `NS`, `SRV`, `TXT`. ### Optional diff --git a/vercel/resource_dns_record.go b/vercel/resource_dns_record.go index e6085c19..e9f0d194 100644 --- a/vercel/resource_dns_record.go +++ b/vercel/resource_dns_record.go @@ -23,6 +23,8 @@ Provides a DNS Record resource. DNS records are instructions that live in authoritative DNS servers and provide information about a domain. +~> The ` + "`value` field" + ` must be specified on all DNS record types except ` + "`SRV`" + `. When using ` + "`SRV`" + ` DNS records, the ` + "`srv`" + ` field must be specified. + For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/concepts/projects/custom-domains#dns-records) `, Attributes: map[string]tfsdk.Attribute{ @@ -48,7 +50,7 @@ For more detailed information, please see the [Vercel documentation](https://ver Type: types.StringType, }, "type": { - Description: "The type of DNS record.", + Description: "The type of DNS record. Available types: " + "`A`" + ", " + "`AAAA`" + ", " + "`ALIAS`" + ", " + "`CAA`" + ", " + "`CNAME`" + ", " + "`MX`" + ", " + "`NS`" + ", " + "`SRV`" + ", " + "`TXT`" + ".", PlanModifiers: tfsdk.AttributePlanModifiers{resource.RequiresReplace()}, Required: true, Type: types.StringType, @@ -65,6 +67,7 @@ For more detailed information, please see the [Vercel documentation](https://ver "ttl": { Description: "The TTL value in seconds. Must be a number between 60 and 2147483647. If unspecified, it will default to 60 seconds.", Optional: true, + Computed: true, Type: types.Int64Type, Validators: []tfsdk.AttributeValidator{ int64GreaterThan(60), @@ -141,6 +144,7 @@ func (r resourceDNSRecord) ValidateConfig(ctx context.Context, req resource.Vali if resp.Diagnostics.HasError() { return } + if config.Type.Value == "SRV" && config.SRV == nil { resp.Diagnostics.AddError( "DNS Record Invalid", @@ -148,6 +152,13 @@ func (r resourceDNSRecord) ValidateConfig(ctx context.Context, req resource.Vali ) } + if config.Type.Value != "SRV" && config.Value.Null { + resp.Diagnostics.AddError( + "DNS Record Invalid", + fmt.Sprintf("The `value` attribute must be set on records of `type` '%s'", config.Type.Value), + ) + } + if config.Type.Value == "SRV" && !config.Value.Null { resp.Diagnostics.AddError( "DNS Record Invalid", diff --git a/vercel/resource_dns_record_model.go b/vercel/resource_dns_record_model.go index d263fba2..f89d7ff6 100644 --- a/vercel/resource_dns_record_model.go +++ b/vercel/resource_dns_record_model.go @@ -40,6 +40,7 @@ func (d DNSRecord) toCreateDNSRecordRequest() client.CreateDNSRecordRequest { Weight: d.SRV.Weight.Value, } } + return client.CreateDNSRecordRequest{ Domain: d.Domain.Value, MXPriority: d.MXPriority.Value, diff --git a/vercel/resource_dns_record_test.go b/vercel/resource_dns_record_test.go index 06d0372c..cec9cdea 100644 --- a/vercel/resource_dns_record_test.go +++ b/vercel/resource_dns_record_test.go @@ -63,6 +63,7 @@ func TestAcc_DNSRecord(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( + testAccDNSRecordDestroy("vercel_dns_record.a_without_ttl", ""), testAccDNSRecordDestroy("vercel_dns_record.a", ""), testAccDNSRecordDestroy("vercel_dns_record.aaaa", ""), testAccDNSRecordDestroy("vercel_dns_record.alias", ""), @@ -76,6 +77,11 @@ func TestAcc_DNSRecord(t *testing.T) { { Config: testAccDNSRecordConfig(testDomain(), nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( + testAccDNSRecordExists("vercel_dns_record.a_without_ttl", ""), + resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), + resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), + resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "60"), + resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "127.0.0.1"), testAccDNSRecordExists("vercel_dns_record.a", ""), resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), @@ -137,6 +143,11 @@ func TestAcc_DNSRecord(t *testing.T) { { Config: testAccDNSRecordConfigUpdated(testDomain(), nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( + testAccDNSRecordExists("vercel_dns_record.a_without_ttl", ""), + resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), + resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), + resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "120"), + resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "127.0.0.1"), testAccDNSRecordExists("vercel_dns_record.a", ""), resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), @@ -234,6 +245,12 @@ func TestAcc_DNSRecord(t *testing.T) { func testAccDNSRecordConfig(testDomain, nameSuffix string) string { return fmt.Sprintf(` +resource "vercel_dns_record" "a_without_ttl" { + domain = "%[1]s" + name = "test-acc-%[2]s-a-without-ttl-record" + type = "A" + value = "127.0.0.1" +} resource "vercel_dns_record" "a" { domain = "%[1]s" name = "test-acc-%[2]s-a-record" @@ -320,6 +337,13 @@ resource "vercel_dns_record" "ns" { func testAccDNSRecordConfigUpdated(testDomain, nameSuffix string) string { return fmt.Sprintf(` +resource "vercel_dns_record" "a_without_ttl" { + domain = "%[1]s" + name = "test-acc-%[2]s-a-without-ttl-record" + type = "A" + ttl = 120 + value = "127.0.0.1" +} resource "vercel_dns_record" "a" { domain = "%[1]s" name = "test-acc-%[2]s-a-record-updated" From 9f9ae6763577f013767b810e37986c0f9d72c23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20/=20=E7=8F=9E=E8=BE=B0?= Date: Fri, 26 Aug 2022 13:52:25 +0200 Subject: [PATCH 2/3] Update vercel/resource_dns_record_test.go Co-authored-by: Douglas Parsons --- vercel/resource_dns_record_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vercel/resource_dns_record_test.go b/vercel/resource_dns_record_test.go index cec9cdea..b4947cb6 100644 --- a/vercel/resource_dns_record_test.go +++ b/vercel/resource_dns_record_test.go @@ -144,10 +144,10 @@ func TestAcc_DNSRecord(t *testing.T) { Config: testAccDNSRecordConfigUpdated(testDomain(), nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( testAccDNSRecordExists("vercel_dns_record.a_without_ttl", ""), - resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), - resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), - resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "120"), - resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "127.0.0.1"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain()), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "type", "A"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "ttl", "120"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "value", "127.0.0.1"), testAccDNSRecordExists("vercel_dns_record.a", ""), resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), From c4d11dd9fd0fe4fa1d041f2f575d6257cba42a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florentin=20/=20=E7=8F=9E=E8=BE=B0?= Date: Fri, 26 Aug 2022 13:57:40 +0200 Subject: [PATCH 3/3] Update vercel/resource_dns_record_test.go Co-authored-by: Douglas Parsons --- vercel/resource_dns_record_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vercel/resource_dns_record_test.go b/vercel/resource_dns_record_test.go index b4947cb6..35e89058 100644 --- a/vercel/resource_dns_record_test.go +++ b/vercel/resource_dns_record_test.go @@ -78,10 +78,10 @@ func TestAcc_DNSRecord(t *testing.T) { Config: testAccDNSRecordConfig(testDomain(), nameSuffix), Check: resource.ComposeAggregateTestCheckFunc( testAccDNSRecordExists("vercel_dns_record.a_without_ttl", ""), - resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), - resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), - resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "60"), - resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "127.0.0.1"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain()), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "type", "A"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "ttl", "60"), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "value", "127.0.0.1"), testAccDNSRecordExists("vercel_dns_record.a", ""), resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"),