Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource/Data Source: azurerm_private_link_service, Data Source: azurerm_private_link_service_endpoint_connections and expose in azurerm_lb and azurerm_subnet #4426

Merged
merged 49 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c320621
Add new resources and data sources
WodansSon Sep 25, 2019
978be18
Manual fixup
WodansSon Sep 25, 2019
b196c7f
TOC tweaks
WodansSon Sep 25, 2019
3ad7245
Examples fix
WodansSon Sep 25, 2019
e86b1e5
[WIP] Current Progress
WodansSon Sep 26, 2019
99a9179
[WIP] Updates to code
WodansSon Sep 26, 2019
cfb7bc0
[WIP] gofmt
WodansSon Sep 26, 2019
b2b681e
[WIP] Final changes
WodansSon Sep 28, 2019
5abd85a
[WIP] Updated Tests and Docs
WodansSon Sep 28, 2019
19c8dfd
[WIP] Updated test cases
WodansSon Oct 1, 2019
d4bd7e4
[WIP] fix test and lint
WodansSon Oct 1, 2019
08695db
[WIP] Update attribute
WodansSon Oct 3, 2019
8067191
[WIP] Progress
WodansSon Oct 4, 2019
3ffd269
[WIP] Progress
WodansSon Oct 5, 2019
693df4b
Updates per PR
WodansSon Oct 8, 2019
d54e001
Gofmt
WodansSon Oct 8, 2019
deec420
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon Oct 8, 2019
5422f4f
Updates for the new terraform-plugin-sdk
WodansSon Oct 9, 2019
cf6a876
Removed leading newline
WodansSon Oct 9, 2019
44052c7
Updates per PR feedback
WodansSon Oct 11, 2019
474375a
A couple other things
WodansSon Oct 11, 2019
a1e79b2
Gofmt validate
WodansSon Oct 11, 2019
d1ae650
Update Subnet documentation
WodansSon Oct 11, 2019
24d5986
Fix schema and removed unused code refactor
WodansSon Oct 23, 2019
1ea5f77
Merge branch 'master' into nr_private-link-service
WodansSon Oct 30, 2019
97f86ee
Fixed conflict
WodansSon Oct 30, 2019
11cb0e2
Added some more validation
WodansSon Nov 1, 2019
1870099
Resource is good now
WodansSon Nov 5, 2019
a2e93d8
Update name all private link endpoint attributes
WodansSon Nov 5, 2019
bca2ca5
New datasource and refactor done
WodansSon Nov 5, 2019
1f68a54
Fix test and lint issues
WodansSon Nov 6, 2019
ae318b6
Updates per PR comments
WodansSon Nov 12, 2019
2526235
Add subbcategory to docs
WodansSon Nov 12, 2019
94e12d1
Updated name of policy enforcement
WodansSon Nov 12, 2019
627cf84
Fix docs and example
WodansSon Nov 12, 2019
315128f
in progress
WodansSon Nov 12, 2019
d85ba9a
Updates per Tom PR comment and test
WodansSon Nov 14, 2019
e635720
Update website/docs/r/subnet.html.markdown
WodansSon Nov 18, 2019
8301465
Update website/docs/d/private_link_service.html.markdown
WodansSon Nov 18, 2019
d4100c5
Merge branch 'master' into nr_private-link-service
WodansSon Nov 18, 2019
d55f495
gofmt provider
WodansSon Nov 18, 2019
26d0a88
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon Nov 19, 2019
708d10c
Add private link service datasource
WodansSon Nov 19, 2019
e05fc52
Updates per PR comments
WodansSon Nov 20, 2019
50467d8
Merge branch 'master' into nr_private-link-service
WodansSon Nov 20, 2019
00bc22b
Updates per PR comments
WodansSon Nov 21, 2019
8bc37dc
Added state wait code
WodansSon Nov 21, 2019
29a07fd
Fix test collision issue
WodansSon Nov 21, 2019
b2dec30
Update data source validation
WodansSon Nov 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions azurerm/data_source_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func dataSourceArmLoadBalancer() *schema.Resource {
},

"zones": azure.SchemaZonesComputed(),

"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -158,6 +163,10 @@ func flattenLoadBalancerDataSourceFrontendIpConfiguration(ipConfigs *[]network.F
ipConfig["name"] = *config.Name
}

if config.ID != nil {
ipConfig["id"] = *config.ID
}

zones := make([]string, 0)
if zs := config.Zones; zs != nil {
zones = *zs
Expand Down
168 changes: 168 additions & 0 deletions azurerm/data_source_private_link_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmPrivateLinkService() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmPrivateLinkServiceRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: aznet.ValidatePrivateLinkServiceName,
},

"location": azure.SchemaLocationForDataSource(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"auto_approval_subscription_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"visibility_subscription_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

// currently not implemented yet, timeline unknown, exact purpose unknown, maybe coming to a future API near you
// "fqdns": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },

"nat_ip_configuration": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_address_version": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"primary": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

"load_balancer_frontend_ip_configuration_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"alias": {
Type: schema.TypeString,
Computed: true,
},

"network_interface_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmPrivateLinkServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Network.PrivateLinkServiceClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Private Link Service %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error reading Private Link Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil {
return fmt.Errorf("Cannot read ID for Private Link Service %q (Resource Group %q)", name, resourceGroup)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", azure.NormalizeLocation(*resp.Location))

if props := resp.PrivateLinkServiceProperties; props != nil {
d.Set("alias", props.Alias)
if props.AutoApproval.Subscriptions != nil {
if err := d.Set("auto_approval_subscription_ids", utils.FlattenStringSlice(props.AutoApproval.Subscriptions)); err != nil {
return fmt.Errorf("Error setting `auto_approval_subscription_ids`: %+v", err)
}
}
if props.Visibility.Subscriptions != nil {
if err := d.Set("visibility_subscription_ids", utils.FlattenStringSlice(props.Visibility.Subscriptions)); err != nil {
return fmt.Errorf("Error setting `visibility_subscription_ids`: %+v", err)
}
}
// currently not implemented yet, timeline unknown, exact purpose unknown, maybe coming to a future API near you
// if props.Fqdns != nil {
// if err := d.Set("fqdns", utils.FlattenStringSlice(props.Fqdns)); err != nil {
// return fmt.Errorf("Error setting `fqdns`: %+v", err)
// }
// }
if props.IPConfigurations != nil {
if err := d.Set("nat_ip_configuration", flattenArmPrivateLinkServiceIPConfiguration(props.IPConfigurations)); err != nil {
return fmt.Errorf("Error setting `nat_ip_configuration`: %+v", err)
}
}
if props.LoadBalancerFrontendIPConfigurations != nil {
if err := d.Set("load_balancer_frontend_ip_configuration_ids", flattenArmPrivateLinkServiceFrontendIPConfiguration(props.LoadBalancerFrontendIPConfigurations)); err != nil {
return fmt.Errorf("Error setting `load_balancer_frontend_ip_configuration_ids`: %+v", err)
}
}
if props.NetworkInterfaces != nil {
if err := d.Set("network_interface_ids", flattenArmPrivateLinkServiceInterface(props.NetworkInterfaces)); err != nil {
return fmt.Errorf("Error setting `network_interface_ids`: %+v", err)
}
}
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("API returns a nil/empty id on Private Link Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)

return tags.FlattenAndSet(d, resp.Tags)
}
149 changes: 149 additions & 0 deletions azurerm/data_source_private_link_service_endpoint_connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package azurerm

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-07-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmPrivateLinkServiceEndpointConnections() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmPrivateLinkServiceEndpointConnectionsRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: aznet.ValidatePrivateLinkServiceName,
},

"location": azure.SchemaLocationForDataSource(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"private_endpoint_connections": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_id": {
Type: schema.TypeString,
Computed: true,
},
"connection_name": {
Type: schema.TypeString,
Computed: true,
},
"private_endpoint_id": {
Type: schema.TypeString,
Computed: true,
},
"private_endpoint_name": {
Type: schema.TypeString,
Computed: true,
},
"action_required": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func dataSourceArmPrivateLinkServiceEndpointConnectionsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Network.PrivateLinkServiceClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Private Link Service %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error reading Private Link Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("API returns a nil/empty id on Private Link Service Endpoint Connection Status %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", azure.NormalizeLocation(*resp.Location))

if props := resp.PrivateLinkServiceProperties; props != nil {
if ip := props.PrivateEndpointConnections; ip != nil {
if err := d.Set("private_endpoint_connections", flattenArmPrivateLinkServicePrivateEndpointConnections(ip)); err != nil {
return fmt.Errorf("Error setting `private_endpoint_connections`: %+v", err)
}
}
}

d.SetId(*resp.ID)

return nil
}

func flattenArmPrivateLinkServicePrivateEndpointConnections(input *[]network.PrivateEndpointConnection) []interface{} {
results := make([]interface{}, 0)
if input == nil {
return results
}

for _, item := range *input {
v := make(map[string]interface{})
if id := item.ID; id != nil {
v["connection_id"] = *id
}
if name := item.Name; name != nil {
v["connection_name"] = *name
}

if props := item.PrivateEndpointConnectionProperties; props != nil {
if p := props.PrivateEndpoint; p != nil {
if id := p.ID; id != nil {
v["private_endpoint_id"] = *id

id, _ := azure.ParseAzureResourceID(*id)
name := id.Path["privateEndpoints"]
if name != "" {
v["private_endpoint_name"] = name
}
}
}
if s := props.PrivateLinkServiceConnectionState; s != nil {
if a := s.ActionsRequired; a != nil {
v["action_required"] = *a
} else {
v["action_required"] = "none"
}
if d := s.Description; d != nil {
v["description"] = *d
}
if t := s.Status; t != nil {
v["status"] = *t
}
}
}

results = append(results, v)
}

return results
}
45 changes: 45 additions & 0 deletions azurerm/data_source_private_link_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func TestAccDataSourceAzureRMPrivateLinkService_complete(t *testing.T) {
dataSourceName := "data.azurerm_private_link_service.test"
ri := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourcePrivateLinkService_complete(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.#", "2"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.17"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.1.private_ip_address", "10.5.1.18"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.1.private_ip_address_version", "IPv4"),
resource.TestCheckResourceAttr(dataSourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"),
),
},
},
})
}

func testAccDataSourcePrivateLinkService_complete(rInt int, location string) string {
config := testAccAzureRMPrivateLinkService_complete(rInt, location)
return fmt.Sprintf(`
%s

data "azurerm_private_link_service" "test" {
name = azurerm_private_link_service.test.name
resource_group_name = azurerm_private_link_service.test.resource_group_name
}
`, config)
}
Loading