-
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:
private_dns_zone_virtual_network_link
(#18045)
- Loading branch information
1 parent
351fe61
commit 3d53f35
Showing
4 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
internal/services/privatedns/private_dns_zone_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,87 @@ | ||
package privatedns | ||
|
||
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/privatedns/2018-09-01/virtualnetworklinks" | ||
"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 dataSourcePrivateDnsZoneVirtualNetworkLink() *pluginsdk.Resource { | ||
return &pluginsdk.Resource{ | ||
Read: dataSourcePrivateDnsZoneVirtualNetworkLinkRead, | ||
|
||
Timeouts: &pluginsdk.ResourceTimeout{ | ||
Read: pluginsdk.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
// TODO: in 4.0 switch this to `private_dns_zone_id` | ||
"private_dns_zone_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": commonschema.ResourceGroupNameForDataSource(), | ||
|
||
"virtual_network_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"registration_enabled": { | ||
Type: pluginsdk.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"tags": commonschema.TagsDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePrivateDnsZoneVirtualNetworkLinkRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).PrivateDns.VirtualNetworkLinksClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||
id := virtualnetworklinks.NewVirtualNetworkLinkID(subscriptionId, d.Get("resource_group_name").(string), d.Get("private_dns_zone_name").(string), d.Get("name").(string)) | ||
|
||
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("reading %s: %+v", id, err) | ||
} | ||
|
||
d.SetId(id.ID()) | ||
|
||
d.Set("name", id.VirtualNetworkLinkName) | ||
d.Set("private_dns_zone_name", id.PrivateZoneName) | ||
d.Set("resource_group_name", id.ResourceGroupName) | ||
|
||
if model := resp.Model; model != nil { | ||
if props := model.Properties; props != nil { | ||
d.Set("registration_enabled", props.RegistrationEnabled) | ||
|
||
if network := props.VirtualNetwork; network != nil { | ||
d.Set("virtual_network_id", network.Id) | ||
} | ||
} | ||
return tags.FlattenAndSet(d, model.Tags) | ||
} | ||
|
||
return nil | ||
} |
47 changes: 47 additions & 0 deletions
47
internal/services/privatedns/private_dns_zone_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,47 @@ | ||
package privatedns_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type PrivateDnsZoneVirtualNetworkLinkDataSource struct{} | ||
|
||
func TestAccDataSourcePrivateDnsZoneVirtualNetworkLink_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_private_dns_zone_virtual_network_link", "test") | ||
r := PrivateDnsZoneVirtualNetworkLinkDataSource{} | ||
|
||
resourceName := "azurerm_private_dns_zone_virtual_network_link.test" | ||
zoneName := "azurerm_private_dns_zone.test" | ||
vnetName := "azurerm_virtual_network.test" | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("id").MatchesOtherKey(check.That(resourceName).Key("id")), | ||
check.That(data.ResourceName).Key("name").MatchesOtherKey(check.That(resourceName).Key("name")), | ||
check.That(data.ResourceName).Key("resource_group_name").MatchesOtherKey(check.That(resourceName).Key("resource_group_name")), | ||
check.That(data.ResourceName).Key("virtual_network_id").MatchesOtherKey(check.That(vnetName).Key("id")), | ||
check.That(data.ResourceName).Key("private_dns_zone_name").MatchesOtherKey(check.That(zoneName).Key("name")), | ||
check.That(data.ResourceName).Key("registration_enabled").HasValue("false"), | ||
check.That(data.ResourceName).Key("tags.%").HasValue("0"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (PrivateDnsZoneVirtualNetworkLinkDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_private_dns_zone_virtual_network_link" "test" { | ||
name = azurerm_private_dns_zone_virtual_network_link.test.name | ||
resource_group_name = azurerm_resource_group.test.name | ||
private_dns_zone_name = azurerm_private_dns_zone.test.name | ||
} | ||
`, PrivateDnsZoneVirtualNetworkLinkResource{}.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
49 changes: 49 additions & 0 deletions
49
website/docs/d/private_dns_zone_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,49 @@ | ||
--- | ||
subcategory: "Private DNS" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_private_dns_zone_virtual_network_link" | ||
description: |- | ||
Gets information about an existing Private DNS Zone Virtual Network Link. | ||
--- | ||
|
||
# Data Source: azurerm_private_dns_zone_virtual_network_link | ||
|
||
Use this data source to access information about an existing Private DNS zone Virtual Network Link. These Links enable DNS resolution and registration inside Azure Virtual Networks using Azure Private DNS. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_private_dns_zone_virtual_network_link" "example" { | ||
name = "test" | ||
resource_group_name = "test-rg" | ||
private_dns_zone_name = "test-zone" | ||
} | ||
output "private_dns_a_record_id" { | ||
value = data.azurerm_private_dns_zone_virtual_network_link.example.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - The name of the Private DNS Zone Virtual Network Link. | ||
|
||
* `private_dns_zone_name` - The name of the Private DNS zone (without a terminating dot). | ||
|
||
* `resource_group_name` - Specifies the resource group where the Private DNS Zone exists. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the Private DNS Zone Virtual Network Link. | ||
|
||
* `virtual_network_id` - The ID of the Virtual Network that is linked to the DNS Zone. | ||
|
||
* `registration_enabled` - Whether the auto-registration of virtual machine records in the virtual network in the Private DNS zone is enabled or not. | ||
|
||
* `tags` - A mapping of tags to assign to the resource. | ||
|
||
## 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 Zone Virtual Network Link. |