-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from alrayyes/feat/dns-data-source
feat: implement dns resource record sets data source
- Loading branch information
Showing
12 changed files
with
286 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
PUBLIC_CLOUD_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/publiccloud/api/openapi.yaml | ||
DEDICATED_SERVER_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/dedicatedserver/api/openapi.yaml | ||
DNS_API_SPEC_URL=https://raw.githubusercontent.com/Leaseweb/leaseweb-go-sdk/main/dns/api/openapi.yaml | ||
#PUBLIC_CLOUD_API_SPEC_URL=http://host.docker.internal:8081/publicCloud.json | ||
#DEDICATED_SERVER_API_SPEC_URL=http://host.docker.internal:8081/dedicatedServer.json | ||
#DNS_SERVER_API_SPEC_URL=http://host.docker.internal:8081/dns.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "leaseweb_dns_resource_record_sets Data Source - leaseweb" | ||
subcategory: "" | ||
description: |- | ||
List resource record sets | ||
--- | ||
|
||
# leaseweb_dns_resource_record_sets (Data Source) | ||
|
||
List resource record sets | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# List DNS resource record sets for example.com | ||
data "leaseweb_dns_resource_record_sets" "all" { | ||
domain_name = "example.com" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `domain_name` (String) Domain Name | ||
|
||
### Read-Only | ||
|
||
- `info_message` (String) Optional additional information | ||
- `resource_record_sets` (Attributes List) Array of resource record sets (see [below for nested schema](#nestedatt--resource_record_sets)) | ||
|
||
<a id="nestedatt--resource_record_sets"></a> | ||
### Nested Schema for `resource_record_sets` | ||
|
||
Read-Only: | ||
|
||
- `content` (List of String) Array of resource record set Content entries | ||
- `name` (String) Name of the resource record set | ||
- `ttl` (Number) Time to live of the resource record set | ||
- `type` (String) Type of the resource record set |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/leaseweb_dns_resource_record_sets/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# List DNS resource record sets for example.com | ||
data "leaseweb_dns_resource_record_sets" "all" { | ||
domain_name = "example.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package dns implements functionality for dns data sources & resources. | ||
package dns |
132 changes: 132 additions & 0 deletions
132
internal/provider/dns/resource_record_sets_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package dns | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
"github.com/leaseweb/terraform-provider-leaseweb/internal/utils" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSourceWithConfigure = &resourceRecordSet{} | ||
) | ||
|
||
type resourceRecordSetsDataSourceModel struct { | ||
DomainName types.String `tfsdk:"domain_name"` | ||
InfoMessage types.String `tfsdk:"info_message"` | ||
ResourceRecordSets []resourceRecordSetDataSourceModel `tfsdk:"resource_record_sets"` | ||
} | ||
|
||
type resourceRecordSetDataSourceModel struct { | ||
Name types.String `tfsdk:"name"` | ||
RecordType types.String `tfsdk:"type"` | ||
Content []string `tfsdk:"content"` | ||
TTL types.Int32 `tfsdk:"ttl"` | ||
} | ||
|
||
type resourceRecordSet struct { | ||
utils.DataSourceAPI | ||
} | ||
|
||
func (r *resourceRecordSet) Schema( | ||
_ context.Context, | ||
_ datasource.SchemaRequest, | ||
response *datasource.SchemaResponse, | ||
) { | ||
response.Schema = schema.Schema{ | ||
Description: "List resource record sets", | ||
Attributes: map[string]schema.Attribute{ | ||
"domain_name": schema.StringAttribute{ | ||
Required: true, | ||
Description: "Domain Name", | ||
Validators: []validator.String{ | ||
stringvalidator.LengthAtLeast(1), | ||
}, | ||
}, | ||
"info_message": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Optional additional information", | ||
}, | ||
"resource_record_sets": schema.ListNestedAttribute{ | ||
Description: "Array of resource record sets", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Name of the resource record set", | ||
}, | ||
"type": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Type of the resource record set", | ||
}, | ||
"content": schema.ListAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
Description: "Array of resource record set Content entries", | ||
}, | ||
"ttl": schema.Int32Attribute{ | ||
Computed: true, | ||
Description: "Time to live of the resource record set", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (r *resourceRecordSet) Read( | ||
ctx context.Context, | ||
request datasource.ReadRequest, | ||
response *datasource.ReadResponse, | ||
) { | ||
var config resourceRecordSetsDataSourceModel | ||
response.Diagnostics.Append(request.Config.Get(ctx, &config)...) | ||
|
||
result, httpResponse, err := r.DNSAPI.GetResourceRecordSetList( | ||
ctx, | ||
config.DomainName.ValueString(), | ||
).Execute() | ||
if err != nil { | ||
utils.SdkError(ctx, &response.Diagnostics, err, httpResponse) | ||
return | ||
} | ||
|
||
var resourceRecordSets []resourceRecordSetDataSourceModel | ||
for _, resourceRecordSetDetails := range result.GetResourceRecordSets() { | ||
resourceRecordSets = append( | ||
resourceRecordSets, | ||
resourceRecordSetDataSourceModel{ | ||
Name: basetypes.NewStringValue(resourceRecordSetDetails.GetName()), | ||
RecordType: basetypes.NewStringValue(string(resourceRecordSetDetails.GetType())), | ||
Content: resourceRecordSetDetails.GetContent(), | ||
TTL: basetypes.NewInt32Value(int32(resourceRecordSetDetails.GetTtl())), | ||
}, | ||
) | ||
} | ||
|
||
response.Diagnostics.Append( | ||
response.State.Set( | ||
ctx, | ||
resourceRecordSetsDataSourceModel{ | ||
DomainName: config.DomainName, | ||
InfoMessage: basetypes.NewStringValue(result.GetInfoMessage()), | ||
ResourceRecordSets: resourceRecordSets, | ||
}, | ||
)..., | ||
) | ||
} | ||
|
||
func NewResourceRecordSetsDataSource() datasource.DataSource { | ||
return &resourceRecordSet{ | ||
DataSourceAPI: utils.DataSourceAPI{ | ||
Name: "dns_resource_record_sets", | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters