Skip to content

Commit

Permalink
Merge pull request #3184 from Lucretius/datasource_serviceendpoints
Browse files Browse the repository at this point in the history
Add service endpoint to subnet data_source
  • Loading branch information
tombuildsstuff authored Apr 6, 2019
2 parents 87279bf + 0105697 commit 5e28259
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
12 changes: 12 additions & 0 deletions azurerm/data_source_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
}
}
Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions azurerm/data_source_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions website/docs/d/subnet.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 5e28259

Please sign in to comment.