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

Adding azurerm_dns_ds_record and azurerm_dns_tlsa_record #28213

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/hashicorp/terraform-provider-azurerm

replace github.com/hashicorp/go-azure-sdk/resource-manager => ../go-azure-sdk/resource-manager

require (
github.com/Azure/azure-sdk-for-go v66.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.29
Expand All @@ -17,7 +19,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-azure-helpers v0.71.0
github.com/hashicorp/go-azure-sdk/resource-manager v0.20241206.1180327
github.com/hashicorp/go-azure-sdk/resource-manager v0.20241128.1112539
github.com/hashicorp/go-azure-sdk/sdk v0.20241206.1180327
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-multierror v1.1.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-azure-helpers v0.71.0 h1:ra3aIRzg01g6MLKQ+yABcb6WJtrqRUDDgyuPLmyZ9lY=
github.com/hashicorp/go-azure-helpers v0.71.0/go.mod h1:BmbF4JDYXK5sEmFeU5hcn8Br21uElcqLfdQxjatwQKw=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20241206.1180327 h1:6b8IGRB1RpeFUtUym6bf+GJgyWuQpZq+fa/dBpHgPIE=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20241206.1180327/go.mod h1:Y2T5KK4QAV+/tGfcwp5BzPRQs5/cbIXT/igtHqYZ09U=
github.com/hashicorp/go-azure-sdk/sdk v0.20241206.1180327 h1:c7Y0wwTOdna2dndVW1nalZ/DZX1wDQCSj2JNgiLycKw=
github.com/hashicorp/go-azure-sdk/sdk v0.20241206.1180327/go.mod h1:oI5R0fTbBx3K/sJBK5R/OlEy8ozdQjvctxVU9v3EDkc=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
Expand Down
4 changes: 2 additions & 2 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
analysisservices_v2017_08_01 "github.com/hashicorp/go-azure-sdk/resource-manager/analysisservices/2017-08-01"
azurestackhci_v2024_01_01 "github.com/hashicorp/go-azure-sdk/resource-manager/azurestackhci/2024-01-01"
datadog_v2021_03_01 "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01"
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01"
dns_v2023_07_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview"
fluidrelay_2022_05_26 "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26"
hdinsight_v2021_06_01 "github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01"
nginx_2024_11_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-11-01-preview"
Expand Down Expand Up @@ -201,7 +201,7 @@ type Client struct {
DesktopVirtualization *desktopvirtualization.Client
DevTestLabs *devtestlabs.Client
DigitalTwins *digitaltwins.Client
Dns *dns_v2018_05_01.Client
Dns *dns_v2023_07_01_preview.Client
DomainServices *domainservices.Client
Dynatrace *dynatrace.Client
Elastic *elastic.Client
Expand Down
1 change: 1 addition & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
dataprotection.Registration{},
desktopvirtualization.Registration{},
digitaltwins.Registration{},
dns.Registration{},
domainservices.Registration{},
dynatrace.Registration{},
elasticsan.Registration{},
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package client

import (
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01"
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_a_record_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"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"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_a_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_a_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_aaaa_record_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"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/tf/set"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_aaaa_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_aaaa_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_caa_record_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"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"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_caa_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"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/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/dns/migration"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_caa_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_cname_record_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"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/2018-05-01/recordsets"
"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"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_cname_record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"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/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/trafficmanager/2022-04-01/endpoints"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down
2 changes: 1 addition & 1 deletion internal/services/dns/dns_cname_record_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets"
"github.com/hashicorp/go-azure-sdk/resource-manager/dns/2023-07-01-preview/recordsets"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
145 changes: 145 additions & 0 deletions internal/services/dns/dns_ds_record_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package dns

import (
"context"
"fmt"
"time"

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

var _ sdk.DataSource = DnsDSRecordDataResource{}

type DnsDSRecordDataResource struct{}

func (DnsDSRecordDataResource) ModelObject() interface{} {
return &DnsDSRecordDataSourceModel{}
}

func (d DnsDSRecordDataResource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return validate.ValidateRecordTypeID(recordsets.RecordTypeDS)
}

func (DnsDSRecordDataResource) ResourceType() string {
return "azurerm_dns_ds_record"
}

type DnsDSRecordDataSourceModel struct {
Name string `tfschema:"name"`
ZoneId string `tfschema:"dns_zone_id"`
Ttl int64 `tfschema:"ttl"`
Record []DnsDSRecordResourceRecord `tfschema:"record"`
Tags map[string]string `tfschema:"tags"`
Fqdn string `tfschema:"fqdn"`
}

func (DnsDSRecordDataResource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
},

"dns_zone_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: zones.ValidateDnsZoneID,
},
}
}

func (DnsDSRecordDataResource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"record": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"algorithm": {
Type: pluginsdk.TypeInt,
Computed: true,
},

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

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

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

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

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

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

func (DnsDSRecordDataResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Dns.RecordSets
subscriptionId := metadata.Client.Account.SubscriptionId

var state DnsDSRecordDataSourceModel
if err := metadata.Decode(&state); err != nil {
return fmt.Errorf("decoding: %+v", err)
}
zoneId, err := zones.ParseDnsZoneID(state.ZoneId)
if err != nil {
return fmt.Errorf("parsing dns_zone_id: %+v", err)
}
id := recordsets.NewRecordTypeID(subscriptionId, zoneId.ResourceGroupName, zoneId.DnsZoneName, recordsets.RecordTypeDS, state.Name)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
state.Ttl = pointer.From(props.TTL)
state.Fqdn = pointer.From(props.Fqdn)

state.Record = flattenDnsDSRecords(props.DSRecords)

state.Tags = pointer.From(props.Metadata)
}
}
metadata.SetID(id)

return metadata.Encode(&state)
},
}
}
44 changes: 44 additions & 0 deletions internal/services/dns/dns_ds_record_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package dns_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type DnsDSRecordDataSource struct{}

func TestAccDataSourceDnsDSRecord_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_dns_ds_record", "test")
r := DnsDSRecordDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("dns_zone_id").Exists(),
check.That(data.ResourceName).Key("record.#").HasValue("2"),
check.That(data.ResourceName).Key("ttl").Exists(),
check.That(data.ResourceName).Key("fqdn").Exists(),
check.That(data.ResourceName).Key("tags.%").HasValue("0"),
),
},
})
}

func (DnsDSRecordDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_dns_ds_record" "test" {
name = azurerm_dns_ds_record.test.name
dns_zone_id = azurerm_dns_zone.test.id
}
`, DnsDSRecordResource{}.basic(data))
}
Loading
Loading