这是indexloc提供的服务,不要输入任何密码
Skip to content

Add support for comments on DNS records #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/dns_record_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CreateDNSRecordRequest struct {
TTL int64 `json:"ttl,omitempty"`
Type string `json:"type"`
Value string `json:"value,omitempty"`
Comment string `json:"comment"`
}

// CreateDNSRecord creates a DNS record for a specified domain name within Vercel.
Expand Down
1 change: 1 addition & 0 deletions client/dns_record_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type DNSRecord struct {
Value string `json:"value"`
RecordType string `json:"recordType"`
Priority int64 `json:"priority"`
Comment string `json:"comment"`
}

// GetDNSRecord retrieves information about a DNS domain from Vercel.
Expand Down
1 change: 1 addition & 0 deletions client/dns_record_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type UpdateDNSRecordRequest struct {
SRV *SRVUpdate `json:"srv,omitempty"`
TTL *int64 `json:"ttl,omitempty"`
Value *string `json:"value,omitempty"`
Comment string `json:"comment"`
}

// UpdateDNSRecord updates a DNS record for a specified domain name within Vercel.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/dns_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ resource "vercel_dns_record" "txt" {

### Optional

- `comment` (String) A comment explaining what the DNS record is for.
- `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.
- `srv` (Attributes) Settings for an SRV record. (see [below for nested schema](#nestedatt--srv))
- `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.
Expand Down
13 changes: 13 additions & 0 deletions vercel/resource_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package vercel

import (
"context"
"encoding/json"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -109,6 +111,15 @@ For more detailed information, please see the [Vercel documentation](https://ver
int64LessThan(65535),
},
},
"comment": schema.StringAttribute{
Description: "A comment explaining what the DNS record is for.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Validators: []validator.String{
stringLengthBetween(0, 500),
},
},
"srv": schema.SingleNestedAttribute{
Description: "Settings for an SRV record.",
Optional: true, // required for SRV records.
Expand Down Expand Up @@ -303,6 +314,8 @@ func (r *dnsRecordResource) Update(ctx context.Context, req resource.UpdateReque
return
}

thing, _ := json.Marshal(plan.toUpdateRequest())
tflog.Error(ctx, "UPDATE REQUEST", map[string]interface{}{"request": string(thing)})
out, err := r.client.UpdateDNSRecord(
ctx,
plan.TeamID.ValueString(),
Expand Down
4 changes: 4 additions & 0 deletions vercel/resource_dns_record_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DNSRecord struct {
TeamID types.String `tfsdk:"team_id"`
Type types.String `tfsdk:"type"`
Value types.String `tfsdk:"value"`
Comment types.String `tfsdk:"comment"`
}

func (d DNSRecord) toCreateDNSRecordRequest() client.CreateDNSRecordRequest {
Expand All @@ -49,6 +50,7 @@ func (d DNSRecord) toCreateDNSRecordRequest() client.CreateDNSRecordRequest {
Type: d.Type.ValueString(),
Value: d.Value.ValueString(),
SRV: srv,
Comment: d.Comment.ValueString(),
}
}

Expand All @@ -68,6 +70,7 @@ func (d DNSRecord) toUpdateRequest() client.UpdateDNSRecordRequest {
SRV: srv,
TTL: toInt64Pointer(d.TTL),
Value: toStrPointer(d.Value),
Comment: d.Comment.ValueString(),
}
}

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

if r.RecordType == "SRV" {
Expand Down
Loading