diff --git a/azurerm/data_source_subnet.go b/azurerm/data_source_subnet.go index 7a7e0e50b8fc..e0793640680f 100644 --- a/azurerm/data_source_subnet.go +++ b/azurerm/data_source_subnet.go @@ -47,6 +47,14 @@ func dataSourceArmSubnet() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, + + "service_endpoints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, } } @@ -90,6 +98,10 @@ func dataSourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("ip_configurations", flattenSubnetIPConfigurations(props.IPConfigurations)); err != nil { return err } + + if err := d.Set("service_endpoints", flattenSubnetServiceEndpoints(props.ServiceEndpoints)); err != nil { + return err + } } return nil diff --git a/azurerm/data_source_subnet_test.go b/azurerm/data_source_subnet_test.go index 3c4c63642eea..3570f1f506b0 100644 --- a/azurerm/data_source_subnet_test.go +++ b/azurerm/data_source_subnet_test.go @@ -77,6 +77,32 @@ func TestAccDataSourceAzureRMSubnet_routeTable(t *testing.T) { }) } +func TestAccDataSourceAzureRMSubnet_serviceEndpoints(t *testing.T) { + dataSourceName := "data.azurerm_subnet.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSubnet_serviceEndpoints(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "name"), + resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_name"), + resource.TestCheckResourceAttrSet(dataSourceName, "address_prefix"), + resource.TestCheckResourceAttr(dataSourceName, "network_security_group_id", ""), + resource.TestCheckResourceAttr(dataSourceName, "route_table_id", ""), + resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.#", "2"), + resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.0", "Microsoft.Sql"), + resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.1", "Microsoft.Storage"), + ), + }, + }, + }) +} + func testAccDataSourceAzureRMSubnet_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -196,3 +222,33 @@ data "azurerm_subnet" "test" { } `, rInt, location, rInt, rInt, rInt, rInt) } + +func testAccDataSourceAzureRMSubnet_serviceEndpoints(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvirtnet%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctestsubnet%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" + service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] +} + +data "azurerm_subnet" "test" { + name = "${azurerm_subnet.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" +} +`, rInt, location, rInt, rInt) +} diff --git a/website/docs/d/subnet.html.markdown b/website/docs/d/subnet.html.markdown index d4d0c1626fee..913ea9a6d705 100644 --- a/website/docs/d/subnet.html.markdown +++ b/website/docs/d/subnet.html.markdown @@ -37,3 +37,4 @@ output "subnet_id" { * `network_security_group_id` - The ID of the Network Security Group associated with the subnet. * `route_table_id` - The ID of the Route Table associated with this subnet. * `ip_configurations` - The collection of IP Configurations with IPs within this subnet. +* `service_endpoints` - A list of Service Endpoints within this subnet.