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

New Data Source: azurerm_private_dns_resolver_inbound_endpoint #19948

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package privatednsresolver

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/dnsresolvers"
"github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/inboundendpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

type PrivateDNSResolverInboundEndpointDataSourceModel struct {
Name string `tfschema:"name"`
PrivateDNSResolverId string `tfschema:"private_dns_resolver_id"`
IPConfigurations []IPConfigurationModel `tfschema:"ip_configurations"`
Location string `tfschema:"location"`
Tags map[string]string `tfschema:"tags"`
}

type PrivateDNSResolverInboundEndpointDataSource struct{}

var _ sdk.DataSource = PrivateDNSResolverInboundEndpointDataSource{}

func (r PrivateDNSResolverInboundEndpointDataSource) ResourceType() string {
return "azurerm_private_dns_resolver_inbound_endpoint"
}

func (r PrivateDNSResolverInboundEndpointDataSource) ModelObject() interface{} {
return &PrivateDNSResolverInboundEndpointDataSourceModel{}
}

func (r PrivateDNSResolverInboundEndpointDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return inboundendpoints.ValidateInboundEndpointID
}

func (r PrivateDNSResolverInboundEndpointDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"private_dns_resolver_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: dnsresolvers.ValidateDnsResolverID,
},
}
}

func (r PrivateDNSResolverInboundEndpointDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"ip_configurations": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"subnet_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

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

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

"location": commonschema.LocationComputed(),

"tags": tags.SchemaDataSource(),
}
}

func (r PrivateDNSResolverInboundEndpointDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.PrivateDnsResolver.InboundEndpointsClient

var state PrivateDNSResolverInboundEndpointDataSourceModel
if err := metadata.Decode(&state); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

dnsForwardingRulesetId, err := inboundendpoints.ParseDnsResolverID(state.PrivateDNSResolverId)
if err != nil {
return err
}

id := inboundendpoints.NewInboundEndpointID(
dnsForwardingRulesetId.SubscriptionId,
dnsForwardingRulesetId.ResourceGroupName,
dnsForwardingRulesetId.DnsResolverName,
state.Name)
resp, err := client.Get(ctx, id)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
}

model := resp.Model
if model == nil {
return fmt.Errorf("retrieving %s: model was nil", id)
}

state.Location = location.Normalize(model.Location)
state.PrivateDNSResolverId = dnsresolvers.NewDnsResolverID(id.SubscriptionId, id.ResourceGroupName, id.DnsResolverName).ID()

state.IPConfigurations = flattenIPConfigurationModel(&model.Properties.IPConfigurations)
if model.Tags != nil {
state.Tags = *model.Tags
}

metadata.SetID(id)

return metadata.Encode(&state)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package privatednsresolver_test

import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type DNSResolverInboundEndpointDataSource struct{}

func TestAccDNSResolverInboundEndpointDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_private_dns_resolver_inbound_endpoint", "test")
d := DNSResolverInboundEndpointDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("private_dns_resolver_id").Exists(),
check.That(data.ResourceName).Key("location").HasValue(location.Normalize(data.Locations.Primary)),
check.That(data.ResourceName).Key("ip_configurations.0.subnet_id").Exists(),
check.That(data.ResourceName).Key("ip_configurations.0.private_ip_address").Exists(),
),
},
})
}

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

data "azurerm_private_dns_resolver_inbound_endpoint" "test" {
name = azurerm_private_dns_resolver_inbound_endpoint.test.name
private_dns_resolver_id = azurerm_private_dns_resolver.test.id
}
`, DNSResolverInboundEndpointResource{}.basic(data))
}
1 change: 1 addition & 0 deletions internal/services/privatednsresolver/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
func (r Registration) DataSources() []sdk.DataSource {
return []sdk.DataSource{
PrivateDNSResolverDnsResolverDataSource{},
PrivateDNSResolverInboundEndpointDataSource{},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
subcategory: "Private DNS Resolver"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_private_dns_resolver_inbound_endpoint"
description: |-
Gets information about an existing Private DNS Resolver Inbound Endpoint.
---

# Data Source: azurerm_private_dns_resolver_inbound_endpoint

Gets information about an existing Private DNS Resolver Inbound Endpoint.

## Example Usage

```hcl
resource "azurerm_private_dns_resolver_inbound_endpoint" "example" {
name = "example-drie"
private_dns_resolver_id = "example-private-dns-resolver-id"
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) Name of the Private DNS Resolver Inbound Endpoint.

* `private_dns_resolver_id` - (Required) ID of the Private DNS Resolver Inbound Endpoint.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Private DNS Resolver Inbound Endpoint.

* `ip_configurations` - A list of `ip_configurations` block as defined below.

* `location` - The Azure Region where the Private DNS Resolver Inbound Endpoint exists.

* `tags` - The tags assigned to the Private DNS Resolver Inbound Endpoint.

---

An `ip_configurations` block exports the following:

* `private_ip_allocation_method` - The private IP address allocation method.

* `subnet_id` - The subnet ID of the IP configuration.

* `private_ip_address` - The private IP address of the IP configuration.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Private DNS Resolver Inbound Endpoint.