-
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.
New Data Source:
azurerm_private_dns_resolver_virtual_network_link
(#…
- Loading branch information
1 parent
1753a4a
commit 26c00cd
Showing
4 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
...rnal/services/privatednsresolver/private_dns_resolver_virtual_network_link_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,114 @@ | ||
package privatednsresolver | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/dnsforwardingrulesets" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/virtualnetworklinks" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
) | ||
|
||
type PrivateDNSResolverVirtualNetworkLinDataSourcekModel struct { | ||
Name string `tfschema:"name"` | ||
DnsForwardingRulesetId string `tfschema:"dns_forwarding_ruleset_id"` | ||
Metadata map[string]string `tfschema:"metadata"` | ||
VirtualNetworkId string `tfschema:"virtual_network_id"` | ||
} | ||
|
||
type PrivateDNSResolverVirtualNetworkLinkDataSource struct{} | ||
|
||
var _ sdk.DataSource = PrivateDNSResolverVirtualNetworkLinkDataSource{} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) ResourceType() string { | ||
return "azurerm_private_dns_resolver_virtual_network_link" | ||
} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) ModelObject() interface{} { | ||
return &PrivateDNSResolverVirtualNetworkLinDataSourcekModel{} | ||
} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return virtualnetworklinks.ValidateVirtualNetworkLinkID | ||
} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) Arguments() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"dns_forwarding_ruleset_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: dnsforwardingrulesets.ValidateDnsForwardingRulesetID, | ||
}, | ||
} | ||
} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"virtual_network_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"metadata": { | ||
Type: pluginsdk.TypeMap, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (r PrivateDNSResolverVirtualNetworkLinkDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.PrivateDnsResolver.VirtualNetworkLinksClient | ||
|
||
var state PrivateDNSResolverVirtualNetworkLinDataSourcekModel | ||
if err := metadata.Decode(&state); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
dnsForwardingRulesetId, err := virtualnetworklinks.ParseDnsForwardingRulesetID(state.DnsForwardingRulesetId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := virtualnetworklinks.NewVirtualNetworkLinkID( | ||
dnsForwardingRulesetId.SubscriptionId, | ||
dnsForwardingRulesetId.ResourceGroupName, | ||
dnsForwardingRulesetId.DnsForwardingRulesetName, | ||
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.DnsForwardingRulesetId = dnsforwardingrulesets.NewDnsForwardingRulesetID(id.SubscriptionId, id.ResourceGroupName, id.DnsForwardingRulesetName).ID() | ||
state.VirtualNetworkId = model.Properties.VirtualNetwork.Id | ||
|
||
if model.Properties.Metadata != nil { | ||
state.Metadata = *model.Properties.Metadata | ||
} | ||
|
||
metadata.SetID(id) | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...services/privatednsresolver/private_dns_resolver_virtual_network_link_data_source_test.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,38 @@ | ||
package privatednsresolver_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type PrivateDNSResolverVirtualNetworkLinkDataSource struct{} | ||
|
||
func TestAccPrivateDNSResolverVirtualNetworkLinkDataSource_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_private_dns_resolver_virtual_network_link", "test") | ||
d := PrivateDNSResolverVirtualNetworkLinkDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: d.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("name").Exists(), | ||
check.That(data.ResourceName).Key("dns_forwarding_ruleset_id").Exists(), | ||
check.That(data.ResourceName).Key("virtual_network_id").Exists(), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (d PrivateDNSResolverVirtualNetworkLinkDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_private_dns_resolver_virtual_network_link" "test" { | ||
name = azurerm_private_dns_resolver_virtual_network_link.test.name | ||
dns_forwarding_ruleset_id = azurerm_private_dns_resolver_dns_forwarding_ruleset.test.id | ||
} | ||
`, PrivateDNSResolverVirtualNetworkLinkResource{}.basic(data)) | ||
} |
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
44 changes: 44 additions & 0 deletions
44
website/docs/d/private_dns_resolver_virtual_network_link.html.markdown
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,44 @@ | ||
--- | ||
subcategory: "Private DNS Resolver" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_private_dns_resolver_virtual_network_link" | ||
description: |- | ||
Gets information about an existing Private DNS Resolver Virtual Network Link. | ||
--- | ||
|
||
# Data Source: azurerm_private_dns_resolver_virtual_network_link | ||
|
||
Gets information about an existing Private DNS Resolver Virtual Network Link. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_private_dns_resolver_virtual_network_link" "example" { | ||
name = "example-link" | ||
dns_forwarding_ruleset_id = "example-dns-forwarding-ruleset-id" | ||
} | ||
``` | ||
|
||
## Arguments Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) Name of the Private DNS Resolver Virtual Network Link. | ||
|
||
* `dns_forwarding_ruleset_id` - (Required) ID of the Private DNS Resolver DNS Forwarding Ruleset. | ||
|
||
## Attributes Reference | ||
|
||
In addition to the Arguments listed above - the following Attributes are exported: | ||
|
||
* `id` - The ID of the Private DNS Resolver Virtual Network Link. | ||
|
||
* `virtual_network_id` - The ID of the Virtual Network that is linked to the Private DNS Resolver Virtual Network Link. | ||
|
||
* `metadata` - The metadata attached to the Private DNS Resolver Virtual Network Link. | ||
|
||
## 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 Virtual Network Link. |