From 36b65cc7483622e283beaa48c334e5c3159d2fa6 Mon Sep 17 00:00:00 2001 From: njucz <740360112@qq.com> Date: Fri, 21 Feb 2020 17:39:42 +0800 Subject: [PATCH 1/2] add `private_ip_address` --- .../network/resource_arm_private_endpoint.go | 18 ++++++++++++++++++ .../resource_arm_private_endpoint_test.go | 1 + website/docs/r/private_endpoint.html.markdown | 2 ++ 3 files changed, 21 insertions(+) diff --git a/azurerm/internal/services/network/resource_arm_private_endpoint.go b/azurerm/internal/services/network/resource_arm_private_endpoint.go index cce2878f8e83..db7d08aae658 100644 --- a/azurerm/internal/services/network/resource_arm_private_endpoint.go +++ b/azurerm/internal/services/network/resource_arm_private_endpoint.go @@ -90,6 +90,10 @@ func resourceArmPrivateEndpoint() *schema.Resource { Optional: true, ValidateFunc: validation.StringLenBetween(1, 140), }, + "private_ip_address": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -166,6 +170,7 @@ func resourceArmPrivateEndpointCreateUpdate(d *schema.ResourceData, meta interfa func resourceArmPrivateEndpointRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.PrivateEndpointClient + nicsClient := meta.(*clients.Client).Network.InterfacesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -193,7 +198,20 @@ func resourceArmPrivateEndpointRead(d *schema.ResourceData, meta interface{}) er } if props := resp.PrivateEndpointProperties; props != nil { + privateIpAddress := "" + + if nics := props.NetworkInterfaces; nics != nil && len(*nics) > 0 { + nic := (*nics)[0] + if nic.ID != nil && *nic.ID != "" { + privateIpAddress = getPrivateIpAddress(ctx, nicsClient, *nic.ID) + } + } + flattenedConnection := flattenArmPrivateLinkEndpointServiceConnection(props.PrivateLinkServiceConnections, props.ManualPrivateLinkServiceConnections) + for _, item := range flattenedConnection { + v := item.(map[string]interface{}) + v["private_ip_address"] = privateIpAddress + } if err := d.Set("private_service_connection", flattenedConnection); err != nil { return fmt.Errorf("Error setting `private_service_connection`: %+v", err) } diff --git a/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go index 0357699e654a..3548306180a8 100644 --- a/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateEndpoint_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateEndpointExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_service_connection.0.private_ip_address"), ), }, data.ImportStep(), diff --git a/website/docs/r/private_endpoint.html.markdown b/website/docs/r/private_endpoint.html.markdown index 2a0c8428d971..df4e4a7b59a7 100644 --- a/website/docs/r/private_endpoint.html.markdown +++ b/website/docs/r/private_endpoint.html.markdown @@ -141,6 +141,8 @@ See the product [documentation](https://docs.microsoft.com/en-us/azure/private-l * `request_message` - (Optional) A message passed to the owner of the remote resource when the private endpoint attempts to establish the connection to the remote resource. The request message can be a maximum of `140` characters in length. Only valid if `is_manual_connection` is set to `true`. +* `private_ip_address` - The private IP address associated with the private endpoint, note that you will have a private IP address assigned to the private endpoint even if the connection request was `Rejected`. + ## Attributes Reference The following attributes are exported: From 9faf7caa13e79aea072178abdbdb9f66ebfce241 Mon Sep 17 00:00:00 2001 From: WS <20408400+WodansSon@users.noreply.github.com> Date: Tue, 25 Feb 2020 15:18:32 -0800 Subject: [PATCH 2/2] Added computed to the private_ip_address desc --- website/docs/r/private_endpoint.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/private_endpoint.html.markdown b/website/docs/r/private_endpoint.html.markdown index df4e4a7b59a7..8c47cda30ef8 100644 --- a/website/docs/r/private_endpoint.html.markdown +++ b/website/docs/r/private_endpoint.html.markdown @@ -141,7 +141,7 @@ See the product [documentation](https://docs.microsoft.com/en-us/azure/private-l * `request_message` - (Optional) A message passed to the owner of the remote resource when the private endpoint attempts to establish the connection to the remote resource. The request message can be a maximum of `140` characters in length. Only valid if `is_manual_connection` is set to `true`. -* `private_ip_address` - The private IP address associated with the private endpoint, note that you will have a private IP address assigned to the private endpoint even if the connection request was `Rejected`. +* `private_ip_address` - (Computed) The private IP address associated with the private endpoint, note that you will have a private IP address assigned to the private endpoint even if the connection request was `Rejected`. ## Attributes Reference