Skip to content
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

Support regional records #156

Merged
5 commits merged into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions internal/framework/resources/zone_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ZoneRecordResourceModel struct {
Name types.String `tfsdk:"name"`
QualifiedName types.String `tfsdk:"qualified_name"`
Type types.String `tfsdk:"type"`
Regions types.List `tfsdk:"regions"`
Value types.String `tfsdk:"value"`
TTL types.Int64 `tfsdk:"ttl"`
Priority types.Int64 `tfsdk:"priority"`
Expand Down Expand Up @@ -81,6 +82,10 @@ func (r *ZoneRecordResource) Schema(_ context.Context, _ resource.SchemaRequest,
stringplanmodifier.RequiresReplace(),
},
},
"regions": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
},
"value": schema.StringAttribute{
Required: true,
},
Expand Down Expand Up @@ -125,6 +130,8 @@ func (r *ZoneRecordResource) Create(ctx context.Context, req resource.CreateRequ

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
regions := make([]string, len(data.Regions.Elements()))
resp.Diagnostics.Append(data.Regions.ElementsAs(ctx, &regions, false)...)

if resp.Diagnostics.HasError() {
return
Expand All @@ -134,6 +141,7 @@ func (r *ZoneRecordResource) Create(ctx context.Context, req resource.CreateRequ
Name: dnsimple.String(data.Name.ValueString()),
Type: data.Type.ValueString(),
Content: data.Value.ValueString(),
Regions: regions,
TTL: int(data.TTL.ValueInt64()),
}

Expand Down Expand Up @@ -248,6 +256,8 @@ func (r *ZoneRecordResource) Update(ctx context.Context, req resource.UpdateRequ

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
regions := make([]string, len(data.Regions.Elements()))
resp.Diagnostics.Append(data.Regions.ElementsAs(ctx, &regions, false)...)

if resp.Diagnostics.HasError() {
return
Expand All @@ -257,6 +267,7 @@ func (r *ZoneRecordResource) Update(ctx context.Context, req resource.UpdateRequ
Name: dnsimple.String(data.Name.ValueString()),
Type: data.Type.ValueString(),
Content: data.Value.ValueString(),
Regions: regions,
TTL: int(data.TTL.ValueInt64()),
}

Expand Down
1 change: 1 addition & 0 deletions internal/framework/resources/zone_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ resource "dnsimple_zone_record" "test" {
value = "192.168.0.10"
type = "A"
ttl = 2800
regions = ["IAD", "SYD"]
This conversation was marked as resolved.
Show resolved Hide resolved
}`, domainName)
}

Expand Down