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..35e89058 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_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"), @@ -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_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"), @@ -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"