-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fef53ae
commit 1e24365
Showing
3 changed files
with
445 additions
and
0 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 |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.