Skip to content

Commit

Permalink
Data Source: azurerm_network_service_tags - add name property (#23382)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Oct 12, 2023
1 parent 45e882e commit d59c372
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/services/network/network_service_tags_data_source.go
Expand Up @@ -33,6 +33,11 @@ func dataSourceNetworkServiceTags() *pluginsdk.Resource {
Required: true,
},

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

"location_filter": commonschema.LocationOptional(),

"address_prefixes": {
Expand Down Expand Up @@ -91,6 +96,8 @@ func dataSourceNetworkServiceTagsRead(d *pluginsdk.ResourceData, meta interface{
}

if location.NormalizeNilable(props.Region) == locationFilter {
d.Set("name", value.Name)

addressPrefixes := make([]string, 0)
if props.AddressPrefixes != nil {
addressPrefixes = *props.AddressPrefixes
Expand Down
28 changes: 28 additions & 0 deletions internal/services/network/network_service_tags_data_source_test.go
Expand Up @@ -20,6 +20,25 @@ func TestAccDataSourceAzureRMServiceTags_basic(t *testing.T) {
{
Config: r.basic(),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("address_prefixes.#").Exists(),
check.That(data.ResourceName).Key("ipv4_cidrs.#").Exists(),
check.That(data.ResourceName).Key("ipv6_cidrs.#").Exists(),
),
},
})
}

func TestAccDataSourceAzureRMServiceTags_tagName(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_network_service_tags", "test")
r := NetworkServiceTagsDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.tagName(),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("id").HasValue("westus2-Storage"),
check.That(data.ResourceName).Key("name").HasValue("Storage.WestUS2"),
check.That(data.ResourceName).Key("address_prefixes.#").Exists(),
check.That(data.ResourceName).Key("ipv4_cidrs.#").Exists(),
check.That(data.ResourceName).Key("ipv6_cidrs.#").Exists(),
Expand All @@ -36,6 +55,7 @@ func TestAccDataSourceAzureRMServiceTags_region(t *testing.T) {
{
Config: r.region(),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("address_prefixes.#").Exists(),
check.That(data.ResourceName).Key("ipv4_cidrs.#").Exists(),
check.That(data.ResourceName).Key("ipv6_cidrs.#").Exists(),
Expand All @@ -58,3 +78,11 @@ func (NetworkServiceTagsDataSource) region() string {
location_filter = "australiacentral"
}`
}

func (NetworkServiceTagsDataSource) tagName() string {
return `data "azurerm_network_service_tags" "test" {
location = "westus2"
service = "Storage"
location_filter = "westus2"
}`
}
2 changes: 2 additions & 0 deletions website/docs/d/network_service_tags.html.markdown
Expand Up @@ -46,6 +46,8 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `id` - The ID of this Service Tags block.

* `name` - The name of this Service Tags block.

* `address_prefixes` - List of address prefixes for the service type (and optionally a specific region).

* `ipv4_cidrs` - List of IPv4 addresses for the service type (and optionally a specific region)
Expand Down

0 comments on commit d59c372

Please sign in to comment.