Skip to content

Commit

Permalink
Add TLSA records (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilcox9 committed Dec 10, 2024
1 parent fef53ae commit 1e24365
Show file tree
Hide file tree
Showing 3 changed files with 445 additions and 0 deletions.
119 changes: 119 additions & 0 deletions internal/services/dns/dns_tlsa_record_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package dns

import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
)

func dataSourceDnsTLSARecord() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceDnsTLSARecordRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
},

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"zone_name": {
Type: pluginsdk.TypeString,
Required: true,
},

"record": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"matching_type": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"selector": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"usage": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"cert_association_data": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
Set: resourceDnsTLSARecordHash,
},

"ttl": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tags": commonschema.TagsDataSource(),
},
}
}

func dataSourceDnsTLSARecordRead(d *pluginsdk.ResourceData, meta interface{}) error {
recordSetsClient := meta.(*clients.Client).Dns.RecordSets
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
subscriptionId := meta.(*clients.Client).Account.SubscriptionId

id := recordsets.NewRecordTypeID(subscriptionId, d.Get("resource_group_name").(string), d.Get("zone_name").(string), recordsets.RecordTypeTLSA, d.Get("name").(string))
resp, err := recordSetsClient.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("reading %s: %+v", id, err)
}

d.SetId(id.ID())

d.Set("name", id.RelativeRecordSetName)
d.Set("resource_group_name", id.ResourceGroupName)
d.Set("zone_name", id.DnsZoneName)

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
d.Set("ttl", props.TTL)
d.Set("fqdn", props.Fqdn)

if err := d.Set("record", flattenAzureRmDnsTLSARecords(props.TLSARecords)); err != nil {
return err
}

return tags.FlattenAndSet(d, props.Metadata)
}
}

return nil
}
Loading

0 comments on commit 1e24365

Please sign in to comment.