Skip to content

Commit d54b3c6

Browse files
authored
Add support for comments on DNS records (#157)
Closes #156
1 parent e19ed08 commit d54b3c6

File tree

7 files changed

+104
-82
lines changed

7 files changed

+104
-82
lines changed

client/dns_record_create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type CreateDNSRecordRequest struct {
2222
TTL int64 `json:"ttl,omitempty"`
2323
Type string `json:"type"`
2424
Value string `json:"value,omitempty"`
25+
Comment string `json:"comment"`
2526
}
2627

2728
// CreateDNSRecord creates a DNS record for a specified domain name within Vercel.

client/dns_record_get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type DNSRecord struct {
1616
Value string `json:"value"`
1717
RecordType string `json:"recordType"`
1818
Priority int64 `json:"priority"`
19+
Comment string `json:"comment"`
1920
}
2021

2122
// GetDNSRecord retrieves information about a DNS domain from Vercel.

client/dns_record_update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type UpdateDNSRecordRequest struct {
2222
SRV *SRVUpdate `json:"srv,omitempty"`
2323
TTL *int64 `json:"ttl,omitempty"`
2424
Value *string `json:"value,omitempty"`
25+
Comment string `json:"comment"`
2526
}
2627

2728
// UpdateDNSRecord updates a DNS record for a specified domain name within Vercel.

docs/resources/dns_record.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ resource "vercel_dns_record" "txt" {
104104

105105
### Optional
106106

107+
- `comment` (String) A comment explaining what the DNS record is for.
107108
- `mx_priority` (Number) The priority of the MX record. The priority specifies the sequence that an email server receives emails. A smaller value indicates a higher priority.
108109
- `srv` (Attributes) Settings for an SRV record. (see [below for nested schema](#nestedatt--srv))
109110
- `team_id` (String) The team ID that the domain and DNS records belong to. Required when configuring a team resource if a default team has not been set in the provider.

vercel/resource_dns_record.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package vercel
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/hashicorp/terraform-plugin-framework/resource"
89
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1012
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1113
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1214
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -109,6 +111,15 @@ For more detailed information, please see the [Vercel documentation](https://ver
109111
int64LessThan(65535),
110112
},
111113
},
114+
"comment": schema.StringAttribute{
115+
Description: "A comment explaining what the DNS record is for.",
116+
Optional: true,
117+
Computed: true,
118+
Default: stringdefault.StaticString(""),
119+
Validators: []validator.String{
120+
stringLengthBetween(0, 500),
121+
},
122+
},
112123
"srv": schema.SingleNestedAttribute{
113124
Description: "Settings for an SRV record.",
114125
Optional: true, // required for SRV records.
@@ -303,6 +314,8 @@ func (r *dnsRecordResource) Update(ctx context.Context, req resource.UpdateReque
303314
return
304315
}
305316

317+
thing, _ := json.Marshal(plan.toUpdateRequest())
318+
tflog.Error(ctx, "UPDATE REQUEST", map[string]interface{}{"request": string(thing)})
306319
out, err := r.client.UpdateDNSRecord(
307320
ctx,
308321
plan.TeamID.ValueString(),

vercel/resource_dns_record_model.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type DNSRecord struct {
2828
TeamID types.String `tfsdk:"team_id"`
2929
Type types.String `tfsdk:"type"`
3030
Value types.String `tfsdk:"value"`
31+
Comment types.String `tfsdk:"comment"`
3132
}
3233

3334
func (d DNSRecord) toCreateDNSRecordRequest() client.CreateDNSRecordRequest {
@@ -49,6 +50,7 @@ func (d DNSRecord) toCreateDNSRecordRequest() client.CreateDNSRecordRequest {
4950
Type: d.Type.ValueString(),
5051
Value: d.Value.ValueString(),
5152
SRV: srv,
53+
Comment: d.Comment.ValueString(),
5254
}
5355
}
5456

@@ -68,6 +70,7 @@ func (d DNSRecord) toUpdateRequest() client.UpdateDNSRecordRequest {
6870
SRV: srv,
6971
TTL: toInt64Pointer(d.TTL),
7072
Value: toStrPointer(d.Value),
73+
Comment: d.Comment.ValueString(),
7174
}
7275
}
7376

@@ -80,6 +83,7 @@ func convertResponseToDNSRecord(r client.DNSRecord, value types.String, srv *SRV
8083
TTL: types.Int64Value(r.TTL),
8184
TeamID: toTeamID(r.TeamID),
8285
Type: types.StringValue(r.RecordType),
86+
Comment: types.StringValue(r.Comment),
8387
}
8488

8589
if r.RecordType == "SRV" {

0 commit comments

Comments
 (0)